Producing stable video from slow images with FFmpeg

5

2

I'm struggling to achieve stable ffmpeg outputs that work across players and platforms for a video produced from a series of images that need to roll at about 1 fps.

ffmpeg -f image2 -r 1 -i %02d.png video.avi takes files named '01.png, 02.png' etc and outputs at 1 fps. But the result won't play on VLC or Quicktime - only WMP seems to handle it.

ffmpeg -f image2 -r 25 -i %02d.png video.mp4 does produce more stable output, but only at speeds around 25 fps - much too fast for my data viz.

Very grateful for assistance. It seems pointless to create duplicate images to resolve this.


The console output:

ffmpeg version N-53284-gd0a34ae Copyright (c) 2000-2013 the FFmpeg developers
  built on May 20 2013 01:07:40 with gcc 4.7.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzli
b --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libblu
ray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libr
tmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwola
me --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264
 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 33.100 / 52. 33.100
  libavcodec     55. 10.101 / 55. 10.101
  libavformat    55.  7.100 / 55.  7.100
  libavdevice    55.  1.100 / 55.  1.100
  libavfilter     3. 68.101 /  3. 68.101
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
[image2 @ 00000000025977e0] max_analyze_duration 5000000 reached at 5000000 microseconds
Input #0, image2, from '%02d.png':
  Duration: 00:00:40.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, pal8, 1300x1100, 1 fps, 1 tbr, 1 tbn, 1 tbc
Output #0, avi, to 'video.avi':
  Metadata:
    ISFT            : Lavf55.7.100
    Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1300x1100, q=2-31, 200 kb/s, 1 tbn, 1 tb
c
Stream mapping:
  Stream #0:0 -> #0:0 (png -> mpeg4)
Press [q] to stop, [?] for help
frame=   40 fps=6.6 q=31.0 Lsize=    3754kB time=00:00:40.00 bitrate= 768.9kbits/s
video:3748kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.173624%

geotheory

Posted 2013-05-30T16:58:14.107

Reputation: 919

Please include the complete ffmpeg console output from your first ffmpeg command. – llogan – 2013-05-30T17:24:39.763

Thanks @LordNeckbeard that works for me :) Give it as an answer and I'll tick it. – geotheory – 2013-05-30T22:14:30.370

Answers

7

I'm not sure why the players won't work with 1 fps, but you can use -framerate for your input, and -r for your output to set different frame rates:

Example

ffmpeg -framerate 1 -i %02d.png -r 25 -pix_fmt yuv420p video.mp4

Notes

  • Image inputs use -framerate to set frame rate, while video output uses -r.

  • -f image2 is usually not required since the demuxer will recognize your inputs as images.

  • In this example ffmpeg will duplicate frames to reach the higher output frame rate, but it will still show the same "image" for each second.

  • Some encoders and containers may be limited in the frame rates that they support, but they will often let you know in the ffmpeg console output.

  • By default ffmpeg will use libx264 (H.264 video) as the encoder for MP4 container output. If it is unavailable then mpeg4 (MPEG-4 Part 2 video) will be used.

  • -pix_fmt yuv420p will output a widely compatible chroma subsampled output.

Just out of curiosity it might be interesting to find out the lowest output -framerate value that works in all of your players.

Also see

llogan

Posted 2013-05-30T16:58:14.107

Reputation: 31 929

From http://superuser.com/questions/632455/ffmpeg-for-animation-of-image-files-outputs-all-black-video, where I was struggling with a similar issue and ended up using your work-around (though it's a shame multiple copies of the same frame are required!): A -r value of 3 (but not 1, which is the next lower value I tried) solves an issue where Windows Media Player will spend too much time on the first frame of the low-FPS video and not enough time on the rest. A -r value of 10 (but not 5, the next lower value tested) solves an issue where VLC refuses to play the low-FPS video at all!

– A.M. – 2013-08-15T22:33:11.523