FFmpeg Concat Demuxer with Different Subtitles
This article explains how to configure and use the FFmpeg
concat demuxer when joining video files that contain
different, mismatched, or missing subtitle tracks. Because the
concat demuxer requires identical stream configurations
across all input files, attempting to merge files with differing
subtitle layouts will normally result in errors or dropped tracks.
Below, you will find the precise steps and workarounds to successfully
merge these files while preserving your subtitles.
The Core Problem with Concat and Subtitles
The FFmpeg concat demuxer is a physical-level demuxer.
It reads a list of files and joins them consecutively. For this to work
seamlessly, all input files must have the exact same stream
layout. This means: * The same number of streams (e.g., one
video, one audio, one subtitle). * The same codecs in the same order. *
The same time bases.
If File A has an English subtitle track (SRT) and File B has no
subtitle track, or if File B has a subtitle track in a different codec
(e.g., ASS), the concat demuxer will fail or output a file
with corrupted/missing subtitles.
Solution 1: Standardize Streams Prior to Concatenation (Recommended)
To use the fast concat demuxer, you must first
preprocess your files so their stream structures match perfectly.
Step 1: Add a Dummy Subtitle Track to Files Lacking One
If some of your video files lack subtitles entirely, you must add an empty subtitle track to them.
First, create an empty subtitle file named
empty.srt:
1
00:00:00,000 --> 00:00:00,100
Then, remux the subtitle-less video (e.g., input2.mp4)
with this empty track:
ffmpeg -i input2.mp4 -i empty.srt -c copy -map 0 -map 1 output2.mp4Step 2: Convert Subtitles to a Common Codec
If your files have subtitles but in different formats (e.g., one is ASS, the other is SRT), transcode them to a unified format like SubRip (SRT) or WebVTT:
ffmpeg -i input1.mp4 -c:v copy -c:a copy -c:s srt output1.mp4Step 3: Run the Concat Demuxer
Once all files have the exact same stream mapping (Video, Audio,
Subtitle), create your inputs.txt file:
file 'output1.mp4'
file 'output2.mp4'
Run the concat command, making sure to use the -map flag
to include the subtitle stream in the output:
ffmpeg -f concat -safe 0 -i inputs.txt -map 0 -c copy final_output.mp4Solution 2: Extract, Concat, and Re-Merge (The Safest Workaround)
If standardizing the streams inside the video containers is too difficult, the most reliable method is to extract the subtitles, concatenate the videos separately, concatenate the subtitles separately, and then merge them back together.
Step 1: Extract the Subtitles
Extract the subtitle tracks from each of your input files:
ffmpeg -i input1.mp4 -map 0:s:0 sub1.srt
ffmpeg -i input2.mp4 -map 0:s:0 sub2.srtStep 2: Concatenate the Videos (Without Subtitles)
Concatenate the video and audio streams using the concat
demuxer. Create an inputs.txt containing your original
video files, then run:
ffmpeg -f concat -safe 0 -i inputs.txt -map 0:v -map 0:a -c copy video_only.mp4Step 3: Merge the Subtitle Files
You can merge the .srt files using a subtitle editor, or
manually adjust the timestamps of sub2.srt to start exactly
where input1.mp4 ends, then paste them into a single file
named merged.srt.
Step 4: Remux Video and Merged Subtitles
Finally, combine the concatenated video file and the merged subtitle file back into a single container:
ffmpeg -i video_only.mp4 -i merged.srt -c copy -map 0 -map 1 final_video.mp4