You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用FFmpeg将JPG序列生成动画:消除左右黑边及尺寸适配

Fixing FFmpeg Animation Issues: Black Bars & "Past Duration" Warnings

Hey there, let's work through your problems with converting JPGs to an AVI animation step by step. I'll break this down into the two main issues you're facing, plus give you clear guidance on resizing your images properly.

1. Getting Rid of the Left/Right Black Bars

Your original images are 1200x900, which has a 4:3 aspect ratio. The black bars appear because FFmpeg is defaulting to a standard resolution (like 16:9) that doesn't match your image's natural ratio. Here are two solid fixes:

  • Option 1: Match output to your exact image size
    Add the -s flag to explicitly set the output resolution in your FFmpeg command:

    ffmpeg -f image2 -i img%04d.jpg -r 24 -s 1200x900 sound.avi
    
  • Option 2: Force the correct aspect ratio (more flexible)
    Use a video filter to lock the 4:3 ratio, which prevents accidental stretching if you ever adjust sizes later:

    ffmpeg -f image2 -i img%04d.jpg -r 24 -vf "scale=1200:900,setdar=4/3" sound.avi
    

Resizing Images with convert (If Needed)

If you want to resize your JPGs first, always keep the 4:3 aspect ratio to avoid future black bars. For example:

  • To shrink to 800x600 (still 4:3):
    convert img%04d.jpg -resize 800x600 resized_img%04d.jpg
    
  • The -resize flag in ImageMagick automatically maintains aspect ratio—use 800x600^ (caret) to fill the exact size, or just 800x600 to fit within those dimensions without cropping.

2. Fixing the "Past Duration X too large" Warnings

These warnings pop up when FFmpeg struggles to sync input image timestamps with your specified output frame rate. Try either of these quick fixes:

  • Use variable frame rate sync
    The -vsync vfr flag tells FFmpeg to adapt to the input's natural timing, eliminating timestamp mismatches:

    ffmpeg -f image2 -i img%04d.jpg -r 24 -vsync vfr -s 1200x900 sound.avi
    
  • Generate proper presentation timestamps
    If the first fix doesn't clear the warnings, add -fflags +genpts to force FFmpeg to create accurate timestamps for each frame:

    ffmpeg -f image2 -i img%04d.jpg -r 24 -fflags +genpts -s 1200x900 sound.avi
    

You can even combine both flags for extra safety—they won't conflict with each other.

内容的提问来源于stack exchange,提问作者Clinton Winant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:31:22