← Blog.backToBlog

Merging M3U8 TS Segments with FFmpeg

7 min read

Method 1: Direct Playlist Input

Let FFmpeg read the playlist and merge automatically:

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

Works for remote playlists and local .m3u8 files when segment paths resolve. This is usually the easiest path. Browser alternative: our downloader merges in-browser.

Method 2: Local Concat Demuxer

# files.txt
file 'seg-001.ts'
file 'seg-002.ts'
file 'seg-003.ts'

ffmpeg -f concat -safe 0 -i files.txt -c copy output.ts
ffmpeg -i output.ts -c copy -bsf:a aac_adtstoasc output.mp4

Best for many local segments already on disk.

Method 3: Concat Protocol

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

Handy for a few files; less flexible than the demuxer for large sets.

Important Notes

  • Segments should share codec and resolution.
  • Missing segments cause glitches or failure.
  • Prefer concat demuxer for large N.
  • Use -bsf:a aac_adtstoasc when remuxing AAC into MP4.

Segment theory: how HLS segment merging works.

When Merge Fails

Check order, missing files, and mixed codecs. Re-encoding can force compatibility: -c:v libx264 -c:a aac. Full convert guide: FFmpeg M3U8 to MP4.

Frequently Asked Questions

How do I merge TS files with FFmpeg?
Use concat demuxer with a file list, or feed the M3U8 playlist to FFmpeg.

Do I need to re-encode?
Usually no — -c copy is enough if codecs match.

Can the browser merge for me?
Yes — our online downloader does.

Why is audio broken in MP4?
Add -bsf:a aac_adtstoasc.