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

如何使用ffmpeg在指定时间为视频添加多段音频

Got it, let's expand on your existing FFmpeg command to handle multiple audio tracks easily. Your current command uses the concat filter to join a 30-second silent track with a single input audio—scaling this to 2, 3, or more audio clips just requires extending that concat chain correctly.

First, let's recap your original command logic

Your command does two key things:

  1. Generates a 30-second silent audio track with aevalsrc=0:d=30[s1]
  2. Uses concat to join that silent track with your input audio ([s1][1:a]concat=n=2:v=0:a=1[aout]), where n=2 tells FFmpeg you're joining 2 audio segments

Adding 2 audio clips (plus the initial silent track)

To add a second audio file, you just need to:

  • Add another -i flag for the second audio file
  • Update the concat filter to include this new audio stream, and set n=3 (since we now have 3 segments: silent + audio1 + audio2)

Here's the command:

ffmpeg -i input_video.mp4 -i audio1.mp3 -i audio2.mp3 -filter_complex "
  # Generate 30-second silent track
  aevalsrc=0:d=30[s1];
  # Concatenate silent track + audio1 + audio2
  [s1][1:a][2:a]concat=n=3:v=0:a=1[aout]
" -c:v copy -map 0:v -map [aout] output_video.mp4

Adding 3+ audio clips

For three audio clips, follow the same pattern: add another -i for the third audio, extend the concat input list, and set n=4 (silent + audio1 + audio2 + audio3):

ffmpeg -i input_video.mp4 -i audio1.mp3 -i audio2.mp3 -i audio3.mp3 -filter_complex "
  aevalsrc=0:d=30[s1];
  [s1][1:a][2:a][3:a]concat=n=4:v=0:a=1[aout]
" -c:v copy -map 0:v -map [aout] output_video.mp4

Bonus: Mixing silent tracks between audio clips

If you want to add silence between audio clips (not just at the start), generate multiple silent tracks and include them in the concat chain. For example: audio1 → 10s silence → audio2 → 5s silence → audio3

ffmpeg -i input_video.mp4 -i audio1.mp3 -i audio2.mp3 -i audio3.mp3 -filter_complex "
  # Generate two different silent tracks
  aevalsrc=0:d=10[s1];
  aevalsrc=0:d=5[s2];
  # Concatenate all segments in order
  [1:a][s1][2:a][s2][3:a]concat=n=5:v=0:a=1[aout]
" -c:v copy -map 0:v -map [aout] output_video.mp4

Critical Notes to Avoid Errors

  • Matching audio specs: All audio segments (silent tracks included) must have the same sample rate, channel count, and format. If they don't, add the aformat filter to standardize them first. For example:
    # Standardize audio1 to stereo, 44.1kHz, FLTP format
    [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo[a1];
    # Do the same for audio2
    [2:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo[a2];
    # Then concatenate [s1][a1][a2]...
    
  • Update n in concat: The n value must always equal the number of segments you're joining. If you have 5 segments, set n=5—this is a common mistake that causes failures.

内容的提问来源于stack exchange,提问作者呂裕翔

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:27:12