Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Mencoder Cheat Sheet
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Tux's lil' helper
Tux's lil' helper

Joined: 08 Mar 2005
Posts: 84

PostPosted: Thu Dec 01, 2005 2:03 am    Post subject: Mencoder Cheat Sheet Reply with quote

Mencoder Cheat Sheet

A quick cheat sheet for some common and obvious mencoder tasks

Note: some of these use mplayer (not mencoder). I think the one Package gives you both programs anyway. The two programs share a common man page. These are methods I have figured out over a period of a month or two or so, by browsing the fourms, searching the web, combing through the mplayer/mencoder man page ... not to mention much time with my old friends Trial and Error.

0. extract/cut

To extract part of a video into a new file, with no re-encoding (and thus no degradation of quality):

mencoder -of mpeg -idx -oac copy -ovc copy \
  infile.mpg  \
  -ss [H:]MM:SS[.tenths] \
  -endpos [H:]MM:SS[.tenths] \
  -o outfile.mpg

Note that endpos is actually the length of the extracted segment. It is not the end time of the extracted segment. So to extract video from 12 minutes in to 14 minutes in, use "-ss 12:00 -endpos 2:00", not "-ss 12:00 -endpos 14:00".

Also note that you will not achieve frame-accurate cuts. mpeg video, like mpeg audio, is in packets/chunks and mencoder will not split a packet. I myself edit/cut only to a half-second precision.

1. Make A File Containing Only The Video (no audio)

Warning: this generates one warning (when played back in gmplayer) about too many video packets, but it keeps playing anyway so I dismiss it.

mencoder -of mpeg -idx -ovc copy -nosound in.mpg -o out.mpg

2. Make A File Containing Only The Audio

Oddly enough we use mplayer, not mencoder, for this task.

mplayer -novideo input_video.mpg -dumpaudio -dumpfile out_audio.mp3

I think maybe the audio file is in whatever format the audio was originally encoded as, so it might not always be mp3.

3. Add Audio to Video

Take a mpeg file with no audio in it (just video) and take an audio file (for some reason wav works for me but not mp3) and create a new mpeg file with the sound and video combined into one file. The video is not re-encoded so there is no picture degradation.

mencoder -of mpeg -idx -ovc copy -oac mp3lame \
  -lameopts cbr -lameopts br=128 -lameopts aq=0 -lameopts mode=0 \
  -audiofile audio_in.wav video_in.mpg -o mixed_output.mpg

Note that "mode=0" is stereo and "aq" is encoding quality (0 is best). "br" is the bitrate. It is set to 128 in that above. Set to your taste. When the audio is shorter than the video it bitches.

4. Extract Single Frames

Many methods of doing this have been discussed. Some work for for one person and not for another. Grabbing from a paused gmplayer only works depending on how your graphics driver in x-windows is set up (ever since I got 3d hardware acceleration to work, I can't grab frames anymore). Some people have even resorted to a "cvs" or non-portage version of mplayer/mencoder.

This next bit works (well, for me, anyway) with the portage version of mplayer. Targa output doesn't work (darnit!) so we use png instead.

mplayer infile.mpg -ss 0:00:40 -vf format=bgr24 -vo png -nosound -frames 2

In the above example, we've set it to grab 1 frame, 40 seconds in. The -ss parameter is the start position, exactly as it is in mencoder.

Set frames to 2 to grab one frame. Setting it to 1 results in no output at all. Best to set the frames to get a full seconds worth of time (-frames 60 works for me) and then pick the picture you want later.

The output png files will have arbitrarily assigned names and they will be in the current directory.

That's all. I hope some people find it useful. Hopefully I have not had any typos. Everything listed here has worked for me.
Back to top
View user's profile Send private message

Joined: 31 Jul 2004
Posts: 1886

PostPosted: Thu Dec 01, 2005 11:00 am    Post subject: Reply with quote

Anyone has a mencoder line that encodes (playable) .wmv files to a decent xvid or other mpeg4 codec?

I have wmv videos which mplayer plays fine (they do not have drm protection or such crap), but if I encode them to mpeg4 avi with mencoder I get lousy blocky picture as if he used 50 kbit/s instead of the 1000 kbit/s I allowed him to use. Tried every configuration I can think of, always the same result.

Thanks for any suggestions

Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum