FFmpeg: Convert M3U8 to MP4 (Commands for Every Case)
Installing FFmpeg
FFmpeg is a free command-line tool that downloads and converts HLS in one step. Install it first: on macOS use brew install ffmpeg, on Windows download it from the official site (or winget install ffmpeg), and on Linux use your package manager (e.g. apt install ffmpeg). Then run the commands below in a terminal. Prefer no install? Skip to the browser method at the end.
Write down the successful path once it works — URL pattern, tool, and flags — so the next person on your team does not rediscover the same CORS or auth failure under deadline pressure.
Basic Conversion (Lossless Stream Copy)
This is the command you'll use most — it downloads the stream and remuxes it to MP4 without re-encoding:
ffmpeg -i "https://example.com/stream.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4
-c copy copies the streams as-is (fast and lossless); -bsf:a aac_adtstoasc fixes AAC audio when moving from a TS container to MP4. This works when the stream is already H.264/AAC — which most are.
Re-Encoding for Compatibility
If the stream uses a codec you need to change (e.g. HEVC → H.264), re-encode:
ffmpeg -i "https://example.com/stream.m3u8" -c:v libx264 -crf 23 -c:a aac output.mp4
-crf 23 sets quality (lower = better, 18–23 is a good range), and libx264 produces widely-compatible H.264. This is slower and CPU-heavy but maximizes compatibility.
Common FFmpeg Options Explained
| Option | What it does |
|---|---|
-c copy | Remux without re-encoding (lossless, fast) |
-c:v libx264 | Re-encode video to H.264 |
-crf 23 | Quality level for re-encoding |
-bsf:a aac_adtstoasc | Fix AAC audio for MP4 |
-ss / -t | Trim: start time / duration |
Passing Headers and Authentication
Some streams require a referer or user-agent header. Pass them with -headers or -user_agent:
ffmpeg -user_agent "Mozilla/5.0" -headers "Referer: https://example.com" -i "URL" -c copy output.mp4
This is the FFmpeg equivalent of the browser sending those headers, and it resolves many 403/forbidden errors.
Extracting Audio Only
To grab just the audio as an MP3:
ffmpeg -i "URL" -vn -c:a libmp3lame -q:a 2 audio.mp3
-vn drops the video, and libmp3lame encodes MP3. Useful for podcasts or music streams. See extract audio from M3U8.
Troubleshooting Common FFmpeg Errors
- 403 Forbidden — add
-headers/-user_agentas above. - Non-monotonous DTS / muxing warnings — usually harmless; the file still plays.
- Invalid data / demuxer errors — the URL may be expired; get a fresh one.
- Audio out of sync — try re-encoding instead of
-c copy.
No FFmpeg? Use the Browser Converter
If you'd rather not install FFmpeg, our M3U8 to MP4 converter runs FFmpeg (compiled to WebAssembly) right in your browser — same engine, no terminal, no install, and nothing uploaded.
Copy-Paste Recipes for Real Jobs
Use these as starting points on streams you are allowed to process:
Remux VOD to MP4:ffmpeg -i "https://example.com/master.m3u8" -c copy -bsf:a aac_adtstoasc -movflags +faststart out.mp4
Force a specific video variant (when the master confuses selection): open the media playlist URL for that bitrate directly instead of the master.
With Referer header:ffmpeg -headers "Referer: https://origin.example/
" -i "URL" -c copy out.mp4
Time range (seconds):ffmpeg -ss 00:01:00 -i "URL" -t 00:02:00 -c copy clip.mp4
Always quote URLs. On Windows PowerShell, prefer cmd or careful escaping. After remux, open the file once before deleting sources.
When to Prefer the Browser Instead
FFmpeg is not always the fastest path to a finished file for humans. If you are not comfortable with terminals, need a one-off archive of a short authorized VOD, and CORS allows browser fetch, the online converter or downloader is enough. Use FFmpeg when you need headers, automation, live recording windows, or when the browser fails.
Hybrid workflow many teams use: producers try the web tool first; ops documents a FFmpeg one-liner in the runbook for the same CDN. Related: methods overview, HLS to MP4 guide, no upload.
Quality, Legality, and Ops Hygiene
Default to -c copy so you do not invent quality loss. Re-encode only with intentional targets (device compatibility, size caps). Log the command, date, and source URL template next to the archive file. Do not script downloads of content you cannot legally retain.
If FFmpeg errors mention non-matching codecs or ADTS AAC, the bitstream filters and re-encode examples above usually clear them. If the playlist is 403, fix auth before tuning codecs — no flag repairs a forbidden URL.
FFmpeg vs Online Tools — Honest Split
FFmpeg wins on control, repeatability, and bypassing browser CORS. Online client-side tools win on accessibility: no install, visual progress, lower intimidation for non-engineers. Neither is universally “better.” Teams that publish free web tools and also document FFmpeg (like this site) give users an escalation path instead of a dead end when the tab fails.
If you only memorize one command, memorize remux with -c copy and +faststart. If you only bookmark one page, bookmark a free converter for emergencies when you are on a locked-down laptop. Combine both: converter for speed of human workflow, FFmpeg for production. More: best converters, converter vs downloader.
Frequently Asked Questions
What's the FFmpeg command to convert M3U8 to MP4?ffmpeg -i "url" -c copy output.mp4 for a lossless copy.
Why add -bsf:a aac_adtstoasc?
It fixes AAC audio when moving from TS to MP4.
How do I fix a 403 error?
Pass the required -headers or -user_agent.
Can I convert without installing FFmpeg?
Yes — use our browser converter (ffmpeg.wasm).