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

FFmpeg中音频时长更长时为视频追加黑帧的实现方法

Solution to Match Output Duration to Audio and Pad Video with Black Frames

Got it, let's tackle this problem. You're using FFmpeg because other editors drop frames, and right now your trimmed video is shorter than the trimmed audio—you want the final output to match the audio's duration by adding black frames to the end of the video.

First, the core issue here is that there's no direct "opposite of -shortest" flag, but we can use FFmpeg's tpad video filter to append black frames to the video until it matches the audio's length. Here's how to do it:

Step 1: Calculate the Duration Difference

First figure out how much extra time you need to add to the video. Your audio is trimmed to 00:09:54.38 (594.38 seconds) and the video to 00:09:51 (591 seconds)—the difference is 3.38 seconds.

Step 2: Modified FFmpeg Command

Use the tpad filter to add black frames to the video's end, then combine it with the trimmed audio:

-i "videoplayback1" -t 00:09:51 -vf "tpad=stop_mode=black:stop_duration=3.38" -c:v libx264 -crf 20 -i "audioplayback1" -t 00:09:54.38 -c:a copy -map 0:v -map 1:a "playback1.mp4"

Let's break down the key parts:

  • -vf "tpad=stop_mode=black:stop_duration=3.38": The tpad filter appends frames to the video. stop_mode=black tells it to add black frames, and stop_duration sets how long the padding should be.
  • -map 0:v -map 1:a: Explicitly maps the video from the first input and audio from the second input—this avoids any automatic stream selection issues FFmpeg might have.
  • -c:a copy: Copies the audio stream directly without re-encoding, which saves time and preserves quality.

Alternative: Auto-Calculate the Padding Duration (No Manual Math)

If you don't want to calculate the difference manually, you can use ffprobe to get the audio's trimmed duration first, then pass that to FFmpeg to pad the video to match:

  1. First, get the trimmed audio duration in seconds:

This will output a number like 594.38.

  1. Then use that value in the FFmpeg command to pad the video to exactly that length:
-i "videoplayback1" -t 00:09:51 -vf "tpad=stop_mode=black:stop_duration=594.38" -c:v libx264 -crf 20 -i "audioplayback1" -t 00:09:54.38 -c:a copy -map 0:v -map 1:a "playback1.mp4"

This ensures the video is extended to match the audio's trimmed length perfectly.

Notes

  • Since we're re-encoding the video with libx264, make sure your FFmpeg build includes this codec (most standard builds do).
  • The tpad filter works seamlessly with H.264 encoding, so the black frames will blend naturally with the rest of the video.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:00:41