Log in

View Full Version : MENCODER + x264 and commands


lib3rty1
29th September 2010, 17:40
Hi,
I am looking for commands that I could use to recode movies with mencoder from console.
I am looking commands for small file size and decent quallity that could be similar size with rmvb but with better quality, high quality and medium one.
Is it possible to find sth like that ?

nm
29th September 2010, 21:08
1. Encode the video track to a H.264 elementary stream

mencoder -nosound -of rawvideo -ovc x264 -x264encopts preset=slower:tune=film:crf=20 -o out_video.264 in.ts

Where in.ts is the source and out_video.264 is the output H.264 ES file.
For information on x264 encoding parameters, see x264 --fullhelp, MPlayer/MEncoder manual page (http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.txt) (search for x264encopts) and the MeWiki article (http://mewiki.project357.com/wiki/X264_Settings). Search Doom9/10 for further insights.

2. Decode audio to WAV for feeding it to NeroAacEnc

mplayer -nocorrect-pts -vo null -vc null -ao pcm:file=out_audio.wav:fast in.ts

You could use a named pipe to avoid writing the WAV file on disk (see this (http://forum.doom9.org/showthread.php?p=1226337#post1226337) if you are on Windows or this (http://sites.google.com/site/linuxencoding/x264-encoding-guide) if on Linux/Unix).

If you want to encode to MP3, use LAME through MEncoder or ffmpeg, or separately.

If you want to keep the original audio without re-encoding, you can dump it with MPlayer (mplayer -dumpaudio -dumpfile out_audio.ac3 in.ts) or possibly read it directly with mkvmerge in case it's in a supported container (for example: mkvmerge out_video.264 -D in.avi -o out.mkv).

3. Encode audio with neroAacEnc

neroAacEnc -ignorelength -q 0.5 -if out_audio.wav -of out_audio.mp4

4. Mux to a container

mkvmerge --default-duration 0:24000/1001fps out_video.264 out_audio.mp4 -o out.mkv

Note the framerate setting with --default-duration. Mkvmerge doesn't read framerate hints from H.264 elementary streams and it defaults to 25 fps. Check the source for the correct framerate. It's 25 fps for PAL DVDs and DVB captures and 24000/1001 fps for progressive NTSC DVDs and most Blu-ray movies.

Alternatively, mux to MP4 with MP4Box:

MP4Box -fps 23.976 -add out_video.264 -add out_audio.mp4 out.mp4

But note that there is a compatibility (http://forum.doom9.org/showthread.php?p=1427447#post1427447) problem (http://forum.doom9.org/showthread.php?p=1430698#post1430698) with current x264 versions and older MP4Box builds. Get one of the builds mentioned in the end of that problem thread or compile a patched version yourself.