Understanding the Stream Duplication Issue
A common mistake when working with Transport Stream (.TS) files is assuming that all inputs are empty canvases. Many recorded .TS files already contain embedded subtitle streams, such as Closed Captions or PGS subtitles. When users run standard FFmpeg commands that map all streams from the input file, these existing subtitles are copied into the output alongside your newly added SRT file. This results in duplicate subtitle tracks, which can cause playback issues in media players like VLC or Kodi, where users might see multiple identical or conflicting subtitle options. To avoid this, you must understand how FFmpeg handles stream selection. By default, FFmpeg attempts to copy every stream it finds in the input unless instructed otherwise. Therefore, the solution lies not just in adding the subtitle, but in carefully curating which streams are carried over from the original .TS file. You need to separate the video and audio streams from the potential existing subtitle streams, ensuring only the latter are excluded or overwritten by your new external file.Preparing Your Input Files
Before running the conversion, ensure your SRT file is properly formatted. SubRip Text files should have consistent timing formats and valid line breaks. If your SRT file contains special characters or non-Latin scripts, you may encounter rendering issues depending on the player. For general compatibility, UTF-8 encoding is recommended. Additionally, verify that the timestamp alignment in your SRT file matches the duration of the video content. Mismatches here will not be fixed by FFmpeg during muxing; they will simply result in subtitles appearing at the wrong times or not at all. You also need to locate the original .TS file and the .SRT file on your local system. Note their full paths, as FFmpeg commands require precise file locations. It is advisable to work with copies of your original files if you are unsure about the process, although FFmpeg’s remuxing operation is generally non-destructive to the original source data.The Correct FFmpeg Command Structure
The most robust way to handle this task is to explicitly define the inputs and outputs for each stream type. This method gives you granular control over what gets included in the final file. Instead of using-map 0, which maps all streams from the first input, you should use specific map indices or global stream selection flags.
Here is the recommended command structure:
ffmpeg -i input.ts -i subtitle.srt -c:v copy -c:a copy -c:s mov_text -map 0:v:0 -map 0:a:0 -map 1:s:0 output.ts
Let’s break down why this works. The -i input.ts specifies the main video file, and -i subtitle.srt adds the subtitle file as a second input. The codec flags -c:v copy and -c:a copy tell FFmpeg to re-encode neither the video nor the audio, making the process extremely fast as it only muxes (combines) the streams. The critical part is the -map section. -map 0:v:0 selects only the first video stream from the first input. -map 0:a:0 selects the first audio stream. Finally, -map 1:s:0 selects the subtitle stream from the second input (the SRT file). By omitting any map for subtitles from the first input, you effectively discard any existing subtitles in the .TS file.
Note on Codec Selection: While some guides suggest using -c:s mov_text, this is primarily designed for MP4 containers. For TS files, especially those intended for broadcast or standard players, -c:s srt or simply letting FFmpeg auto-detect the subtitle codec based on the input format is often safer. However, since we are mapping an external SRT file, FFmpeg will typically handle the internal representation correctly. If you face compatibility issues with specific players, consider using -c:s dvb_subtitle or -c:s pgs if you convert the SRT first, but for direct SRT addition, the explicit mapping is the key fix.
Verifying the Output
After running the command, always verify the output file. Use a tool likeffprobe to inspect the streams in the new output.ts. Run the following command:
ffprobe output.ts
Look for the stream tags. You should see one video stream, one or more audio streams, and exactly one subtitle stream derived from your SRT file. If you see additional subtitle streams labeled with IDs that do not match your SRT input, the mapping was incorrect, and you likely still have duplicates. Play the file in a reliable media player to ensure the subtitles appear synchronously and are selectable.
For users who need to retain existing subtitles while adding new ones, or manage complex multi-track scenarios, refer to How to Add Multiple Audio and Subtitle Tracks to Video. This guide expands on stream selection techniques for more intricate editing tasks.
If you are experiencing issues with Arabic text displaying as square boxes or burnt-in subtitle problems, check out Fix Arabic Words Showing Square Boxes and Burnt Subtitles with FFmpeg for specific encoding solutions related to script support.
Frequently Asked Questions
What happens if I don't specify -map?
If you omit the -map option, FFmpeg defaults to copying all streams from the input files. This means any existing subtitles in your .TS file will be duplicated alongside your new SRT file, leading to multiple subtitle tracks in the output.
Can I burn the subtitles directly into the video?
Yes, but this requires re-encoding the video stream, which takes significantly longer and reduces quality. To burn subtitles, you would use the -vf subtitles=subtitle.srt filter instead of mapping the subtitle as a separate stream.
Why does my player show no subtitles even after adding them?
This is often due to codec incompatibility. Some older players struggle with raw SRT streams in TS containers. Try converting the SRT to a different format like PGS or DVB subtitles before muxing, or ensure your player supports soft-coded SRT subtitles.
Is it safe to overwrite the original .TS file?
FFmpeg allows you to save the output to a new filename, which is safer. If you attempt to write back to the same filename, FFmpeg may fail because it cannot read the input file while simultaneously writing to it. Always use a distinct output name.
How do I remove all existing subtitles from a TS file?
You can achieve this by excluding subtitle maps entirely. Use -map 0:v -map 0:a without any -map commands for subtitles. This forces FFmpeg to copy only video and audio, discarding any embedded subtitle tracks from the source.