如何用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:
- 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! - Concatenate all the TS files in the order you want:
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.ffmpeg -i "concat:intermediate1.ts|intermediate2.ts|intermediate3.ts" -c copy -bsf:a aac_adtstoasc final_output.mp4
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:
- 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 - Run FFmpeg with the
concatdemuxer 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 copyand 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 copymethod 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
.tsfiles to free up disk space—they’re just temporary.
内容的提问来源于stack exchange,提问作者Siddharth
相关产品推荐
相关产品推荐

