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.
Basic FFmpeg M3U8 to MP4 Command
The simplest FFmpeg command to convert an M3U8 stream to MP4:
ffmpeg -i "https://example.com/stream.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4
This downloads the stream and copies the video and audio streams directly into an MP4 container without re-encoding. It's fast (download speed limited only by your connection) and preserves original quality.
Understanding the Flags
-i— Input file (the M3U8 URL)-c copy— Copy all streams without re-encoding (stream copy mode)-c:v libx264— Re-encode video using H.264 codec-c:a aac— Re-encode audio using AAC codec-bsf:a aac_adtstoasc— Bitstream filter for AAC audio (needed for MP4 compatibility)-crf 23— Quality level (lower = better, 18-28 typical range)
Re-encoding for Better Compatibility
Some streams use codecs not natively supported in MP4. In that case, re-encode:
ffmpeg -i "https://example.com/stream.m3u8" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k output.mp4
Selecting a Specific Quality Level
For multi-bitrate streams, select a specific variant:
ffmpeg -i "https://example.com/master.m3u8" -map 0:v:0 -map 0:a:0 -c copy output.mp4
The -map 0:v:0 selects the first video stream (usually the highest quality). Change the index to select different variants.
Troubleshooting Common Issues
- "Protocol not found" — Add
-protocol_whitelist file,http,https,tcp,tls,crypto - "Invalid data found" — Try adding
-allowed_extensions ALLbefore -i - "Operation not permitted" — Check if the stream is encrypted (need decryption key)
- No audio — Some streams have separate audio playlists. Use
-map 0:ato include audio
Related Articles
Download M3U8 Streams Using FFmpeg
Learn how to download M3U8/HLS streams with FFmpeg. Commands for saving streams, selecting quality, and handling live streams.
FFmpeg M3U8 Commands You Need to Know
Essential FFmpeg commands for working with M3U8/HLS streams. Quick reference for downloading, converting, and analyzing streams.
Using FFmpeg to Convert M3U8 to MP4 (Step by Step)
Complete FFmpeg guide for converting M3U8/HLS streams to MP4. Covers all common scenarios from simple copy to advanced re-encoding.