Producing stable video from slow images with FFmpeg
2013-08
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%
I'm not sure why the players won't work with 1 fps, but you can use a separate -r
for both your input and output:
ffmpeg -r 1 -i %02d.png -r 25 video.mp4
Notes:
-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 thenmpeg4
(MPEG-4 Part 2 video) will be used.
Just out of curiosity it might be interesting to find out the lowest output -r
value that works in all of your players.
Also see:
How do I encode single pictures into movies?
FFmpeg and x264 encoding Guide
I need to split video files and at the same time convert them to mp4 for a website. I have troubles splitting AVI files (flv and mp4 worked fine).
Example:
> ffmpeg -i original-1.avi -ss 00:03:00 -t 00:00:20 -acodec copy -vcodec libx264 -vpre hq -s 416x240 -y 1.mp4 Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (30000/1) -> 25.00 (25/1) Input #0, avi, from 'original-1.avi': Metadata: ISFT : Nandub v1.0rc2 INAM : Rammstein - Links 2-3-4 ISBJ : Rammstein - Links 2-3-4 IART : ICOP : Coded by Hermit (DivX 5.0.3) 15.04.06 ICMT : Duration: 00:03:34.48, start: 0.000000, bitrate: 1630 kb/s Stream #0.0: Video: mpeg4, yuv420p, 704x406 [PAR 1:1 DAR 352:203], 25 fps, 25 tbr, 25 tbn, 30k tbc Stream #0.1: Audio: mp3, 48000 Hz, 2 channels, s16, 160 kb/s [libx264 @ 0x804215810]using SAR=1/1 [libx264 @ 0x804215810]using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 [libx264 @ 0x804215810]profile High, level 1.3 [libx264 @ 0x804215810]264 - core 110 - H.264/MPEG-4 AVC codec - Copyleft 2003-2010 - http://www.videolan.org/x264.html - options: cabac=1 ref=4 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 constrained_intra=0 bframes=3 b_pyramid=0 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=200 ratetol=20.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 ip_ratio=1.41 aq=1:1.00 Output #0, mp4, to '1.mp4': Metadata: encoder : Lavf52.64.2 Stream #0.0: Video: libx264, yuv420p, 416x240 [PAR 1:1 DAR 26:15], q=10-51, 200 kb/s, 25 tbn, 25 tbc Stream #0.1: Audio: libmp3lame, 48000 Hz, 2 channels, 160 kb/s Stream mapping: Stream #0.0 -> #0.0 Stream #0.1 -> #0.1 Press [q] to stop encoding [mpeg4 @ 0x804214410]Invalid and inefficient vfw-avi packed B frames detected frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 0 fps= 0 q=0.0 size= 0kB time=10000000000.00 bitrate= 0.0kbits/s frame= 8 fps= 1 q=405.0 size= 0kB time=0.74 bitrate= 0.5kbits/s frame= 50 fps= 5 q=37.0 size= 13kB time=0.32 bitrate= 338.7kbits/s frame= 65 fps= 6 q=35.0 size= 38kB time=0.92 bitrate= 334.9kbits/s frame= 68 fps= 6 q=35.0 size= 43kB time=1.04 bitrate= 342.6kbits/s frame= 76 fps= 6 q=35.0 size= 56kB time=1.36 bitrate= 340.3kbits/s frame= 92 fps= 7 q=35.0 size= 85kB time=2.00 bitrate= 349.6kbits/s frame= 112 fps= 8 q=34.0 size= 118kB time=2.80 bitrate= 346.2kbits/s frame= 132 fps= 9 q=35.0 size= 158kB time=3.60 bitrate= 359.8kbits/s frame= 151 fps= 10 q=31.0 size= 193kB time=4.36 bitrate= 363.3kbits/s frame= 168 fps= 11 q=34.0 size= 223kB time=5.04 bitrate= 362.3kbits/s frame= 187 fps= 12 q=34.0 size= 258kB time=5.80 bitrate= 3