1

I am attempting to animate a series of PNG images at 30 frames per second (and add an audio track) with FFmpeg.

On the command line, I specify the input and output frame rates as 30 fps.

ffmpeg.exe -r 30 -i %d.png -itsoffset 0.770 -i soundtrack.wav -r 30 -vcodec mpeg4 -y "ffmpegtest.mp4"

The output shows that it is reading the input images at the default 25 frames per second.

    ffmpeg version N-82225-gb4e9252 Copyright (c) 2000-2016 the FFmpeg developers
      built with gcc 5.4.0 (GCC)
      configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
      libavutil      55. 35.100 / 55. 35.100
      libavcodec     57. 66.101 / 57. 66.101
      libavformat    57. 57.100 / 57. 57.100
      libavdevice    57.  2.100 / 57.  2.100
      libavfilter     6. 66.100 /  6. 66.100
      libswscale      4.  3.100 /  4.  3.100
      libswresample   2.  4.100 /  2.  4.100
      libpostproc    54.  2.100 / 54.  2.100
    Input #0, image2, from '%d.png':
      Duration: 00:02:24.00, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: png, rgba(pc), 480x320, 25 fps, 25 tbr, 25 tbn, 25 tbc

[I'll interrupt here to say it is that last line that confuses me]

    Guessed Channel Layout for Input Stream #1.0 : stereo
    Input #1, wav, from 'soundtrack.wav':
      Duration: 00:06:51.26, bitrate: 1411 kb/s
        Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
    Output #0, mp4, to 'ffmpegtest.mp4':
      Metadata:
        encoder         : Lavf57.57.100
        Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 480x320, q=2-31, 200 kb/s, 30 fps, 15360 tbn, 30 tbc
        Metadata:
          encoder         : Lavc57.66.101 mpeg4
        Side data:
          cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
        Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 128 kb/s
        Metadata:
          encoder         : Lavc57.66.101 aac
    Stream mapping:
      Stream #0:0 -> #0:0 (png (native) -> mpeg4 (native))
      Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
    Press [q] to stop, [?] for help
    [image2 @ 0000000000622cc0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
    frame= 3600 fps=242 q=19.1 Lsize=    9908kB time=00:06:52.04 bitrate= 197.0kbits/s speed=27.7x
    video:3263kB audio:6494kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.540179%
    [aac @ 000000000064e600] Qavg: 448.922

I am fairly new to FFmpeg. What am I missing? How do I tell it the input stream is 30 fps?

1

With image sequences, you have to use the framerate option. So,

ffmpeg -framerate 30 -i %d.png -itsoffset 0.770 -i soundtrack.wav -vcodec mpeg4 -y "ffmpegtest.mp4"

With -r specified before the sequence name, FFmpeg assumes 25 fps and duplicates/drop frames to meet the set rate.

  • I don't completely understand the last sentence yet, but it solved the problem, thank you. – Oddthinking Nov 5 '16 at 16:46
  • Let's say you set -r 50. FFmpeg treats the input as having a native rate of 25 and duplicates each frame to make it 50 fps. If you set -r 10, it drops 3 out of every 5 frames. – Gyan Nov 5 '16 at 16:49
  • Right, I expected that to be true if I had the -r on the output only, and not on the input. I expected the first -r on the command line to affect the input, preventing that. (Clearly, I was wrong!) Looking at section 5.5 of the manual, it seems it used to work they way I expected. Perhaps I got my misunderstanding from an old web-site. Thanks for clearing it up. – Oddthinking Nov 5 '16 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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