Skip to content
  1. Home
  2. Guides
  3. FFmpeg: M3U8 to MP4

FFmpeg: convert or download M3U8 to MP4

One command saves an HLS stream as MP4 without re-encoding. Here it is, with the options for picky servers and what the usual errors mean.

Updated 23 November 2026

The command

ffmpeg -i "https://example.com/video/index.m3u8" -c copy video.mp4
  • -i "…m3u8": the playlist to read. Keep the quotes, because links often contain & or ?.
  • -c copy: copy the streams as they are. No re-encoding, so it's as fast as your connection and the quality is untouched.
  • video.mp4: the output. FFmpeg picks the MP4 format from the extension.

Don't want a terminal? The online M3U8 to MP4 converter does the same in your browser, and the Video Stream Catcher extension finds the link for you as well.

Install FFmpeg

  • Windows: winget install Gyan.FFmpeg, then open a new terminal.
  • macOS: brew install ffmpeg (with Homebrew).
  • Ubuntu / Debian: sudo apt install ffmpeg.

Check it works with ffmpeg -version.

Servers that answer 403: send the page's headers

Many video servers only answer requests that look like they come from their own player. Pass the page's address as the Referer, and a browser's user agent if needed. Options go before -i:

ffmpeg -user_agent "Mozilla/5.0" -headers "Referer: https://example.com/watch/123" -i "https://cdn.example.com/hls/index.m3u8" -c copy video.mp4

Links that carry a token (?token=… or ?Expires=…) stop working after a while: copy a fresh one and run the command straight away. If the site needs your login cookies too, the extension is simpler, since it downloads with the browser's own session.

Choose a quality

A master playlist lists the same video at several qualities. By default FFmpeg takes the highest resolution. To see what's there:

ffprobe -hide_banner "https://example.com/video/master.m3u8"

Each quality appears as a Program. Pick one by its number, here the third:

ffmpeg -i "https://example.com/video/master.m3u8" -map 0:p:2 -c copy video.mp4

Separate sound

Some streams keep the sound in its own playlist (an #EXT-X-MEDIA:TYPE=AUDIO line in the master). If your MP4 is silent, give FFmpeg both playlists and tell it which stream to take from each:

ffmpeg -i video.m3u8 -i audio.m3u8 -map 0:v -map 1:a -c copy video.mp4

A local .m3u8 file

If you saved the playlist and it lists web addresses, FFmpeg refuses them by default with Protocol 'https' not on whitelist. Allow them:

ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i playlist.m3u8 -c copy video.mp4

If you already have the .ts pieces on disk, merge the TS files instead, with FFmpeg's concat option or in the browser.

Common errors

ErrorWhat it meansFix
Server returned 403 ForbiddenThe link expired, or the server wants its page's headersFresh link; add -headers "Referer: …"
Server returned 404 Not FoundThe link is wrong or goneCopy it again from the page
Invalid data found when processing inputThe link isn't a playlist (often a login or error page)Check it in the M3U8 player
Protocol 'https' not on whitelistA local playlist points to web linksAdd -protocol_whitelist file,http,https,tcp,tls,crypto
Malformed AAC bitstream detectedOld FFmpeg versionAdd -bsf:a aac_adtstoasc, or update
Non-monotonous DTS warningsTimestamps jump between piecesUsually harmless; check the file plays
Never finishesIt's a live streamPress q to stop and keep what's recorded

Questions people ask

What does -c copy do?

It copies the video and sound into the MP4 as they are, instead of re-encoding them. That makes the conversion fast and lossless. Leave it out and FFmpeg re-encodes everything, which is slow and slightly worse.

Do I still need -bsf:a aac_adtstoasc?

Not with a recent FFmpeg: the MP4 muxer adds it by itself. On old versions (before 4.0), an error mentioning “Malformed AAC bitstream” means you need to add it.

How do I choose 720p instead of 1080p?

Run ffprobe on the master playlist to list the variants, then pick one with -map 0:p:N, or simply pass the URL of that quality's own playlist instead of the master.

Can FFmpeg save only the audio?

Yes. To keep the sound as it is: ffmpeg -i "LINK.m3u8" -vn -c:a copy audio.m4a. For an MP3, which re-encodes: ffmpeg -i "LINK.m3u8" -vn -c:a libmp3lame -q:a 2 audio.mp3.

Can FFmpeg download encrypted HLS?

If a playlist has an #EXT-X-KEY line, the stream is encrypted. This guide doesn't cover getting around encryption or DRM, and you shouldn't need to for videos you have the right to save.

Skip the copying and pasting

The free Video Stream Catcher extension spots the video on the page you're watching, M3U8 or not. Click its icon, pick a quality and press Download: you get one MP4 file. It also works where this page can't, because it runs on the video's own page.

Free · No sign-up · No ads · Chrome, Edge and Firefox

The Video Stream Catcher popup listing a video with its quality, size and a Download button