What is .m3u8 Format? How to Open m3u8 Files?
Detailed analysis of M3U8 format structure, working principles, and common tags, introducing opening methods for desktop, mobile, and web.
Read More →Master the four core methods of TS file merging and choose the best solution for you
TS (Transport Stream) is a streaming media container format, originally defined by the MPEG-2 standard, widely used in digital television broadcasting, HLS streaming, and other scenarios. The characteristic of TS format is that video, audio, subtitle and other data are divided into fixed-size data packets (usually 188 bytes), each packet carries timestamps and error correction information, so even if some data is lost during transmission, playback can continue.
In HLS (HTTP Live Streaming), the entire video is split into multiple TS segment files, usually each segment is 2-10 seconds long. When we have downloaded all TS segments of an HLS video, we need to merge them into a complete video file for playback and saving.
Concat Demuxer is a file merging method provided by FFmpeg. It reads a list of files listed in a text file and connects them sequentially. The advantage of this method is that it does not require re-encoding, is very fast, and supports almost all container formats.
First create a text file (e.g., filelist.txt) with the following format:
file 'segment1.ts'
file 'segment2.ts'
file 'segment3.ts'
file 'segment4.ts'
Then execute the following FFmpeg command:
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4
-f concat: Specify to use concat demuxer-safe 0: Allow absolute paths (default only allows relative paths)-i filelist.txt: Specify the file list-c copy: Directly copy streams, no re-encodingConcat Protocol is another simple merging method. It directly uses the concat protocol in the input file to connect multiple files. This method only applies to certain specific container formats (such as MPEG-TS, MPEG-PS, etc.), and is very suitable for TS files.
ffmpeg -i "concat:segment1.ts|segment2.ts|segment3.ts" -c copy output.mp4
If there are many TS files, you can use the wildcard method (requires shell support):
ffmpeg -i "concat:$(ls *.ts | sort -V | tr '\n' '|' | sed 's/|$//')" -c copy output.mp4
Concat Filter is one of FFmpeg's filter functions. It can connect multiple video streams at the filter level. The characteristic of this method is that it will re-encode, so it is slower, but it has the best compatibility and can handle files with different encoding parameters.
ffmpeg -i segment1.ts -i segment2.ts -i segment3.ts \
-filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4
concat=n=3: Specify the number of files to merge as 3v=1: Output 1 video streama=1: Output 1 audio stream[outv][outa]: Label names for output streamsThe intermediate file method is a more traditional approach. First merge all TS files into one large TS file, then remux to MP4 or other formats. This method can directly use the copy command on Windows, which is very simple.
copy /b segment1.ts + segment2.ts + segment3.ts combined.ts
ffmpeg -i combined.ts -c copy output.mp4
cat segment1.ts segment2.ts segment3.ts > combined.ts
ffmpeg -i combined.ts -c copy output.mp4
| Method | Speed | Re-encoding | Applicable Formats | Recommendation |
|---|---|---|---|---|
| Concat Demuxer | Extremely Fast | No | Almost All Formats | ★★★★★ |
| Concat Protocol | Extremely Fast | No | MPEG Series | ★★★★ |
| Concat Filter | Slow | Yes | All Formats | ★★★ |
| Intermediate File Method | Fast | No | TS and Other Streaming Formats | ★★★ |
This is usually caused by discontinuous timestamps of TS segments. You can try using the Concat Filter method, or add the -fflags +genpts parameter to regenerate timestamps:
ffmpeg -f concat -safe 0 -i filelist.txt -fflags +genpts -c copy output.mp4
It may be that the segment files are corrupted. You can first use ffprobe to check the integrity of each file, or try using the Concat Filter method for re-encoding.
TS segments are usually named 1.ts, 2.ts, ..., 10.ts. Direct string sorting will cause 10.ts to come before 2.ts. It is recommended to use natural sorting (such as Linux's sort -V) or zero-padded naming (01.ts, 02.ts...).
TS file merging is a common requirement when processing HLS videos. FFmpeg provides multiple methods to meet the needs of different scenarios. For most cases, Concat Demuxer is the best choice — it's fast, has good compatibility, and is simple to use. If you encounter problems like inconsistent encoding parameters, then consider using the Concat Filter method.
If you don't want to manually execute commands, you can directly use our TS File Batch Merger. Upload TS segments and merge them into MP4 files with one click — convenient and fast.
More great articles and useful tools
Detailed analysis of M3U8 format structure, working principles, and common tags, introducing opening methods for desktop, mobile, and web.
Read More →Introduces common processing ideas for organizing M3U8 segmented videos into MP4 files, including online tools, player verification methods, and developer common solutions.
Read More →Selected most practical FFmpeg commands, covering format conversion, clipping, compression, subtitles, streaming, and other common scenarios.
Read More →Use our free TS merging tool — upload segments and merge to MP4 with one click, no software download or installation required
Try It Now ➡