CGJU
CGJU
June 5, 2026 · 6 min read

What is TS Format

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.

Main Features of TS Format

  • Strong Fault Tolerance: Independent data packets, partial loss does not affect overall playback
  • Suitable for Streaming: Can play while downloading, supports live streaming
  • Multi-Track Support: Can simultaneously include multiple video, audio, and subtitle tracks
  • Fixed Packet Length: Each data packet is 188 bytes, facilitating synchronization and transmission

Method 1: Concat Demuxer (Recommended)

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.

Operation Steps

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

Parameter Description

  • -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-encoding

Method 2: Concat Protocol

Concat 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.

Command Example

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

Precautions

  • Only supports MPEG series formats (TS, PS, etc.), does not support MP4, MKV and other formats
  • File order must be correct, otherwise it will cause playback abnormalities
  • Cannot have special characters in filenames

Method 3: Concat Filter

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.

Command Example

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

Parameter Description

  • concat=n=3: Specify the number of files to merge as 3
  • v=1: Output 1 video stream
  • a=1: Output 1 audio stream
  • [outv][outa]: Label names for output streams

Method 4: Intermediate File Method

The 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.

Windows Command Line Method

copy /b segment1.ts + segment2.ts + segment3.ts combined.ts
ffmpeg -i combined.ts -c copy output.mp4

Linux/Mac Method

cat segment1.ts segment2.ts segment3.ts > combined.ts
ffmpeg -i combined.ts -c copy output.mp4

Comparison of Four Methods

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 ★★★

Applicable Scenario Recommendations

Scenarios Recommended for Concat Demuxer

  • All TS files have consistent encoding parameters
  • Need fast merging, don't want to wait for re-encoding
  • Large number of files, need batch processing
  • Want to output MP4, MKV and other formats

Scenarios Requiring Concat Filter

  • Each TS file has inconsistent encoding parameters
  • Need to perform other filter processing simultaneously
  • Special requirements for output quality
  • Audio-video synchronization issues after merging

Common Problems and Solutions

1. Audio-Video Out of Sync After Merging

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

2. Some Segments Cannot Play

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.

3. Filename Sorting Issues

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...).

Summary

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.

Related Recommendations

More great articles and useful tools

Need to Merge TS Files?

Use our free TS merging tool — upload segments and merge to MP4 with one click, no software download or installation required

Try It Now ➡