Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use mencoder to make a video that has music playing over a single image. I'm using mf to add the image and I always get a video with about one second of audio with a reported length of 0:00. I've tried with a variety of mp3's and images from different sources and I tried using various codecs and options but I can't seem to get past this problem. Here's the basic command:

mencoder "mf://image.jpg" -o out.avi -ovc lavc -lavcopts vcodec=mjpeg -audiofile music.mp3 -oac copy

Does anyone know how to do this or why mencoder cuts the music to one second?

share|improve this question

It's because the default FPS is set to 30, so mencoder expects 30 images per second -- you have to tell mencoder to use one image for whole record, so you have to set FPS to 1/"duration".

Add this options:

-fps 1/132.8 -ofps 30

where 132.8 is duration (in seconds) of your audio.

So result should look like this:

mencoder mf://image.jpg -o out.avi \
        -ovc lavc -lavcopts vcodec=mjpeg -audiofile music.mp3 \
        -oac copy -fps 1/132.8 -ofps 30
share|improve this answer
That did the trick. Encoding size wasn't an issue - I can get a file that is basically the size of the mp3 and jpg together. – Tim Dec 23 '10 at 18:56
Just one problem - I can't seek through the video. I thought -idx would work but it didn't help - even when running a second pass just with idx and a/v copy. I also tried -forceidx and setting keyint in avcopts. Is it not possible when there's no scene changes? – Tim Dec 23 '10 at 19:50
You can just put 1/100000 and this will work too. (Thanks btw) – Dorian Jan 20 '12 at 14:07

I only have came with an alternative where you would provide the same image from a pipe:

for x in `seq 1 55`; do cat image.jpg; done | mencoder -o out.avi -fps 1 -ovc lavc -demuxer lavf -lavfdopts format=mjpeg -audiofile music.mp3 -oac copy -

where you would replace 55 with the number of seconds you wish (this would be the length of the song, as you wish).

But, as you can see, it's dumber than the simple and straight-to-the-point answer by Vojtech. Only advantage I got with this alternative of mine was a smaller resulting file size.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.