I just tried your command line and it worked as expected. Your problem might lie with the sound format. Does transcoding the sound work?
–
Captain GiraffeMay 4 '11 at 17:49

By "as expected" do you mean the resulting video has the same duration as the audio input? Have you played it? Isn't it one-frame-long?
–
matteoMay 4 '11 at 17:59

Sound format is not the problem, transcoding the sound works
–
matteoMay 4 '11 at 17:59

I've just found the solution: the order of options matters (a bug I think). The -loop_input -shortest options need to be the first options or they are completely ignored. I'll post the working command line as an answer
–
matteoMay 4 '11 at 18:00

7

Can you provide an answer yourself below and accept it as the answer to the question (you'll have to wait a day)? That's how questions get marked as resolved around here, rather than editing the title.
–
edoloughlinMay 14 '11 at 17:21

9 Answers
9

NOTE: this answer of mine has been arbitrarily edited by a lot of people, even adding significant code to the command lines I provided. I am no longer responsible for whatever is written in this answer and I have no idea whether it still works, because this is not the answer I gave and tested.

The order of options in the command line matters. The following works for my case:

How come the files end up so much bigger than [size of image] + [size of audio file]? I would expect the video compression to go crazy with a constant frame?
–
mangledorfApr 13 '12 at 7:01

2

It depends on the video codec you use. If you are copying the commands in my examples, I'm using mjpeg as the codec, which compresses each frame separately, so it takes no advantage of the fact that all frames are equal. Also, I think that even other codecs would recode the whole frame every once in a while, i.e. every N-th frame, so you would get a much smaller file but still much bigger than just the size of the image+sound. They do so because (a) otherwise the decoder would need to read the whole file from the beginning even if you just want to jump to the last frame, and
–
matteoApr 13 '12 at 10:43

(b) any error or bit corruption during the transmission at a given moment would affect the decoded video starting from that point forever, would never recover
–
matteoApr 13 '12 at 10:43

The only attributes you have to specify are the input filenames, the output codecs, and the output filename (which eo ipso includes the output container, ).

Of course, it makes sense to start with a still image that shares the same dimensions as your eventual video; if you are using a dedicated image editor instead of specifying output dimensions for FFmpeg to meet, you need to make sure your input dimensions are even numbers.

Output size is one of FFmpeg's most common hang-ups; some codecs are more restricted in output dimensions than others, but no output can have odd-number height- or width attributes.

The pause command at the end of the batch file keeps the CLI open--the best way to debug your command line is by reading the error messages it generates. They are extremely specific--and the best documentation FFmpeg has--but the developers' hard work is wasted if you allow the window to close before you can read them.

The command shell has a switch cmd /k that maintains an open window where you can run the same the same instructions from your batch script at the command prompt.

FFmpeg and avconv will both make you use -c:a for -acodec and -c:v for -vcodec eventually, but the old instructions work fine in the builds I use.

Nota Bene: Every commit has idiosyncracies. If your command line is failing for no apparent reason, it is often helpful to try another build--or follow the fork over to libav, where FFmpeg's most active developers have been for the last couple of years. Their transcoding tool has been renamed avconv but your batch files should work with either one.

I must be using a different version than youurs (if you have tried your command and it works as you describe), because, as I already mention in the question, I had already tried your exact same command and I get a video of the duration of 1 frame (a fraction of a second), NOT the duration of the audio file. I did expect it to be intelligent, but (in my version) it proved to be not.
–
matteoDec 16 '12 at 19:59

1

Hey Matteo, yes, I did execute that code, and yes, it works as advertised. I'm sure there are plenty of halfwits that would be so careless as to make such claims without testing them, so I'll try not to be offended :) In a full post below I will supply Pastebin links to FFmpeg console output and MediaInfo data on input files and final output file. My input files, my batch file, my output file are on a GoogleDrive where they are freely downloadable, if you would like to test them against your FFmpeg build.
–
patronanejoJan 5 '13 at 12:59

@ShinMuraoka Mine is a win-64 ffmpeg build compiled on: Jan 6 2013, at: 16:16:53 Neither your solution nor @matteo solution worked for me. Also, I downloaded your files from Google Drive, but it didn't gave the expected output (the output file was black contained only audio). Please help me in figuring out the right command to be used.
–
coding_idiotJan 8 '13 at 17:47

"no output can have odd-number height- or width attributes" Not true. Set pix_fmt to something that doesn't have chroma subsampling, like rgb24 or yuv444p, then make sure the codec and container support it and have no further restrictions. With regards to pix_fmt, FFmpeg is less than intelligent; it assumes yuv420p (which has chroma subsampling) unless you tell it otherwise.
–
Jonathan BaldwinMay 29 '13 at 2:49

Every build of FFmpeg has its quirks, but I'm surprised such a simple command string doesn't deliver the expected results for you. Even if you have a strong reason to hold on to your current version, you can keep any number of builds at hand. I currently have two (static builds) in my %PATH% directory, named ffmpeg and ffmpeg2.

Hi, I am also searching a way to create a video by combining an audio file and an image, within the android code. I figured out the command for that: ffmpeg -i allmapeople.mp3 -i Penguins.jpg video_finale.mpg I tried many 2 tutorials using ffmpeg that generates the .so file. But I still could not find out a way to combine an audio and an image. Please help me!!!
–
TharakaNirmanaJan 15 '13 at 5:19

Checkout the the option -shortest must to be in front of the output file if not I get the below error:

Option shortest (finish encoding within shortest input) cannot be applied to input file pic.jpg -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for input file pic.jpg.