Project

General

Profile

Synology NAS shell script to convert native .ts recorded ... ยป recode_V1_0.sh

recode V1.0 - Stuart Pearson, 2015-11-27 23:36

 
1
#!/opt/bin/bash
2
# version 1.0
3

    
4
SEARCHPATH="/volume1/Freeview/*/*.ts"
5
LOGFILE="/volume1/Freeview/status.txt"
6
LOCKFILE="/volume1/Freeview/lockfile.txt"
7

    
8

    
9
if [ -f $LOCKFILE ]
10
then
11
exit
12
else
13
touch $LOCKFILE
14
fi
15
      
16
shopt -s nullglob
17

    
18
for VIDEO1 in $SEARCHPATH ; do
19

    
20
TEMP1=$(du -k $VIDEO1)
21
FILESIZE1=$(echo $TEMP1 | cut -d' ' -f 1)
22
  
23
sleep 1
24

    
25
TEMP2=$(du -k $VIDEO1)
26
FILESIZE2=$(echo $TEMP2 | cut -d' ' -f 1)  
27
echo "Filesize:$FILESIZE1 - $FILESIZE2" > $LOGFILE
28

    
29
if [[ "$FILESIZE2" == "$FILESIZE1" ]]
30
then
31
echo "$(date) - Converting File: " >> $LOGFILE
32
echo $VIDEO1 >> $LOGFILE
33
VIDEO2=${VIDEO1%.*}
34

    
35
ffmpeg -nostats -loglevel 0 -y  -i "$VIDEO1" -deinterlace -r 29.970 -g 12 -vb 15000k -f mpegts  -vcodec copy -acodec:0 copy "$VIDEO2".mpg
36
rm "$VIDEO1"
37

    
38
echo "$(date) - Conversion Finish" >> $LOGFILE
39

    
40
DIRPATH="${VIDEO1%/*}"
41
echo "$DIRPATH" >> $LOGFILE
42
echo "$VIDEO2.mpg" >> $LOGFILE
43
echo "" >> $LOGFILE
44

    
45
synoindex -A "$DIRPATH"
46
synoindex -a "$VIDEO2.mpg"
47
fi
48
done
49

    
50
rm $LOCKFILE
    (1-1/1)