Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have video frames in PNG format at 1 FPS and I'm trying to convert them into a video using ffmpeg.

If I do something like this:

ffmpeg -i data/input-%4d.png data/output.mp4

I get a video at 25FPS which is basically a very fast-forward of the input (which is captured at 1FPS).

If I try:

ffmpeg -i data/input-%4d.png -r 1 data/output.mp4

I get something that VLC doesn't want to play :)

Now, if I take the first video (the FF one) and apply a filter to slow it down (e.g. -filter:v 'setpts=24.0*PTS'), I can get it to play like a 1 FPS video, but of course the price is file size. It's generating a bunch of repeated frames I guess.

So, the question is how do I create a video that has exactly 1 FPS and actually plays at that speed? The output format, btw, isn't that important for me.

share|improve this question
    
I'm not sure ffmpeg is smart enough to figure out the video codec just from the container format file extension, .mp4. Try adding -vcodec libx264 -vpre hq to the command line, to tell it the codec and encoding parameters. –  Warren Young Mar 22 '13 at 7:09
    
It actually figured it out ok, and I as mentioned it worked well and only produced weird results when I added -r 1. –  Assaf Lavie Mar 22 '13 at 7:43
    
I think you may have better luck at a ffmpeg answer on stackoverflow.com or superuser.com. –  Damien May 4 '13 at 18:21

2 Answers 2

If you want a one-liner for FFMPEG that generates a video that plays at 1 frame per second, what you want to do is specify framerates for both input and output, like this:

ffmpeg -r 1 -i data/input-%4d.png -pix_fmt yuv420p -r 10 data/output.mp4

The -r 1 means the video will play at 1 of the original images per second.
The -r 10 means the video will play at 10 frames per second.

(The -pix_fmt yuv420p is just there to ensure compatibility with a wide range of playback programs. It is required here, for example, for the video to be playable by Windows Media Player.)

I tested many different output framerates, and 10 seems to be the lowest number you can use that will still produce a video that VLC will play.

Of course, the command above means each original image is being multiplied, but it is a simpler method than the "slow it down" one you mentioned, and depending on the codec it may not produce a video much larger than a true 1-FPS video.

To test this, I just produced a true 1-FPS video, which came out to 2.24 kiB. I then produced a video with the same input images but output at 24 FPS, and it came out to 5.76 kiB. That's just over double the size, and nowhere near 24 times the size. :)

share|improve this answer
    
+1 on -pix_fmt. Easy to forget some people insist on using WMP :-) –  Smalltown2k Jul 14 at 14:37

What if you augment your second example slightly as follows:

$ ffmpeg -r 1 -i data/input-%4d.png -c:v libx264 out.mp4

The -r 1 needs to come before the .png files, not after.

From the FFmpeg documentation:

As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file.

share|improve this answer

Your Answer

 
discard

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.