evade
1st March 2004, 19:45
I encode xvid with mencoder and this is how do it for ntsc non-interlaced content which is the bulk of what I do. Suggestions comments and quesitons are welcome.
I use xvid's ability to store aspect ratio and I also use the mencoder modules support for autoaspect which appeared in the mplayer CVS on feb 4 a recent cvs build of mplayer.
First I rip the DVD. I do this with dvd::rip because it has a nice interface for pgc ripping and has a gui for bitrate calculation.
From the transcode screen on dvd::rip I select target size and the audio track I am going to use, note the resulting video bitrate. I can now close dvd::rip discarding the project.
The Rest is done on the command line
First I cd into the directory where the vobs are and store the bitrate in a file so I don't have to remember it
dave@hammer 001 $ cd /raid/dvdrip/data/zeroeffect/vob/001/
dave@hammer 001 $ echo 1296 > bitrate
Then I determine how much I need to crop with this command (I use the second vob so the opening credits don't confuse the filter)
dave@hammer 001 $ mencoder -ovc lavc -oac copy -o /dev/null -vf cropdetect zeroeffect-002.vob
This outputs a suggested crop. I run this command with lavc because it doesn't require and options, quicker to type. Let it run for a about thirty seconds and the run the same command on the third vob, if the values differ its usually due to some very dark scenes and it is a safe bet to take the larger of the two.
( if you want to preview the crop run mplayer with the -vf crop option. I find this unnescessary as the cropdect filter does a great job.)
This movie doesn't need cropping but for examples sake I am putting a crop filter in which takes nothing off.
So now I generate some samples with this script called xvid-samples:
dave@hammer 001 $ /export/scripts/xvid-samples `pwd` Zero_Effect '-vf crop=720:480:0:0'
or if I want to use a noise filter
dave@hammer 001 $ /export/scripts/xvid-samples `pwd` Zero_Effect '-vf crop=720:480:0:0,hqdn3d'
xvid-samples:
#!/bin/tcsh
# ${1}=path to vobs
# ${2}=name of movie
# ${3}=extra (eg -vf crop=)
cd ${1}
mkdir samples
@ br=`cat bitrate`
# hvs-good matrix
echo "`date` ${2}.hvs-good.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-good.intra.txt:quant_inter_matrix=/export/scripts/hvs-good.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-good.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.hvs-good.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-good.intra.txt:quant_inter_matrix=/export/scripts/hvs-good.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-good.avi Finished encoding" >> xvid-samples.log
# hvs-better matrix
echo "`date` ${2}.hvs-better.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-better.intra.txt:quant_inter_matrix=/export/scripts/hvs-better.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-better.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.hvs-better.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-better.intra.txt:quant_inter_matrix=/export/scripts/hvs-better.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-better.avi Finished encoding" >> xvid-samples.log
# hvs-best matrix
echo "`date` ${2}.hvs-best.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-best.intra.txt:quant_inter_matrix=/export/scripts/hvs-best.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-best.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.hvs-best.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-best.intra.txt:quant_inter_matrix=/export/scripts/hvs-best.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-best.avi Finished encoding" >> xvid-samples.log
# mpeg matrix
echo "`date` ${2}.mpeg.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_type=mpeg:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.mpeg.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.mpeg.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_type=mpeg:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.mpeg.avi Finished encoding" >> xvid-samples.log
# h263 matrix
echo "`date` ${2}.h263.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_type=h263:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.h263.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.h263.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_type=h263:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.h263.avi Finished encoding" >> xvid-samples.log
This produces 2 minute samples from the movie encoded at my desired bitrate with good better and best hvs matrices as well as mpeg and h263.
If I was unhappy with this particular sample I could do this to grab a different two minutes from 20 minutes later:
dave@hammer 001 $ /export/scripts/xvid-samples `pwd` Zero_Effect '-vf crop=720:480:0:0 --ss 20:00'
More often than not I will choose an hvs matrix so I run my xvid-hvs script with the following command:
dave@hammer 001 $ /export/scripts/xvid-hvs `pwd` Zero_Effect best '-vf crop=720:480:0:0'
Or if I am sshing into my box I will daemonize it with the at command, this also runs the process at a nice level of 2.
dave@hammer 001 $ echo "/export/scripts/xvid-hvs `pwd` Zero_Effect best '-vf crop=720:480:0:0'" | at now
Or add it to a batch and run it with other jobs
dave@hammer 001 $ echo "/export/scripts/xvid-hvs `pwd` /raid/movies/Zero_Effect.avi best '-vf crop=720:480:0:0'" >> ~/batch.txt
and later run them all at 1am while I am sleeping:
dave@hammer 001 $ at -f ~/batch.txt 01:00
here is xvid-hvs:
#!/bin/tcsh
# ${1}=path to vobs
# ${2}=filename
# ${3}=hvs matrix
# ${4}=extra options eg -vf crop
cd ${1}
@ br=`cat bitrate`
echo "`date` ${2} start encoding" >> encode.log
cat *.vob | mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-${3}.intra.txt:quant_inter_matrix=/export/scripts/hvs-${3}.inter.txt:autoaspect ${4} -aid 128 -oac copy -
echo "`date` ${2} Pass 1 complete" >> encode.log
cat *.vob | mencoder -o ${2} -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-${3}.intra.txt:quant_inter_matrix=/export/scripts/hvs-${3}.inter.txt:autoaspect ${4} -aid 128 -oac copy -
echo "`date` ${2} Finished encoding" >> encode.log
I use xvid's ability to store aspect ratio and I also use the mencoder modules support for autoaspect which appeared in the mplayer CVS on feb 4 a recent cvs build of mplayer.
First I rip the DVD. I do this with dvd::rip because it has a nice interface for pgc ripping and has a gui for bitrate calculation.
From the transcode screen on dvd::rip I select target size and the audio track I am going to use, note the resulting video bitrate. I can now close dvd::rip discarding the project.
The Rest is done on the command line
First I cd into the directory where the vobs are and store the bitrate in a file so I don't have to remember it
dave@hammer 001 $ cd /raid/dvdrip/data/zeroeffect/vob/001/
dave@hammer 001 $ echo 1296 > bitrate
Then I determine how much I need to crop with this command (I use the second vob so the opening credits don't confuse the filter)
dave@hammer 001 $ mencoder -ovc lavc -oac copy -o /dev/null -vf cropdetect zeroeffect-002.vob
This outputs a suggested crop. I run this command with lavc because it doesn't require and options, quicker to type. Let it run for a about thirty seconds and the run the same command on the third vob, if the values differ its usually due to some very dark scenes and it is a safe bet to take the larger of the two.
( if you want to preview the crop run mplayer with the -vf crop option. I find this unnescessary as the cropdect filter does a great job.)
This movie doesn't need cropping but for examples sake I am putting a crop filter in which takes nothing off.
So now I generate some samples with this script called xvid-samples:
dave@hammer 001 $ /export/scripts/xvid-samples `pwd` Zero_Effect '-vf crop=720:480:0:0'
or if I want to use a noise filter
dave@hammer 001 $ /export/scripts/xvid-samples `pwd` Zero_Effect '-vf crop=720:480:0:0,hqdn3d'
xvid-samples:
#!/bin/tcsh
# ${1}=path to vobs
# ${2}=name of movie
# ${3}=extra (eg -vf crop=)
cd ${1}
mkdir samples
@ br=`cat bitrate`
# hvs-good matrix
echo "`date` ${2}.hvs-good.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-good.intra.txt:quant_inter_matrix=/export/scripts/hvs-good.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-good.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.hvs-good.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-good.intra.txt:quant_inter_matrix=/export/scripts/hvs-good.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-good.avi Finished encoding" >> xvid-samples.log
# hvs-better matrix
echo "`date` ${2}.hvs-better.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-better.intra.txt:quant_inter_matrix=/export/scripts/hvs-better.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-better.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.hvs-better.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-better.intra.txt:quant_inter_matrix=/export/scripts/hvs-better.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-better.avi Finished encoding" >> xvid-samples.log
# hvs-best matrix
echo "`date` ${2}.hvs-best.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-best.intra.txt:quant_inter_matrix=/export/scripts/hvs-best.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-best.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.hvs-best.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-best.intra.txt:quant_inter_matrix=/export/scripts/hvs-best.inter.txt:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.hvs-best.avi Finished encoding" >> xvid-samples.log
# mpeg matrix
echo "`date` ${2}.mpeg.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_type=mpeg:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.mpeg.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.mpeg.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_type=mpeg:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.mpeg.avi Finished encoding" >> xvid-samples.log
# h263 matrix
echo "`date` ${2}.h263.avi start encoding" >> xvid-samples.log
mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:turbo=1:vhq=1:quant_type=h263:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.h263.avi Pass 1 complete" >> xvid-samples.log
mencoder -o samples/${2}.h263.avi -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:turbo=1:vhq=1:bitrate=$br\:quant_type=h263:autoaspect ${3} -endpos 2:00 -aid 128 -oac copy *2.vob
echo "`date` ${2}.h263.avi Finished encoding" >> xvid-samples.log
This produces 2 minute samples from the movie encoded at my desired bitrate with good better and best hvs matrices as well as mpeg and h263.
If I was unhappy with this particular sample I could do this to grab a different two minutes from 20 minutes later:
dave@hammer 001 $ /export/scripts/xvid-samples `pwd` Zero_Effect '-vf crop=720:480:0:0 --ss 20:00'
More often than not I will choose an hvs matrix so I run my xvid-hvs script with the following command:
dave@hammer 001 $ /export/scripts/xvid-hvs `pwd` Zero_Effect best '-vf crop=720:480:0:0'
Or if I am sshing into my box I will daemonize it with the at command, this also runs the process at a nice level of 2.
dave@hammer 001 $ echo "/export/scripts/xvid-hvs `pwd` Zero_Effect best '-vf crop=720:480:0:0'" | at now
Or add it to a batch and run it with other jobs
dave@hammer 001 $ echo "/export/scripts/xvid-hvs `pwd` /raid/movies/Zero_Effect.avi best '-vf crop=720:480:0:0'" >> ~/batch.txt
and later run them all at 1am while I am sleeping:
dave@hammer 001 $ at -f ~/batch.txt 01:00
here is xvid-hvs:
#!/bin/tcsh
# ${1}=path to vobs
# ${2}=filename
# ${3}=hvs matrix
# ${4}=extra options eg -vf crop
cd ${1}
@ br=`cat bitrate`
echo "`date` ${2} start encoding" >> encode.log
cat *.vob | mencoder -o /dev/null -ofps 23.976 -ovc xvid -xvidencopts pass=1:packed=1:vhq=1:quant_intra_matrix=/export/scripts/hvs-${3}.intra.txt:quant_inter_matrix=/export/scripts/hvs-${3}.inter.txt:autoaspect ${4} -aid 128 -oac copy -
echo "`date` ${2} Pass 1 complete" >> encode.log
cat *.vob | mencoder -o ${2} -ofps 23.976 -ovc xvid -xvidencopts pass=2:packed=1:vhq=1:bitrate=$br\:quant_intra_matrix=/export/scripts/hvs-${3}.intra.txt:quant_inter_matrix=/export/scripts/hvs-${3}.inter.txt:autoaspect ${4} -aid 128 -oac copy -
echo "`date` ${2} Finished encoding" >> encode.log