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

如何用FFmpeg拼接3个及以上视频?已有双视频拼接命令

Hey there! Glad you’ve got the two-video concat working already—scaling that up to three or more videos is totally straightforward, and I’ll walk you through two reliable methods that fit different scenarios.

Method 1: Extend Your Existing TS Intermediate File Workflow

Since you’re already comfortable converting MP4s to MPEG-TS first (a smart move that avoids codec mismatch headaches), you just need to add more intermediate TS files for each extra video you want to join:

  1. Convert every source MP4 to an MPEG-TS file (repeat this for all your videos):
    ffmpeg -i intro.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
    ffmpeg -i middle_video.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
    ffmpeg -i outro.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate3.ts
    # Add as many of these commands as you have videos!
    
  2. Concatenate all the TS files in the order you want:
    ffmpeg -i "concat:intermediate1.ts|intermediate2.ts|intermediate3.ts" -c copy -bsf:a aac_adtstoasc final_output.mp4
    
    MPEG-TS is a streaming-friendly format, so it plays nice with direct concatenation—no weird glitches from MP4’s fragmented structure. This method is super reliable if all your videos use matching codecs.

Method 2: Use a Text File List (Better for 3+ Videos)

If you’re dealing with a bunch of videos, typing every TS file into the concat string gets messy. Instead, use a text file to list your inputs cleanly:

  1. Create a text file (let’s name it video_list.txt) and add each video’s path on a new line, wrapped in single quotes (handy if your filenames have spaces):
    file 'intro.mp4'
    file 'middle_video.mp4'
    file 'outro.mp4'
    file 'bonus_clip.mp4'
    # Keep adding lines for every video you want to include
    
  2. Run FFmpeg with the concat demuxer to stitch them together:
    ffmpeg -f concat -safe 0 -i video_list.txt -c copy final_output.mp4
    
    • -f concat: Tells FFmpeg to use the concat demuxer (designed for this exact use case)
    • -safe 0: Lets you use absolute file paths if your videos aren’t in the same folder as the text file
    • -c copy: Copies the video/audio streams directly (fast!)—this only works if all your videos have matching codecs, resolution, and frame rate. If they don’t, remove -c copy and FFmpeg will re-encode everything to match (it’ll take longer, but the output will play smoothly).

Quick Pro Tips

  • Double-check that all your source videos use the same codec (H.264 for video, AAC for audio) if you want the fast -c copy method to work. If they don’t match, re-encoding is the way to go.
  • Once you’re done with Method 1, feel free to delete the intermediate .ts files to free up disk space—they’re just temporary.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:53:46