如何用FFmpeg按帧步长20将图片序列转视频?当前命令未筛选帧
Got it, let's fix this for you! Your current command is including every frame from 1 to 400 because it lacks a filter to skip frames at your desired step of 20. Here's the adjusted command and a breakdown of how it works:
Correct FFmpeg Command
!ffmpeg -start_number 1 -i images%05d.jpg -vf "select='mod(n,20)==0',setpts=N/FRAME_RATE/TB" -vcodec mpeg4 result.mp4
What Each Component Does
select='mod(n,20)==0': This filter picks frames where the 0-based frame indexn(your first input frameimages00001.jpgisn=0) is divisible by 20. This means you'll get frames numbered 1, 21, 41, ..., 381 (the last valid frame before exceeding 400).setpts=N/FRAME_RATE/TB: When you skip most frames, FFmpeg would otherwise play the remaining frames at the original speed, making the video way too fast. This filter adjusts the presentation timestamps to ensure the video plays at a normal, smooth pace.- Removed
-vframes 400: Since we're explicitly selecting frames with theselectfilter, we don't need to limit the total frame count anymore. For your range (1 to 400), this command will output exactly 20 frames.
Alternative: Match File Numbering Directly
If you want to frame the selection based on your actual file numbers (instead of the internal index), use this command—it’s more intuitive for matching your named files:
!ffmpeg -start_number 1 -i images%05d.jpg -vf "select='mod(frame_num-1,20)==0',setpts=N/FRAME_RATE/TB" -vcodec mpeg4 result.mp4
Here, frame_num uses the 1-based number from your filenames. frame_num-1 converts it to a 0-based index, so the logic stays aligned with your step of 20. This won’t include images00400.jpg (since 400-1=399, which isn’t divisible by 20), but it’s a robust way to mirror your file naming structure.
内容的提问来源于stack exchange,提问作者Brian Sanchez

