2026-07-034 min readmerge m3u8 ts files ffmpeg, ffmpeg merge ts segments, concat ts files ffmpeg

Merging M3U8 TS Segments with FFmpeg

Learn how to merge TS segments from M3U8 playlists into a single MP4 file using FFmpeg. Both online stream and local file methods.

Method 1: Direct Playlist Input

The simplest method — let FFmpeg handle everything:

ffmpeg -i "https://example.com/stream.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4

FFmpeg reads the playlist, downloads all segments, and concatenates them automatically. This works for both online streams and local M3U8 files.

Method 2: Local File Concatenation

If you've downloaded TS segments locally, merge them with the concat demuxer:

# Create a file list
echo "file 'seg-001.ts'" > files.txt
echo "file 'seg-002.ts'" >> files.txt
echo "file 'seg-003.ts'" >> files.txt

# Merge them
ffmpeg -f concat -safe 0 -i files.txt -c copy output.ts

# Convert to MP4 if needed
ffmpeg -i output.ts -c copy -bsf:a aac_adtstoasc output.mp4

Method 3: Concat Protocol

For a small number of segments:

ffmpeg -i "concat:seg-001.ts|seg-002.ts|seg-003.ts" -c copy merged.ts

This is less flexible than the concat demuxer but works for quick merges.

Important Notes on Merging

  • All segments must have the same codec and resolution
  • Gaps or missing segments will cause playback issues
  • The concat demuxer is preferred for large numbers of segments
  • Use -bsf:a aac_adtstoasc when outputting to MP4 with AAC audio
  • Our online downloader handles all this automatically

Related Articles