M3U8 to MP4: What an M3U8 File Is and How to Convert It
M3U8 to MP4: The Short Answer
An .m3u8 file is a text playlist, not a video, so converting M3U8 to MP4 means fetching every segment the playlist points to and joining them into one file. FFmpeg does that in one command: ffmpeg -i playlist.m3u8 -c copy output.mp4. It copies the video and audio without re-encoding, so it finishes in seconds and loses no quality.
Below: what's in an M3U8 file, how HLS streaming works, and the cases where that one-liner fails.
Before you start: only save streams you own or have permission to download, such as your own webinar recordings, footage on a platform you administer, or open-licensed content. DRM-protected streams (FairPlay, Widevine, PlayReady) can't and shouldn't be converted, and this guide doesn't cover getting around that.
What Is an M3U8 File?
An M3U8 file is a playlist written in plain UTF-8 text. The name comes from M3U, an older audio playlist format, with "8" for UTF-8. Apple adopted it for HTTP Live Streaming, documented in RFC 8216.
Open one in TextEdit or run cat playlist.m3u8 and you'll see something like this (a playlist we generated with FFmpeg for testing):
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:4.000000,
seg_000.ts
#EXTINF:4.000000,
seg_001.ts
#EXTINF:4.000000,
seg_002.ts
#EXT-X-ENDLIST
Every line starting with #EXT is a tag. Every other line is the address of a media segment. That's the whole file: a few hundred bytes pointing at video that lives somewhere else. That's why renaming it to .mp4 produces a broken file, and why a saved M3U8 often won't play on its own.
What Is HLS and How Does HLS Streaming Work?
HLS (HTTP Live Streaming) is Apple's adaptive streaming protocol, and one of the most widely used ways to deliver video on the web, in apps and on smart TVs. Instead of one big file, the video is cut into short segments (Apple's authoring guidelines recommend about 6 seconds each) and served over ordinary HTTP. The player downloads segments one after another and can switch quality between them as your connection changes.
HLS uses two kinds of playlist:
| Playlist type | What it lists | How to recognise it |
|---|---|---|
| Master (multivariant) playlist | Other playlists, one per quality level, plus alternate audio and subtitle tracks | #EXT-X-STREAM-INF lines with BANDWIDTH and RESOLUTION |
| Media playlist | The actual segments for one quality level or one track | #EXTINF lines followed by segment names |
Here's a master playlist from our test, with a 720p and a 360p variant:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=3445288,RESOLUTION=1280x720,CODECS="avc1.64001f,mp4a.40.2"
720p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1003920,RESOLUTION=640x360,CODECS="avc1.64001e,mp4a.40.2"
360p.m3u8
Segment formats: .ts or .m4s
The segments come in one of two containers:
- MPEG-2 Transport Stream (
.ts): the original HLS format, still very common. Each segment is a small, self-contained TS file. Our TS to MP4 guide covers the format and how to join loose.tsfiles. - Fragmented MP4 (
.m4s, sometimes.mp4or.cmfv): used by newer streams, especially HEVC ones. These playlists have an#EXT-X-MAPtag pointing to an initialization file (ofteninit.mp4) that the segments depend on.
Either way, the video inside is usually H.264 or HEVC and the audio is usually AAC, which is exactly what MP4 expects. That's why -c copy works so often.
Other tags worth knowing
#EXT-X-ENDLISTmeans the stream is complete (video on demand). Without it, the playlist is live and keeps growing.#EXT-X-KEYmeans the segments are encrypted.METHOD=AES-128is whole-segment encryption with a key file the player downloads.METHOD=SAMPLE-AEStogether with aKEYFORMATsuch ascom.apple.streamingkeydelivery(FairPlay) indicates DRM.#EXT-X-MEDIAdeclares alternate audio or subtitle tracks that live in their own playlists.
How to Convert M3U8 to MP4 with FFmpeg
FFmpeg has a full HLS reader built in, so it's the most reliable way to convert M3U8 to MP4 on a Mac, Windows or Linux. The npm and Python "m3u8-to-mp4" packages in search results need FFmpeg installed anyway. On a Mac, install it with Homebrew:
brew install ffmpeg
We tested every command below with FFmpeg 9.0 on macOS, using HLS streams we generated ourselves (.ts and fMP4 segments, a two-variant master playlist, separate audio, AES-128) and served from a local web server.
The basic M3U8 to MP4 FFmpeg command
ffmpeg -i https://example.com/video/index.m3u8 -c copy output.mp4
Or, for a playlist and segments saved on your disk:
ffmpeg -i index.m3u8 -c copy output.mp4
-c copy rewraps the existing H.264/HEVC and AAC streams into MP4 without decoding them. Our 20-second test converted in under a second, and the decoded frames matched the original's MD5 hash exactly, so there's no quality change. Add -movflags +faststart if the MP4 is going on a website.
Do you still need -bsf:a aac_adtstoasc?
Older guides insist on this:
ffmpeg -i index.m3u8 -c copy -bsf:a aac_adtstoasc output.mp4
AAC in .ts segments uses ADTS headers, which MP4 doesn't, so old FFmpeg versions needed this filter. Current builds add it themselves: with -v verbose, FFmpeg 9 logged Automatically inserted bitstream filter 'aac_adtstoasc', and the audio decoded cleanly. The flag is harmless, so keep it for old builds or existing scripts, but a recent FFmpeg doesn't need it.
Local playlists: keep the folder structure
Segment lines are usually relative paths like seg_000.ts, resolved from the playlist's own folder, so this works from anywhere:
ffmpeg -i ~/Downloads/lecture/index.m3u8 -c copy lecture.mp4
But if you copy only the .m3u8 to another folder, FFmpeg fails with Error when loading first segment followed by Invalid data found when processing input. Keep the playlist with its segments, and for fMP4 streams keep init.mp4 too.
Local playlist with online segments: protocol_whitelist
If the playlist file is on your disk but its segment lines are full https:// URLs, FFmpeg refuses by default. In our test it printed Protocol 'http' not on whitelist 'file,crypto,data'!. Allow network protocols explicitly, before -i:
ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i index.m3u8 -c copy output.mp4
You don't need this when the playlist itself is a URL.
Picking a variant from a master playlist
When you give FFmpeg a master playlist, it chooses streams the same way it does for any input: the highest-resolution video and one audio track. In our test that meant the 720p variant. To see every variant first:
ffprobe -hide_banner master.m3u8
The output groups streams into Programs, one per variant, each with a variant_bitrate:
Program 0
variant_bitrate : 3445288
Stream #0:0: Video: h264 (High), 1280x720
Stream #0:1: Audio: aac (LC), 48000 Hz
Program 1
variant_bitrate : 1003920
Stream #0:2: Video: h264 (High), 640x360
Stream #0:3: Audio: aac (LC), 48000 Hz
Then map the program you want with -map 0:p:N:
ffmpeg -i master.m3u8 -map 0:p:1 -c copy output-360p.mp4
Our test server's log showed FFmpeg downloading only the chosen variant's segments (plus one probe segment of the other), so a smaller variant also saves bandwidth. You can also pass a media playlist such as 360p.m3u8 directly, but read the next section first.
Separate audio tracks
Many streams keep audio out of the video segments, declared in an #EXT-X-MEDIA:TYPE=AUDIO line with its own playlist. In this layout:
- Converting the master playlist works: FFmpeg attaches the audio to each program, and
-map 0:p:Ngave us video plus audio. - Converting a video media playlist directly gives you an MP4 with no sound, because that playlist contains only video.
To use the media playlists, pass both:
ffmpeg -i 360p.m3u8 -i audio.m3u8 -map 0:v -map 1:a -c copy output.mp4
AES-128 encrypted streams (when you have the key)
An #EXT-X-KEY:METHOD=AES-128,URI="..." line means each segment is encrypted with a 16-byte key that the player downloads from the URI. If you're entitled to the stream and the key is reachable, FFmpeg decrypts it automatically; our keyed test stream converted over HTTP with the plain command.
One catch for local copies: if the key is a local file such as enc.key, FFmpeg 9 blocks it with Filename extension of 'enc.key' is not a common multimedia extension, blocked for security reasons. Allow it explicitly:
ffmpeg -allowed_extensions ALL -i index.m3u8 -c copy output.mp4
This only helps with plain AES-128 where you legitimately have the key. It does nothing for FairPlay, Widevine or PlayReady, and it shouldn't: DRM streams are licensed for playback, not saving. Use the service's own offline feature or ask the rights holder for a file.
Live streams
A playlist without #EXT-X-ENDLIST is live. FFmpeg records from near the live edge until you press q, or for a fixed length with -t:
ffmpeg -i https://example.com/live/index.m3u8 -t 01:00:00 -c copy recording.mp4
For your own broadcasts, recording locally at the source gives better quality; see our OBS recording settings guide.
When to re-encode instead of copying
-c copy only works when the codecs are allowed in MP4 and will play where you need them. Re-encode when:
- The video is HEVC and needs to play on older devices, or you want a smaller file.
- The stream mixes resolutions or codecs between segments (some ad-inserted streams do).
- The copied file shows glitches at segment boundaries.
A widely compatible re-encode:
ffmpeg -i index.m3u8 -c:v libx264 -crf 20 -preset medium -c:a aac -b:a 160k -movflags +faststart output.mp4
On a Mac, -c:v h264_videotoolbox -b:v 5M uses the hardware encoder and is much faster. For HEVC streams you just want to rewrap, add -tag:v hvc1: FFmpeg's default tag for HEVC copied from .ts is hev1, which QuickTime and other Apple players generally won't play.
ffmpeg -i index.m3u8 -c copy -tag:v hvc1 output.mp4
Our guides to compressing video with FFmpeg and HEVC vs H.264 cover CRF values and codec trade-offs. MP4 is the right end point for almost any saved video, as our best video format guide explains; for files rather than streams, see MKV to MP4, WebM to MP4 and converting video to MP4.
Subtitles: FFmpeg's default mapping leaves HLS WebVTT subtitles out of the MP4, and -map 0 -c copy fails with Could not find tag for codec webvtt. Converting with -c:s mov_text worked in our test but dropped a cue and shifted timings, so check subtitles carefully if they matter.
How to Convert M3U8 to MP4 with VLC
VLC plays HLS natively and has a converter built in, which makes it the easiest free option without the Terminal. The steps below are for VLC 3 on a Mac; Windows uses Media > Convert / Save for the same dialog.
- Open VLC and choose File > Convert / Stream.
- Click Open media. For a local playlist, choose the
.m3u8file (its segments must be next to it). For an online stream, go to the Network tab and paste the playlist URL. - Under Choose Profile, select Video - H.264 + MP3 (MP4).
- Click Customize. To rewrap without re-encoding, tick Keep original video track on the Video codec tab and Keep original audio track on the Audio codec tab. Leave them unticked if you need a re-encode.
- Click Save as File, choose a name ending in
.mp4, and click Save.
VLC still has to download every segment, so a long stream takes a while. It also has no equivalent of -map 0:p:N, so pass the media playlist URL if you want a specific quality. If you prefer the command line, VLC can remux too. This worked in our test with VLC 3.0:
/Applications/VLC.app/Contents/MacOS/VLC -I dummy "https://example.com/video/index.m3u8" \
--sout '#std{access=file,mux=mp4,dst=output.mp4}' vlc://quit
For more on VLC's profile editor, see our VLC convert to MP4 guide.
What About Browser Extensions and Online Converters?
We don't recommend "video downloader" extensions. An extension that can read every page you visit is a common route for adware and data harvesting, and many exist mainly to grab streams users have no right to save. Online converters can't reach a playlist on your disk, and for a URL they do what FFmpeg does, on someone else's server. FFmpeg and VLC are free and run locally.
Troubleshooting M3U8 to MP4 Conversions
| Error or symptom | Likely cause | Fix |
|---|---|---|
Server returned 403 Forbidden | Signed URL has expired, or the server only serves your authenticated session | Get a fresh playlist URL from the source you're entitled to; for your own platform, check its token settings or use its download/export feature |
Error when loading first segment | Segments aren't where the playlist says (moved playlist, missing folder) | Keep the playlist with its segments; for URLs, check the first segment loads |
Protocol 'http' not on whitelist | Local playlist with online segments | Add -protocol_whitelist file,http,https,tcp,tls,crypto before -i |
blocked for security reasons on a .key file | Local AES-128 key file | Add -allowed_extensions ALL before -i |
| MP4 has no audio | You converted a video-only media playlist | Use the master playlist, or add the audio playlist as a second input |
| MP4 has audio only | You picked an audio-only variant (some master playlists list one) | Check ffprobe output and map a program that contains video |
| Video jumps or has a gap of a few seconds | One or more segments failed to download | Re-run; check the log for failed too many times, skipping |
| HEVC MP4 won't open in QuickTime | hev1 tag | Remux with -tag:v hvc1 |
Expiring tokens and 403 errors
Most commercial streams sign their URLs with a token that expires after minutes or hours and is tied to a logged-in session, so a URL copied yesterday returns 403 by design. If the stream is yours on a video platform, its own MP4 download or export is a better route than reassembling HLS. If your own server requires an authorization header, FFmpeg can send it with -headers before -i, for example -headers 'Authorization: Bearer YOUR_TOKEN'.
Missing segments
This one is easy to miss. When we deleted one segment from a test stream, FFmpeg logged Segment 2 of playlist 0 failed too many times, skipping and still produced a complete-looking 20-second MP4, with a four-second gap in the video where that segment should be. If a segment fails partway through a long download, you won't know unless you read the log. Add -xerror to make FFmpeg stop with an error instead:
ffmpeg -i index.m3u8 -c copy -xerror output.mp4
Audio-only variants
Some master playlists include an audio-only variant (CODECS="mp4a.40.2" and no RESOLUTION). If that's what you actually want, for a podcast or lecture, save it as M4A:
ffmpeg -i audio.m3u8 -c copy output.m4a
Our AAC codec explainer covers what's in that file.
Where Compresto Fits
Compresto is a Mac app for compressing video, images, GIFs and PDFs locally. It doesn't open .m3u8 playlists or download streams, so the M3U8 to MP4 step itself belongs to FFmpeg or VLC.
Once you have the MP4, though, it's often bigger than it needs to be, because the top HLS variant is encoded at a high fixed bitrate for streaming. Drop the MP4 (or a .ts file) into Compresto and it re-encodes with hardware-accelerated H.264 or HEVC, can downscale, trim, and hit a target file size for email or upload limits, in batches if you've saved a series of lectures. See compressing MP4 files, video transcoders, and FFmpeg vs an easier alternative for the settings.
Frequently Asked Questions
What is an M3U8 file?
A UTF-8 text playlist used by HLS. It lists the addresses of short video segments (.ts or .m4s), or, in a master playlist, the playlists for each quality level. It contains no video itself.
How do I convert M3U8 to MP4?
Install FFmpeg and run ffmpeg -i playlist.m3u8 -c copy output.mp4. It fetches every segment and joins them into one MP4 without re-encoding. The playlist can be a local file or a URL, as long as its segments are reachable.
Do I still need -bsf:a aac_adtstoasc?
Usually not. Current FFmpeg inserts aac_adtstoasc automatically when copying AAC from .ts into MP4; FFmpeg 9 logged this in our test. Adding it manually is harmless.
Can VLC convert M3U8 to MP4?
Yes. Use File > Convert / Stream, open the playlist or paste its URL in the Network tab, choose the Video - H.264 + MP3 (MP4) profile, and save as a file. Tick Keep original video and audio track in the profile to rewrap instead of re-encoding.
Why does my M3U8 to MP4 conversion have no sound?
The stream probably keeps audio in a separate playlist. Convert the master playlist instead, or pass both: ffmpeg -i video.m3u8 -i audio.m3u8 -map 0:v -map 1:a -c copy output.mp4.
Can I convert a DRM-protected M3U8 stream?
No. FairPlay, Widevine and PlayReady streams are licensed for playback only, and bypassing that protection breaks the service's terms and often the law. Use the service's offline feature or ask the rights holder for a file.
The Short Version
An M3U8 is a playlist that points to short .ts or .m4s segments, not a video. To convert M3U8 to MP4, run ffmpeg -i playlist.m3u8 -c copy output.mp4; use -map 0:p:N to pick a variant, convert the master playlist when audio is separate, and check the log for skipped segments. VLC does the same with a graphical interface. Only save streams you own or have permission to keep.