View Full Version : Mencoder parameters for x264 and XviD encoding
rbaggio
22nd May 2006, 11:09
Hi all
I regularly convert DVB-T SDTV broadcasts into both XviD (for a standalone player) and x264 formats, using mencoder.
I thought I would share my encoding options for mencoder (for those that might be interested), and also ask the gurus out there if there are some better settings I could be using.
I am reasonably happy with the x264 results, but I think XviD could be better. They don't look as good as some of the TV rips you see floating around on the net.
anyway..... source is 720x576 PAL DVB-T for these examples
* x264 pass 1
-ovc x264 -vf crop=688:560,scale=624:352 -x264encopts pass=1:cabac:deblock:frameref=3:bframes=2:b_adapt:qp_step=4:4x4mv:weight_b:chroma_me
* x264 pass 2
-ovc x264 -vf crop=688:560,scale=624:352 -x264encopts pass=2:bitrate=896:cabac:deblock:frameref=3:bframes=2:b_adapt:qp_step=4:4x4mv:weight_b:chroma_me
* XviD pass 1
-ovc xvid -xvidencopts aspect=16/9:bitrate=896:pass=1:trellis:quant_type=mpeg: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
* XviD pass 2
-ovc xvid -xvidencopts aspect=16/9:bitrate=896:pass=2:trellis:quant_type=mpeg: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
Cheers :P
Chainmax
22nd May 2006, 21:03
What would you use for lossless x264? And for converting to YUY2 or YV12?
rbaggio
23rd May 2006, 08:52
Hi Chainmax
I haven't looked into lossless x264 encoding as yet (I didn't even know it was around). And I have no need for converting to different colourspaces.
oldcpu
8th June 2006, 22:52
I tried to convert a video in x264 to a dvd compatible mpeg, but I did not succeed. video is 944x528 @ 29.97 fps. avc1 codec. audio is faad @ 126688 bits/sec (48,000 hz).
I'm using SuSE with x264 v0.0svn20060425 and MPlayer-1.0pre7try3, both compiled by Packman.
http://packman.links2linux.org/?action=128
When I simply play the video, it comes ok (albeit jerky) but the audio sounds very very slow. When I try to encode with mencoder, mencoder crashes after about 10 minutes. The portion that was converted it is heavily pixilated.
I can play it ok with vlc, but vlc is not an encoder.
Does anyone know of any application running under linux that works reliably to reduce a high res video (similar to what I mentioned) to a DVD format mpeg?
When I simply play the video, it comes ok (albeit jerky) but the audio sounds very very slow. When I try to encode with mencoder, mencoder crashes after about 10 minutes. The portion that was converted it is heavily pixilated.
You should first try to get it to play back correctly. Try -srate 44100 and if that doesn't help, -ao null. The latter will not send sound to the sound card, but if it plays back without skips, Mencoder could work fine.
What is the exact MPlayer version? It is shown in the first line of output when you run mplayer without any options, like this:
"MPlayer dev-CVS-060123-00:03-3.4.5 (C) 2000-2006 MPlayer Team".
If it's really just a patched pre7, it's no wonder there are problems with H.264 and AAC. In that case you'll need to update to a recent CVS/SVN version.
Post your Mencoder command line too.
I can play it ok with vlc, but vlc is not an encoder.
Actually it can encode to quite a few formats and containers, but I wouldn't recommend it over Mencoder in this case.
Does anyone know of any application running under linux that works reliably to reduce a high res video (similar to what I mentioned) to a DVD format mpeg?
Mencoder is one of the most reliable and versatile tools once you get to know it. You could also take a look at ffmpeg (http://www.ffmpeg.org), transcode (http://www.transcoding.org/cgi-bin/transcode) and maybe Avidemux (http://fixounet.free.fr/avidemux/) (it's a GUI).
oldcpu
11th June 2006, 09:07
nm, thanks for your detailed response.
What is the exact MPlayer version?
I'm using an MPlayer compiled for SuSE users by one of the Packman packagers:
MPlayer 1.0pre7try3-SUSE Linux 10.1 (i686)-Packman-4.1.0 (C) 2000-2005 MPlayer Team
I suspect it IS a patched pre7.
I'll look into installing a recent CVS/SVN. That does mean compiling mplayer, which I know many of the experts on this forum take for granted, ... although my limited experience (failures compiling mplayer previously) has shown this can be a daunting task.
But if x264 can be improved by compiling, then its likely an effort worth spending the time on.
Post your Mencoder command line too.OK, I'll post that soon.
Thanks again for your suggestions.
oldcpu
14th June 2006, 19:28
What is the exact MPlayer version? It is shown in the first line of output when you run mplayer without any options, like this:
"MPlayer dev-CVS-060123-00:03-3.4.5 (C) 2000-2006 MPlayer Team".
If it's really just a patched pre7, it's no wonder there are problems with H.264 and AAC. In that case you'll need to update to a recent CVS/SVN version.I upgraded earlier today to MPlayer -1.0pre8.Try -srate 44100 and if that doesn't help, -ao null.With the newer mplayer, I tried "mplayer inputfile.mp4" and "mplayer inputfile.mp4 -srate 44100" both play perfectly. No pixelization. OK audio. (Xine, on the otherhand, struggles).
What a difference an mplayer version upgrade makes.
Now that I can play it back, I still not clear how I can strip out the audio and convert it to a DVD acceptable format. I have had more success stripping out the video and creating an m2v format (acceptable for a DVD).
oldcpu
14th June 2006, 19:31
Now that I can play it back, I still not clear how I can strip out the audio and convert it to a DVD acceptable format. I have had more success stripping out the video and creating an m2v format (acceptable for a DVD).I'm trying (with mplayer-1.0pre8) the simple command:
mplayer inputfile.mp4 -ao pcm:file=outputfile.wav
and that appears to be working to strip out the audio. That didn't work as good before with mplayer-1.0pre7 with the x264 file.
rbaggio
16th June 2006, 12:07
... so getting back to my original topic .... does anyone else care to share their mencoder parameters for encoding to x264 and/or XviD?
mic64
17th June 2006, 17:37
Here is my script for Episode dvds to xvid.
Size is then ~890MB. So 5 Episodes with ac3 per DVD.
The hqdnd3d stuff is only in it than the source is very grainy.
1st pass:
mencoder dvd://1 -dvd-device /home/mic/mnt/iso -aid 128 -oac copy -ovc xvid -xvidencopts min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:min_bquant=1:max_bquant=31:vhq=1:bvhq=1:me_quality=6:hq_ac:chroma_me:chroma_opt:max_bframes=2:trellis:packed:bitrate=2506:pass=1:keyframe_boost=30:kfthreshold=1:kfreduction=40:overflow_control_strength=15:max_overflow_improvement=15:quant_type=mpeg:quant_inter_matrix=/home/mic/programme/mencoder/hvs.best.inter:quant_intra_matrix=/home/mic/programme/mencoder/hvs.best.intra -vf hqdn3d=4:3:6 -o "/dev/null"
2nd pass:
mencoder dvd://1 -dvd-device /home/mic/mnt/iso -aid 128 -oac copy -ovc xvid -xvidencopts min_iquant=1:max_iquant=31:min_pquant=1:max_pquant=31:min_bquant=1:max_bquant=31:vhq=1:bvhq=1:me_quality=6:hq_ac:chroma_me:chroma_opt:max_bframes=2:trellis:packed:bitrate=2506:pass=2:keyframe_boost=30:kfthreshold=1:kfreduction=40:overflow_control_strength=15:max_overflow_improvement=15:quant_type=mpeg:quant_inter_matrix=/home/mic/programme/mencoder/hvs.best.inter:quant_intra_matrix=/home/mic/programme/mencoder/hvs.best.intra -vf hqdn3d=4:3:6 -o "/home/mic/xvid.avi.avi"
You also need of course the other matrix.
rbaggio
18th June 2006, 01:39
Thanks mic64, I'll check it out :P
Spotteri
25th June 2006, 20:22
Doesn't mencoder always put x264 in avi-container. Bad thing, right?
For that reason I've always done it this way (speed over quality):
mkfifo -m 600 stream.y4m
nice -n 10 \
mplayer -nosound -noframedrop -noautosub \
-vo yuv4mpeg:file=stream.y4m \
-vf kerndeint=16:0:0:0:0,hqdn3d=2:2:4,unsharp=l3x3:1.0,crop=688:560,scale=640:480 \
"/home/somebody/source.vob" &
x264 -q 26 -b 2 --no-cabac --no-chroma-me \
--trellis 0 --no-psnr --sar 16:9 --me hex -m 2 --progress \
-o /home/somebody/encoded.mkv stream.y4m
mplayer -quiet -vo null -dumpfile audiodump.ac3 -dumpaudio "source.vob"
mkvmerge -o "/home/somebody/final.mkv" --language 1:und --default-track 1 \
--aspect-ratio 1:4/3 --fourcc 1:MP4V -d 1 -A -S /home/somebody/encoded.mkv \
--language 0:eng -a 0 -D -S /home/somebody/audiodump.ac3 --track-order 0:1,1:0
I find this a bit slower than direct mencoder-encoding. So is x264 in avi-container really bad thing, or am I just wasting my time?
P.S. any tips for my settings?
It's actually possible to output a "raw" H.264 stream with Mencoder. Here's an example: http://lists.mplayerhq.hu/pipermail/mencoder-users/2006-May/003316.html
IIRC that needs to be first muxed to MP4 with MP4Box, since mkvmerge can't read the raw H.264 file directly.
garbii
15th July 2006, 12:31
I would have some questions :
Does new mencoder support mp4 conteiner only for x264 and FAAC audio ?
I'm askining becouse I make x264 +mp3lame ... and well I get the info in mencoder "Output format is avi , see -o avi for help"
Well sth like that ...
The encodes finish and I can play files with mplayer ... however I'm wondering if it's an mp4
Those are my settings :
mencoder -vf scale=544:271::: -ovc x264 -x264encopts bitrate=275:bframes=5:frameref=10:keyint=3000:weight_b:turbo=1:pass=1 /home/vl/05.avi -o /dev/null -nosound
mencoder -vf scale=544:271::: -ovc x264 -x264encopts bitrate=275:bframes=5:frameref=10:keyint=3000:weight_b:pass=2 /home/vl/05.avi -o /home/vl/ergoproxy05.mp4 -oac mp3lame -lameopts mode=3:vbr=3:br=32
Now I suspect that the output file is an avi ... but with an extension .mp4 ....
Anybody knows how it works ? and can confirm or deny ?
Now I suspect that the output file is an avi ... but with an extension .mp4 ....
That's right because Mencoder outputs AVI by default and you didn't tell it to do otherwise (no, it doesn't look at the output filename extension). You'll need to use the -of option. Read the manual or run "mencoder -of help" to get a list of container formats. Also note "-of lavf" which uses libavformat muxers; the format can be chosen with -lavfopts.
MP4 output can be selected with "-of lavf -lavfopts format=mp4", but the MP4 muxer in libavformat could still be buggy. However, I haven't followed FFmpeg's mailing list for a while, so it may be fixed already. If not, you can always use the raw output (-of rawvideo) and an external muxer (see the example I referred to in my previous post).
garbii
19th July 2006, 00:27
^ thanks for the answer ...
MP4 output can be selected with "-of lavf -lavfopts format=mp4", but the MP4 muxer in libavformat could still be buggy.
-lavfopts format=mp4 -oac copy -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames
^ this is how it's done :-P
well so it is buggy .... at least with b-frames...
................................
You seem to know much about x264 encoding nm so I'll ask a quaestion
Why is avi container bad ? I've heard it's becouse the audio sometimes desync when reencoding editing the file ... Is this the only reason ?
if so then is making an h.264 video without sound in avi container and the sound in external file with mencoder , and then muxing it all in th mp4 container with avidemux a good idea ???
akupenguin
21st July 2006, 19:37
If you're going to mux to mp4 at the end, then have mencoder output an h264 elementary stream, (-of rawvideo), not an avi.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.