-
Notifications
You must be signed in to change notification settings - Fork 1
/
flv-to-divx.sh
executable file
·80 lines (60 loc) · 1.69 KB
/
flv-to-divx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# flv-to-divx.sh is a script to convert FLVs, typically from BBC iplayer,
# into a format that can be streamed over DLNA to a variety of devices
# such as PS3s, Panasonic TVs, bluray players etc.
# the resulting divx's can be streamed with PMS and Twonky.
NEWREZ="" # don't scale
#NEWREZ="1280x720" # 720p
# panasonic TV divx compatible resolutions:
#NEWREZ="720x416" # NTSC resolution
#NEWREZ="720x576" # PAL resolution
if [ "$1" == "-s" ] ; then
NEWREZ="$2"
shift
shift
fi
FFPMEGOPTSCALE=""
FNAMEADD=""
if [ "$NEWREZ" != "" ] ; then
FFMPEGOPTSCALE="-s $NEWREZ"
FNAMEADD="-$NEWREZ"
fi
INFILE="$1"
if [ "$INFILE" == "" ] ; then
echo "no input file given"
exit 1
fi
if [ "$2" == "" ] ; then
OUTFILE=`echo "$INFILE" | sed -e "s/.flv\$/$FNAMEADD.avi/g"`
echo "Info, output file name $OUTFILE was derived from input file name"
else
OUTFILE="$2"
fi
if [ "$OUTFILE" == "" ] ; then
echo "Error, OUTFILE blank"
exit 1
fi
if [ "$INFILE" == "$OUTFILE" ] ; then
echo "Error, INFILE '$INFILE' same as OUTFILE '$OUTFILE'"
exit 1
fi
if [ ! -f "$INFILE" ] ; then
echo "Error, input file doesn't exist"
exit 1
fi
if [ -f "$OUTFILE" ] ; then
echo "Error, output file already exists"
exit 1
fi
INTERMEDIATE="${OUTFILE%.*}.transcoding.avi"
# fixed quality: quality 4, audio 256k
time nice ffmpeg -nostdin -i $INFILE -f avi -vcodec mpeg4 -qscale 4 -b:a 256k -vtag divx $FFMPEGOPTSCALE $INTERMEDIATE
errorcode=$?
# fixed bit rate: video 1280k, audio 320k
#nice ffmpeg -i $INFILE -f avi -vcodec mpeg4 -b:v 1280k -b:a 320k -vtag divx $FFMPEGOPTSCALE $INTERMEDIATE
mv $INTERMEDIATE $OUTFILE
if [ $errcode -ne 0 ] ; then
echo "ffmpeg returned error code $errcode"
fi
exit $errcode
# end flv-to-divx.sh