UltraSPARC T1 (Niagara) support, patch by Derek E. Lewis /dlewis (gobble) solnetworks...
[mplayer/glamo.git] / TOOLS / qepdvcd.sh
bloba03fa9defbc0e216bc9acab8c288a2f4335f6aac
1 #!/bin/bash
3 # QEPDVCD
5 # Most of this stuff comes straight from MPlayer documentation.
6 # Options are limited only to a small useful subset, if you
7 # want more control, RTFM and DIY.
9 # Version: 0.1
11 # Licence: GPL
13 # Author: Reynaldo H. Verdejo Pinochet <reynaldo@opendot.cl>
15 # Script: MPlayer Sources. Anything supported to vcd/svcd pal/ntsc
17 # requires: mencoder
19 # sugests: vcdimager / cdrecord
21 # Thanks to: Carlos Navarro Salas - name author ;)
25 # Defaults
27 MYNAME=`basename $0`
28 TARGET="svcd"
29 ENCQ="2"
30 ABPS="224"
31 VBPS="2000"
32 NORM="NTSC"
33 SPLIT="0"
34 TOLERANCE="85"
35 OUTNAME="mencodedvcd"
36 SUBFILENAME=0
38 EDLFILENAME="pass.edl"
39 HAVESUB=0
40 WORKDIR="."
41 RATIOX=4
42 RATIOY=3
44 OPTIONS="INPUTFILENAME TARGET ENCQ ABPS VBPS NORM SPLIT TOLERANCE OUTNAME"
46 function usage()
48 echo ""
49 echo "usage $MYNAME inputfile [options]"
50 echo ""
51 echo "Options: [Default value]"
52 echo ""
53 echo "-t Target svcd|vcd [svcd]"
54 echo "-q Encoding quality 0|1|2 [2]"
55 echo "-a Audio bitrate in kbps [224]"
56 echo "-v Video bitrate in kbps [2000 For SVCD, 1150 For VCD]"
57 echo "-n Norm NTSC|PAL [NTSC]"
58 echo "-d Divide/split movie at given times time1:time2:... [no split]"
59 echo "-s Shitty TV screen tolerance %, afects subtitle positioning [85]"
60 echo "-u Subtitle file name [No subtitle]"
61 echo "-o Output basename [mencodedvcd]"
62 echo ""
63 echo "In case you want to use -a/-v please read:"
64 echo "http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html"
65 echo ""
68 function test_needed()
71 for i in mencoder; do
72 if [ -z "`which $i`" ]; then
73 echo "[ERROR] mencoder not found in $PATH!"
74 exit 1
76 done
80 function test_sugested()
83 for i in vcdimager cdrecord; do
84 if [ -z "`which $i`" ]; then
85 echo "[WARNING] $i not found in $PATH!"
86 echo "You'll likely need it after we finish."
87 exit 1
89 done
92 test_needed
93 test_sugested
95 if [ $# -lt 1 ]; then
96 echo ""
97 echo "[ERROR] Input filename parameter is mandatory."
98 echo ""
99 usage
100 exit 1
103 case $1 in
105 usage
106 exit 1
109 INPUTFILENAME=$1
110 shift 1
112 esac
114 while [ "$1"x != "x" ]; do
115 case $1 in
117 TARGET=$2
118 shift 1
121 ENCQ=$2
122 shift 1
125 ABPS=$2
126 shift 1
129 VBPS=$2
130 shift 1
133 NORM=$2
134 shift 1
137 SPLIT=$2
138 shift 1
141 TOLERANCE=$2
142 shift 1
145 SUBFILENAME="$2"
146 HAVESUB=1
147 shift 1
150 OUTNAME=$2
151 shift 1
153 esac
154 shift 1
155 done
157 echo ""
158 echo "[STATUS] Will re-encode using the following parameters:"
159 echo ""
160 for i in $OPTIONS ; do
161 echo "$i ${!i}";
162 done
164 # Parameter Sanity Check ###########################################
165 # We need to check supplied params against known format constraints
166 ####################################################################
168 if [ $TARGET = "svcd" ]; then
169 if [ $ABPS -gt 384 ]; then
170 echo "[ERROR] SVCD maximum abitrate is 384kbps."
171 exit 1
173 if [ $VBPS -gt 2600 ]; then
174 echo "[ERROR] SVCD maximum vbitrate is 2600kbps."
175 exit 1
177 else [ $TARGET = "vcd" ]
178 if [ $ABPS -eq 224 ]; then
179 echo "[ERROR] VCD abitrate must be 224kbps."
180 exit 1
182 if [ $VBPS -gt 1150 ]; then
183 echo "[ERROR] VCD maximum vbitrate is 1150kbps."
184 exit 1
188 # Set encoding options ##############################################
190 if [ $TARGET = "svcd" ]; then
191 FORMAT="xsvcd"
192 VCODEC="mpeg2video"
193 VRCMINRATE=4
194 VRCMAXRATE=2500
195 VRCBUFSIZE=917
196 if [ $NORM = "NTSC" ]; then
197 SCALEX=480
198 SCALEY=480
199 KEYINT=18
200 OFPS="24000/1001"
201 TELECINE=":telecine"
202 else [ $NORM = "PAL" ]
203 SCALEX=480
204 SCALEY=576
205 KEYINT=15
206 OFPS=25
208 else [ $TARGET = "vcd" ]
209 FORMAT="xvcd"
210 VCODEC="mpeg1video"
211 VRCMINRATE=$VBPS
212 VRCMAXRATE=$VBPS
213 VRCBUFSIZE=327
214 if [ $NORM = "NTSC" ]; then
215 SCALEX=352
216 SCALEY=240
217 KEYINT=18
218 OFPS="24000/1001"
219 else [ $NORM = "PAL" ]
220 SCALEX=352
221 SCALEY=288
222 KEYINT=15
223 OFPS=25
227 # Start reencoding ###################################################
229 cd $WORKDIR
231 if [ $(($HAVESUB+1)) -eq 1 ]; then
232 SUBTITLESTRING="/dev/null"
233 else
234 SUBTITLESTRING="$SUBFILENAME"
237 if [ $SPLIT == "0" ]; then
238 CICLES=0
239 TIMESTRING=""
240 else
241 if [ -e $EDLFILENAME ]; then
242 echo "[ERROR]"
243 echo "The -d option needs to generate a temporary file called"
244 echo "$EDLFILENAME. You already have one in this directory,"
245 echo "please remove/rename it and run $MYNAME again."
246 echo ""
247 exit 1
248 else
249 EDLSTRING=$(echo $SPLIT | sed -e s/:/' '/g)
250 EDLARRAY=($EDLSTRING)
251 CICLES=$(echo $EDLSTRING | wc -w)
252 TIMESTRING="-edl $EDLFILENAME -hr-edl-seek"
257 for j in $(seq 0 $CICLES); do
259 NEWNAME=$OUTNAME"_PART"$j".mpg"
260 echo ""
261 echo "Making $NEWNAME, wish me luck ;-)"
262 echo ""
264 # Create EDLFILENAME #################################################
266 if [ $CICLES -ge 1 ]; then
267 for i in $(seq 0 $CICLES)
269 if [ $i -eq $j ]; then
270 if [ $j -ne 0 ]; then
271 echo "0 ${EDLARRAY[$(($i-1))]} 0" > $EDLFILENAME
273 if [ $i -ne $CICLES ]; then
274 echo "${EDLARRAY[$(($i))]} 999999 0" >> $EDLFILENAME
277 done
280 # Mencoder Time ;-) ###################################################
282 mencoder \
283 -ovc lavc -oac lavc -vf expand=:::::$RATIOX/$RATIOY:1,scale=$SCALEX:$SCALEY,harddup \
284 -srate 44100 -af lavcresample=44100 -lavcopts acodec=mp2:abitrate=$ABPS:vcodec=$VCODEC:\
285 vbitrate=$VBPS:keyint=$KEYINT:mbd=$ENCQ:vrc_buf_size=$VRCBUFSIZE:vrc_maxrate=$VRCMAXRATE:\
286 vrc_minrate=$VRCMINRATE:vi_qfactor=0.1:vi_qoffset=1.5:aspect=$RATIOX/$RATIOY -of mpeg \
287 -mpegopts format=$FORMAT$TELECINE -sub $SUBTITLESTRING -subpos $TOLERANCE -subwidth \
288 $TOLERANCE -ofps $OFPS $TIMESTRING -o $NEWNAME $INPUTFILENAME
290 echo "Encoding of $NEWNAME finished."
291 echo "Run vcdimager -t svcd/vcd $NEWNAME and burn with cdrecord."
293 done
295 echo "$(($CICLES+1)) VCD/SVCD file(s) created!!!"
296 echo "Happy to be of some help ;-) have fun."
297 exit 0