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_adtstoascwhen outputting to MP4 with AAC audio - Our online downloader handles all this automatically
Related Articles
Convert M3U8 to MP4 with FFmpeg: Complete Guide
Step-by-step guide to converting M3U8 streams to MP4 using FFmpeg. Fast, lossless, and fully customizable conversion commands.
FFmpeg M3U8 Commands You Need to Know
Essential FFmpeg commands for working with M3U8/HLS streams. Quick reference for downloading, converting, and analyzing streams.
Convert M3U8 to MP4 Without Uploading Files to Any Server
Privacy-focused M3U8 to MP4 conversion that happens entirely in your browser. No uploads, no servers — your files stay on your computer.