← Blog.backToBlog

Convert M3U8 to MP4 with FFmpeg: Complete Guide

8 min read

Basic FFmpeg M3U8 to MP4 Command

The standard lossless command:

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

FFmpeg downloads every segment listed in the playlist, concatenates them, and writes an MP4 without re-encoding. Speed is limited mainly by your network; quality matches the source. Prefer a browser tool instead? Use our free M3U8 to MP4 converter (ffmpeg.wasm, no install).

Understanding the Flags

FlagMeaning
-iInput (M3U8 URL or file)
-c copyStream copy — no re-encode
-c:v libx264Re-encode video as H.264
-c:a aacRe-encode audio as AAC
-bsf:a aac_adtstoascFix AAC for MP4 from TS
-crf 23Quality when re-encoding (lower = better)

Re-encoding for Compatibility

If stream copy fails (codec not MP4-friendly), re-encode:

ffmpeg -i "https://example.com/stream.m3u8" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k output.mp4

Slower and CPU-heavy, but maximizes playback compatibility. Quality tips: high-quality M3U8 to MP4.

Selecting a Quality Level

For multi-bitrate masters, inspect then map streams:

ffmpeg -i "https://example.com/master.m3u8"
ffmpeg -i "https://example.com/master.m3u8" -map 0:v:0 -map 0:a:0 -c copy output.mp4

-map 0:v:0 usually picks the highest video variant; increase the index for lower tiers.

Headers and Authentication

Some CDNs require a User-Agent or Referer:

ffmpeg -user_agent "Mozilla/5.0" -headers "Referer: https://example.com" -i "URL" -c copy output.mp4

This fixes many 403 errors without changing the stream itself.

Troubleshooting Common Issues

  • Protocol not found — add -protocol_whitelist file,http,https,tcp,tls,crypto.
  • Invalid data — try -allowed_extensions ALL before -i.
  • Operation not permitted / key errors — stream may be encrypted; key must be reachable.
  • No audio — map audio explicitly with -map 0:a.

More commands: FFmpeg HLS command reference.

Install and Sanity-Check FFmpeg

Install a recent static build or package-manager FFmpeg (ffmpeg -version). Confirm HTTPS and protocol support in your build if you pull remote playlists. On corporate laptops, verify the binary is approved — random “FFmpeg GUI” installers are a common malware vector.

Sanity check with a short public HLS demo before touching production URLs. If local files play but remote HTTPS fails, look at TLS/proxy interception, not “HLS is broken.”

Core Commands That Cover 90% of Jobs

# Remux / copy when codecs are already MP4-friendly
ffmpeg -i "https://example.com/master.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4

# Explicit media playlist (skip master confusion)
ffmpeg -i "https://example.com/720p.m3u8" -c copy out.mp4

# Re-encode only when required
ffmpeg -i "input.m3u8" -c:v libx264 -c:a aac -movflags +faststart out.mp4

Prefer -c copy for speed and quality. Add headers (-headers "Referer: … ") when origins require them. For live, set -t duration so the process ends.

Browser Tools vs FFmpeg

NeedBrowser converterFFmpeg
One-off authorized VODFastOptional
Batch / CIPoorBest
Custom headers / cookiesLimitedFlexible
No install policyWinsBlocked
Huge multi-hour jobsRAM riskStable

Start in the online converter when possible; escalate to FFmpeg for automation. Also see shorter FFmpeg guide and download with FFmpeg.

Bottom Line

FFmpeg remains the complete M3U8→MP4 toolkit: remux first, re-encode only when forced, script everything that repeats, and respect DRM/rights boundaries. Pair it with a browser preflight player so you never automate a dead URL.

Frequently Asked Questions

What is the best FFmpeg command for M3U8 to MP4?
ffmpeg -i "url" -c copy -bsf:a aac_adtstoasc out.mp4 for lossless copy.

Why use aac_adtstoasc?
It fixes AAC bitstream layout when remuxing from TS into MP4.

Can I convert without installing FFmpeg?
Yes — use our browser converter.

Does -c copy lose quality?
No — it remuxes without re-encoding.