I am trying to generate a video from a bunch of png images and audio using the command:

/usr/bin/ffmpeg -y -framerate 30 -pattern_type glob -i 'images/*.png' -i audio.wav -c:v libx264 -b:v 0 -crf 18 -g 300000 -pix_fmt yuv420p -shortest output.mp4

There are a total of 52 images with their FFprobe output as below:

Input #0, png_pipe, from 'images/0000000.png':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, rgb24(pc), 1200x1000, 25 tbr, 25 tbn, 25 tbc

And FFprobe output for audio.wav is:

Input #0, wav, from 'audio.wav':
    encoder         : Lavf58.29.100
  Duration: 00:00:01.74, bitrate: 256 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, 1 channels, s16, 256 kb/s

At 30 fps, the length of output video should be 1.734s, but actually, it is 1.80s.

FFprobe output for final video:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:01.80, start: 0.000000, bitrate: 1627 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1200x1000, 1603 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 74 kb/s (default)
      handler_name    : SoundHandler

Can someone help me understand why is there a difference and how can I remove it?

My use case requires that the video is of the same length as that of audio otherwise it will cause issues. Any help will be appreciated.

  • Have you got any explanation?
    – Sam
    Commented Apr 11, 2023 at 6:42

1 Answer 1


What you can do is use -shortest to stop encoding once the shortest stream ends. This option needs to be given before the output file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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