Log in

View Full Version : mencoder command for libavcodec und xvid


hellfred
15th June 2004, 08:06
Hi there
I am new to encoding in Linux, just did some encodings under win32 using GUIs. Now i want to start all over from the commandline.
So i want to ask you for a little bit of help to not having to start from zero.
I want to use mencoder (and maybe transcode later,too) to create some MPEG4 videos, using both libavcodec and xvid. I have compiled mencoder with support of libavcodec, xvid and lame.
Serching Doom9 i only came up with an quite old thread (http://forum.doom9.org/showthread.php?s=&threadid=75402&highlight=mencoder) (late 2001)
The documentation of mplayer/mencoder is a little bit outdated, too, but i have found a draft (http://sault.org/~tack/menc-feat-dvd-mpeg4.html) for a up to date "Making a high quality MPEG4 ("DivX") rip of a DVD movie" page. I want to use this as a startpoint for libavcodec encoding, and ask you what to change/improve to get a good quality two CD-R rip of a movie from DVD, or anime content capured with a analog capture card which adds lots of noise.
We're now ready to do the 2-pass encode. Pass 1:

mencoder dvd://1 -ofps 23.976 -oac copy -vf crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \
-lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=1 \
-o Harry_Potter_2.avi

And pass 2 is the same, except that we specify vpass=2:

mencoder dvd://1 -ofps 23.976 -oac copy -vf crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \
-lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=2 \
-o Harry_Potter_2.avi

The options v4mv:mbd=2:trell will greatly increase the quality at the expense of encoding time. There's little reason to leave these options out when the primary goal is quality. The options cmp=3:subcmp=3:mbcmp=3 select a comparison function that yields higher quality than the defaults. You might try experimenting with with this parameter (refer to the man page for the possible values) as different functions can have a large impact on quality depending on the source material. For example, if you find libavcodec produces too much blocky artifacting, you could try *cmp=10. (This comparison function, NSSE, is currently only available in CVS versions and is experimental.)

For this movie, the resulting AVI will be 138 minutes long and nearly 3GB. And because you said that file size doesn't matter, this is a perfectly acceptable size. However, if you had wanted it smaller, you could try a lower bitrate. Increasing bitrates have diminishing returns. So while we might clearly see an improvement from 1800Kbit to 2000Kbit, it might not be so noticeable above 2000Kbit. Feel free to experiment until you're happy.

I have now idea what to what and how to pass parameters to mencoder for encoding with xvid and where to look for. Can anybody please give me an example and a link to a place wher i learn what to do and what the parameters are?

Good shellscripts are welcome, too.
This (http://them.ws/stuff/docs/dvdencode.txt) one is missing some sophisticated command line parameters for encoding, though.

Hellfred

frodoontop
15th June 2004, 09:05
I think xvid is very usefull when a movie is easy to compress, to get most details. Libavcodec seems to be much better in doing the hard to compress movies.

Anyway, for xvid I use:

1st pass:
cat *vob|mencoder -endpos 02:24:00 -nosound -o /dev/null -sws 2 -vf crop=718:436:0:74,scale=576:416 -ovc xvid -xvidencopts pass=1:quant_intra_matrix=/opt/matrix/xvid-hvs-best.intra:quant_inter_matrix=/opt/matrix/xvid-hvs-best.inter:qpel:chroma_me:max_bframes=3:vhq=1:min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:min_bquant=1:max_bquant=31 -

2nd pass:
cat *vob|mencoder -endpos 02:24:00 -nosound -o movie.avi -sws 2 -vf crop=718:436:0:74,scale=576:416 -ovc xvid -xvidencopts pass=2:bitrate=1231:quant_intra_matrix=/opt/matrix/xvid-hvs-best.intra:quant_inter_matrix=/opt/matrix/xvid-hvs-best.inter:qpel:chroma_me:max_bframes=3:vhq=1:min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:min_bquant=1:max_bquant=31 -

Note: aspect ratio will be set in matroska container.
Note2: I use -endpos because I'm never interested in the credits part.
Note3: The default of mencoder ain't the same as the defaults of xvid. By default mencoder doesn't use quant 1.

For Libavcodec I use:

1st pass:
cat *vob|mencoder -endpos 01:42:20 -nosound -o /dev/null -sws 2 -vf crop=718:436:0:74,scale=576:320 -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:lumi_mask=0.5:scplx_mask=0.1:vpass=1:vqscale=2:vmax_b_frames=1:cmp=256:vqmin=2:vqmax=6:mbqmin=2:mbqmax=10 -

cat *vob | mencoder -endpos 01:42:20 -nosound -o video.avi -sws 2 -vf crop=718:436:0:74,scale=576:320 -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:lumi_mask=0.5:scplx_mask=0.1:vpass=2:vbitrate=1231:vmax_b_frames=1:cmp=256:vqmin=2:vqmax=6:mbqmin=2:mbqmax=10 -

Note: These settings are both fast and good. I tried other settings which were much slower, but it seemed the compression gain was minimal or even negative. This results in about 20 fps on my AMD 800 for both passes.

Overall notes:
For determining the audio offset, I cheat and use DVD2AVI through wine for a few seconds. When using cat *vob it always result in unpredictable offsets for audio. Better use vobcopy and make sure that results in one big .vob. See vobcopy --help or something like that.

To determine the crop values you can use (from a terminal):
mplayer filename -vop cropdetect

The crop values will be shown in the terminal. Skip the video to different parts to get a reliable result.

This in only what I got so far. I used to encode in windows too about 2 months ago. This should get you on your way ;) .

((( atom )))
28th June 2004, 18:02
Originally posted by frodoontop

For determining the audio offset, I cheat and use DVD2AVI through wine for a few seconds. When using cat *vob it always result in unpredictable offsets for audio. Better use vobcopy and make sure that results in one big .vob. See vobcopy --help or something like that.
wasn't that problem solved by mencoder dvd://1 where 1 i the title number? i am even rather sure, maybe it helps you out..

and.. is there a way meanwhile to mux two audiotracks into an avi file under linux?

frodoontop
30th June 2004, 08:41
About the offset, if you're encoding mp3 or keep the ac3-file that works. Not if you want to separate the audio and encode it to vorbis. Please correct me if I'm wrong.

You probably already know matroska handles two audiotracks easily and is well supported in linux?

((( atom )))
30th June 2004, 15:48
Originally posted by frodoontop
About the offset, if you're encoding mp3 or keep the ac3-file that works. Not if you want to separate the audio and encode it to vorbis. Please correct me if I'm wrong.

You probably already know matroska handles two audiotracks easily and is well supported in linux? about vorbis i dunno and for matroska i only know that standalones mostly support the avi container, if i like it or not, so i stick to that, since there are quite a few of these around in my friendhood. none of these has a problem with >1 audiotracks inside the avi and some of them can even play them back.