Forums » Tutorial and setups »
Synology NAS shell script to convert native .ts recorded files from DVB-T adapter to .mpg for playback on Samsung TV
Added by Stuart Pearson almost 9 years ago
I am currently setting up my synology NAS and connected DVB adapters for our recording needs. One issue I have had to overcome is my Samsung TV will not play the native .ts files produced by tvheadend. For the solution I have created a script that converts from .ts to .mpg using ffmpeg. The script is below, it probably can be optimised, I searched online for snippets of code to achieve the various functions. In tvheadend I have my post process script set to "recode", the name I have gave the script. To tidy up the synology file index I also have a scheduled task that runs every day as "synoindex -R share:Freeview.
Hope others with this requirement find it useful.
Stuart
#!/opt/bin/bash
version 1.0
SEARCHPATH="/volume1/Freeview/*/*.ts"
LOGFILE="/volume1/Freeview/status.txt"
LOCKFILE="/volume1/Freeview/lockfile.txt"
if [ -f $LOCKFILE ]
then
exit
else
touch $LOCKFILE
fi
shopt -s nullglob
for VIDEO1 in $SEARCHPATH ; do
TEMP1=$(du -k $VIDEO1)
FILESIZE1=$(echo $TEMP1 | cut -d' ' -f 1)
sleep 1
TEMP2=$(du -k $VIDEO1)
FILESIZE2=$(echo $TEMP2 | cut -d' ' -f 1)
echo "Filesize:$FILESIZE1 - $FILESIZE2" > $LOGFILE
if "$FILESIZE2" == "$FILESIZE1"
then
echo "$(date) - Converting File: " >> $LOGFILE
echo $VIDEO1 >> $LOGFILE
VIDEO2=${VIDEO1%.*}
ffmpeg -nostats -loglevel 0 -y -i "$VIDEO1" -deinterlace -r 29.970 -g 12 -vb 15000k -f mpegts -vcodec copy -acodec:0 copy "$VIDEO2".mpg
rm "$VIDEO1"
echo "$(date) - Conversion Finish" >> $LOGFILE
DIRPATH="${VIDEO1%/*}"
echo "$DIRPATH" >> $LOGFILE
echo "$VIDEO2.mpg" >> $LOGFILE
echo "" >> $LOGFILE
synoindex -A "$DIRPATH"
synoindex -a "$VIDEO2.mpg"
fi
done
recode_V1_0.sh (972 Bytes) recode_V1_0.sh | recode V1.0 |