2005-11-16 19:15:27 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# QEPDVCD
|
|
|
|
#
|
2005-11-17 00:47:25 +00:00
|
|
|
# Most of this stuff comes straight from MPlayer documentation.
|
2009-05-13 02:58:57 +00:00
|
|
|
# Options are limited only to a small useful subset, if you
|
2005-11-17 00:47:25 +00:00
|
|
|
# want more control, RTFM and DIY.
|
2005-11-16 19:15:27 +00:00
|
|
|
#
|
|
|
|
# Version: 0.1
|
|
|
|
#
|
|
|
|
# Licence: GPL
|
|
|
|
#
|
2009-05-13 02:58:57 +00:00
|
|
|
# Author: Reynaldo H. Verdejo Pinochet <reynaldo@opendot.cl>
|
2005-11-16 19:15:27 +00:00
|
|
|
#
|
2009-05-13 02:58:57 +00:00
|
|
|
# Script: MPlayer Sources. Anything supported to vcd/svcd pal/ntsc
|
2005-11-16 19:15:27 +00:00
|
|
|
#
|
|
|
|
# requires: mencoder
|
|
|
|
#
|
2009-05-13 02:58:57 +00:00
|
|
|
# sugests: vcdimager / cdrecord
|
2005-11-16 19:15:27 +00:00
|
|
|
#
|
|
|
|
# Thanks to: Carlos Navarro Salas - name author ;)
|
2009-05-13 02:58:57 +00:00
|
|
|
#
|
2005-11-16 19:15:27 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
|
|
|
|
MYNAME=`basename $0`
|
|
|
|
TARGET="svcd"
|
|
|
|
ENCQ="2"
|
|
|
|
ABPS="224"
|
|
|
|
VBPS="2000"
|
|
|
|
NORM="NTSC"
|
|
|
|
SPLIT="0"
|
|
|
|
TOLERANCE="85"
|
|
|
|
OUTNAME="mencodedvcd"
|
|
|
|
SUBFILENAME=0
|
|
|
|
|
|
|
|
EDLFILENAME="pass.edl"
|
|
|
|
HAVESUB=0
|
|
|
|
WORKDIR="."
|
|
|
|
RATIOX=4
|
|
|
|
RATIOY=3
|
|
|
|
|
|
|
|
OPTIONS="INPUTFILENAME TARGET ENCQ ABPS VBPS NORM SPLIT TOLERANCE OUTNAME"
|
|
|
|
|
2008-07-07 06:30:24 +00:00
|
|
|
usage()
|
2005-11-16 19:15:27 +00:00
|
|
|
{
|
|
|
|
echo ""
|
|
|
|
echo "usage $MYNAME inputfile [options]"
|
|
|
|
echo ""
|
|
|
|
echo "Options: [Default value]"
|
|
|
|
echo ""
|
|
|
|
echo "-t Target svcd|vcd [svcd]"
|
|
|
|
echo "-q Encoding quality 0|1|2 [2]"
|
|
|
|
echo "-a Audio bitrate in kbps [224]"
|
|
|
|
echo "-v Video bitrate in kbps [2000 For SVCD, 1150 For VCD]"
|
|
|
|
echo "-n Norm NTSC|PAL [NTSC]"
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "-d Divide/split movie at given times time1:time2:... [no split]"
|
2005-11-16 19:15:27 +00:00
|
|
|
echo "-s Shitty TV screen tolerance %, afects subtitle positioning [85]"
|
|
|
|
echo "-u Subtitle file name [No subtitle]"
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "-o Output basename [mencodedvcd]"
|
2005-11-16 19:15:27 +00:00
|
|
|
echo ""
|
|
|
|
echo "In case you want to use -a/-v please read:"
|
|
|
|
echo "http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2008-07-07 06:30:24 +00:00
|
|
|
test_needed()
|
2005-11-16 19:15:27 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
for i in mencoder; do
|
|
|
|
if [ -z "`which $i`" ]; then
|
|
|
|
echo "[ERROR] mencoder not found in $PATH!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-07 06:30:24 +00:00
|
|
|
test_sugested()
|
2005-11-16 19:15:27 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
for i in vcdimager cdrecord; do
|
|
|
|
if [ -z "`which $i`" ]; then
|
|
|
|
echo "[WARNING] $i not found in $PATH!"
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "You'll likely need it after we finish."
|
2005-11-16 19:15:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
test_needed
|
|
|
|
test_sugested
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
echo ""
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "[ERROR] Input filename parameter is mandatory."
|
2005-11-16 19:15:27 +00:00
|
|
|
echo ""
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
-*)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
INPUTFILENAME=$1
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
while [ "$1"x != "x" ]; do
|
|
|
|
case $1 in
|
|
|
|
-t)
|
|
|
|
TARGET=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-q)
|
|
|
|
ENCQ=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-a)
|
|
|
|
ABPS=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-v)
|
|
|
|
VBPS=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-n)
|
|
|
|
NORM=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
SPLIT=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-s)
|
|
|
|
TOLERANCE=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-u)
|
|
|
|
SUBFILENAME="$2"
|
|
|
|
HAVESUB=1
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
-o)
|
|
|
|
OUTNAME=$2
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift 1
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ""
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "[STATUS] Will re-encode using the following parameters:"
|
2005-11-16 19:15:27 +00:00
|
|
|
echo ""
|
|
|
|
for i in $OPTIONS ; do
|
|
|
|
echo "$i ${!i}";
|
|
|
|
done
|
|
|
|
|
|
|
|
# Parameter Sanity Check ###########################################
|
|
|
|
# We need to check supplied params against known format constraints
|
|
|
|
####################################################################
|
|
|
|
|
|
|
|
if [ $TARGET = "svcd" ]; then
|
|
|
|
if [ $ABPS -gt 384 ]; then
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "[ERROR] SVCD maximum abitrate is 384kbps."
|
2005-11-16 19:15:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ $VBPS -gt 2600 ]; then
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "[ERROR] SVCD maximum vbitrate is 2600kbps."
|
2005-11-16 19:15:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else [ $TARGET = "vcd" ]
|
|
|
|
if [ $ABPS -eq 224 ]; then
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "[ERROR] VCD abitrate must be 224kbps."
|
2005-11-16 19:15:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ $VBPS -gt 1150 ]; then
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "[ERROR] VCD maximum vbitrate is 1150kbps."
|
2005-11-16 19:15:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set encoding options ##############################################
|
|
|
|
|
|
|
|
if [ $TARGET = "svcd" ]; then
|
|
|
|
FORMAT="xsvcd"
|
|
|
|
VCODEC="mpeg2video"
|
|
|
|
VRCMINRATE=4
|
|
|
|
VRCMAXRATE=2500
|
|
|
|
VRCBUFSIZE=917
|
|
|
|
if [ $NORM = "NTSC" ]; then
|
|
|
|
SCALEX=480
|
|
|
|
SCALEY=480
|
|
|
|
KEYINT=18
|
|
|
|
OFPS="24000/1001"
|
|
|
|
TELECINE=":telecine"
|
|
|
|
else [ $NORM = "PAL" ]
|
|
|
|
SCALEX=480
|
|
|
|
SCALEY=576
|
|
|
|
KEYINT=15
|
|
|
|
OFPS=25
|
|
|
|
fi
|
|
|
|
else [ $TARGET = "vcd" ]
|
|
|
|
FORMAT="xvcd"
|
|
|
|
VCODEC="mpeg1video"
|
|
|
|
VRCMINRATE=$VBPS
|
|
|
|
VRCMAXRATE=$VBPS
|
|
|
|
VRCBUFSIZE=327
|
|
|
|
if [ $NORM = "NTSC" ]; then
|
|
|
|
SCALEX=352
|
|
|
|
SCALEY=240
|
|
|
|
KEYINT=18
|
|
|
|
OFPS="24000/1001"
|
|
|
|
else [ $NORM = "PAL" ]
|
|
|
|
SCALEX=352
|
|
|
|
SCALEY=288
|
|
|
|
KEYINT=15
|
|
|
|
OFPS=25
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Start reencoding ###################################################
|
|
|
|
|
|
|
|
cd $WORKDIR
|
|
|
|
|
|
|
|
if [ $(($HAVESUB+1)) -eq 1 ]; then
|
|
|
|
SUBTITLESTRING="/dev/null"
|
|
|
|
else
|
|
|
|
SUBTITLESTRING="$SUBFILENAME"
|
|
|
|
fi
|
|
|
|
|
2008-07-07 06:43:45 +00:00
|
|
|
if [ $SPLIT = "0" ]; then
|
2005-11-16 19:15:27 +00:00
|
|
|
CICLES=0
|
|
|
|
TIMESTRING=""
|
|
|
|
else
|
|
|
|
if [ -e $EDLFILENAME ]; then
|
|
|
|
echo "[ERROR]"
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "The -d option needs to generate a temporary file called"
|
|
|
|
echo "$EDLFILENAME. You already have one in this directory,"
|
|
|
|
echo "please remove/rename it and run $MYNAME again."
|
2005-11-16 19:15:27 +00:00
|
|
|
echo ""
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
EDLSTRING=$(echo $SPLIT | sed -e s/:/' '/g)
|
|
|
|
EDLARRAY=($EDLSTRING)
|
|
|
|
CICLES=$(echo $EDLSTRING | wc -w)
|
|
|
|
TIMESTRING="-edl $EDLFILENAME -hr-edl-seek"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
for j in $(seq 0 $CICLES); do
|
|
|
|
|
|
|
|
NEWNAME=$OUTNAME"_PART"$j".mpg"
|
|
|
|
echo ""
|
|
|
|
echo "Making $NEWNAME, wish me luck ;-)"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
# Create EDLFILENAME #################################################
|
|
|
|
|
|
|
|
if [ $CICLES -ge 1 ]; then
|
|
|
|
for i in $(seq 0 $CICLES)
|
|
|
|
do
|
|
|
|
if [ $i -eq $j ]; then
|
|
|
|
if [ $j -ne 0 ]; then
|
|
|
|
echo "0 ${EDLARRAY[$(($i-1))]} 0" > $EDLFILENAME
|
|
|
|
fi
|
|
|
|
if [ $i -ne $CICLES ]; then
|
|
|
|
echo "${EDLARRAY[$(($i))]} 999999 0" >> $EDLFILENAME
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-11-16 19:15:27 +00:00
|
|
|
# Mencoder Time ;-) ###################################################
|
|
|
|
|
2006-04-23 04:42:25 +00:00
|
|
|
mencoder \
|
|
|
|
-ovc lavc -oac lavc -vf expand=:::::$RATIOX/$RATIOY:1,scale=$SCALEX:$SCALEY,harddup \
|
|
|
|
-srate 44100 -af lavcresample=44100 -lavcopts acodec=mp2:abitrate=$ABPS:vcodec=$VCODEC:\
|
|
|
|
vbitrate=$VBPS:keyint=$KEYINT:mbd=$ENCQ:vrc_buf_size=$VRCBUFSIZE:vrc_maxrate=$VRCMAXRATE:\
|
|
|
|
vrc_minrate=$VRCMINRATE:vi_qfactor=0.1:vi_qoffset=1.5:aspect=$RATIOX/$RATIOY -of mpeg \
|
|
|
|
-mpegopts format=$FORMAT$TELECINE -sub $SUBTITLESTRING -subpos $TOLERANCE -subwidth \
|
|
|
|
$TOLERANCE -ofps $OFPS $TIMESTRING -o $NEWNAME $INPUTFILENAME
|
2005-11-16 19:15:27 +00:00
|
|
|
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "Encoding of $NEWNAME finished."
|
|
|
|
echo "Run vcdimager -t svcd/vcd $NEWNAME and burn with cdrecord."
|
2005-11-16 19:15:27 +00:00
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$(($CICLES+1)) VCD/SVCD file(s) created!!!"
|
2005-11-17 00:47:25 +00:00
|
|
|
echo "Happy to be of some help ;-) have fun."
|
2005-11-16 19:15:27 +00:00
|
|
|
exit 0
|