FFmpeg Command Generator for HLS (M3U8) and DASH Streams
Build a working FFmpeg command for an .m3u8 or .mpd stream, with User-Agent, Referer and Cookie headers, stream copy and trimming. Tested on a strict server.
On this page
Fill in the stream address, add any headers the server needs, and copy a one-line FFmpeg command for Terminal. Every option the generator can produce was run against a test server that refuses any request without the right headers, and all of them worked. The command is built in your browser, so cookies you paste stay on this page.
FFmpeg command generator
Fill in what you have. The command updates as you type, and nothing leaves this page.
Request headers
Only needed when the server refuses requests that don't look like they come from its own player. Copy the values from the request in your browser's Network panel.
A cookie is your login. The command contains it, so don't paste it anywhere public.
Streams and range
Key takeaways:
- Headers go before
-i:-user_agent,-refererand-headersdescribe how to read the stream. - All 6 test commands passed against a server that returns 403 without the right Referer, cookie and custom header; it logged 78 requests and refused none.
-c copynever re-encodes, so a full 60-second 1080p stream came out at 60.03 s with the same H.264 and AAC.-map 0:p:1picks an HLS variant; left alone, FFmpeg takes the highest resolution.- Homebrew’s FFmpeg has no DASH demuxer, so
.mpdlinks fail with “Invalid data found when processing input”.
What the options do
Headers go before -i. In FFmpeg, an option applies to the next input or output named after it. -user_agent, -referer and -headers describe how to read the stream, so the generator always places them before -i. ffmpeg -h protocol=http lists all three: -headers “set custom HTTP headers”, -user_agent “override User-Agent header” and -referer “override referer header”.
Several headers need real line breaks. FFmpeg separates custom headers with a carriage return and line feed (CR LF). The generator writes them in zsh and bash’s $'…' quoting, where \r\n becomes those characters:
-headers $'Cookie: session=abc123\r\nX-Token: tok 1\r\n'
-c copy never re-encodes. It copies the video and audio into the new container as they are, so it’s fast and loses nothing. Choose re-encode audio to AAC only if a player rejects the original audio. That option keeps the video as it is (-c:v copy) and converts only the sound.
Picking an HLS variant. FFmpeg reads every variant of a master playlist as a separate “program”, numbered from 0 in playlist order. Left alone, it picks the highest-resolution video. In our test, it chose 1080p from a 1080p and 720p playlist. -map 0:p:1 keeps program 1 instead. The M3U8 inspector shows the order.
Start and length. -ss before -i starts reading at that time, and -t after it limits the output length. With stream copy, the cut starts on a keyframe, so expect a fraction of a second either way. Our 0:20-plus-15-seconds test came out at 15.09 seconds. Keyframe boundaries explains why.
Fast start (-movflags +faststart) moves the MP4’s index to the beginning, so the file can start playing before it has fully loaded. It only applies to MP4 and M4A.
How the commands were tested
I served a 60-second, 1080p and 720p HLS stream from a local server that returns 403 Forbidden unless every request has a specific Referer, a session cookie and a custom header. Then I ran six commands from the generator in zsh on macOS 26.6.2 with FFmpeg 8.1.2:
| Command | Result |
|---|---|
| Full stream, all headers, MP4 | 1080p H.264 + AAC, 60.03 s |
| Program 1, start 0:20, length 0:15 | 720p, 15.09 s |
| Re-encode audio to AAC 128k | 1080p, 60.03 s |
| Audio only, M4A | AAC, 60.03 s |
| TS container | 1080p H.264 + AAC, 60.02 s |
| MKV, no audio, file name with a space | 1080p video only, 60.00 s |
The server logged 78 requests across the six runs, every playlist and segment, and refused none. That confirms FFmpeg sends the headers on segment requests too, not just on the first playlist request. The User-Agent in the test contained an apostrophe, to check the quoting.
Errors you might see
| FFmpeg says | What it usually means | What to try |
|---|---|---|
Server returned 403 Forbidden (access denied) |
The server wants headers you didn’t send, or the link’s token expired | Add Referer, User-Agent or Cookie from the Network panel, or copy a fresh link |
Invalid data found when processing input on an .mpd |
Your FFmpeg has no DASH demuxer. FFmpeg needs libxml2 for DASH, and Homebrew’s build doesn’t include it | Check with ffmpeg -demuxers | grep -w dash; see the DASH guide |
Invalid data found when processing input on anything else |
The address is a web page, not the manifest | Find the .m3u8 or .mpd in the Network panel, or extract it from a HAR file |
command not found: ffmpeg |
FFmpeg isn’t installed | brew install ffmpeg |
The 403 message above is FFmpeg 8.1.2’s exact wording against our test server. The DASH case is covered in detail on the MPD to MP4 page.
FFmpeg or VidNeat?
VidNeat is our app, so weigh this accordingly. FFmpeg is free and can send any header. VidNeat reads the same HLS and DASH links without Terminal, lists the qualities the stream actually offers, and can fetch only the time range you mark. It can borrow your browser’s sign-in cookies, but it can’t send a custom Referer, User-Agent or other header. For a stream that needs those, the FFmpeg command is the tool, and the button under the command says so when it applies.
Limits, plainly: VidNeat can’t add custom headers, can’t save DRM-protected streams, and needs macOS 14 or later.
Common questions
Is it safe to paste my cookie here?
The command is built in your browser, and nothing is sent anywhere. The finished command does contain the cookie, so treat it like a password: don’t post it in a forum or a bug report.
Does -c copy work for every stream?
For HLS and DASH with H.264 or HEVC video and AAC audio into MP4, yes. It worked on every test above. If a codec isn’t allowed in the container you chose, FFmpeg stops with an error. Choose MKV, or re-encode the audio.
How do I add a User-Agent or Referer to FFmpeg?
Put -user_agent "…" and -referer "…" before -i. For anything else, such as a cookie, use -headers with each header ending in \r\n. The generator writes the quoting for you.
How do I convert an M3U8 to MP4 with FFmpeg?
ffmpeg -i "URL.m3u8" -c copy out.mp4. Add headers if the server returns 403. The M3U8 to MP4 guide covers finding the address.
Why does FFmpeg say 403 Forbidden?
The server wants headers you didn’t send, or the link’s token has expired. Copy the Referer, User-Agent and Cookie from the Network panel, or copy a fresh link.
Can I record a live stream with this?
Yes: choose TS and stop with q when you’re done. A TS file that’s cut off still plays up to the break. See recording an HLS stream.
Summary
Fill in the stream address and any headers, copy the command, and run it in Terminal. Headers go before -i, -c copy keeps the original quality, and a 403 means a missing header or an expired link. For DASH, check that your FFmpeg build has the demuxer first; the MPD to MP4 guide shows how.
Related reading
M3U8 Inspector: Read an HLS Playlist and Calculate Its File Size
Paste an .m3u8 link or its text to see every variant, codec, audio track and segment, and the stream's size: exact where possible, estimated otherwise.
HAR File Video URL Extractor: Find the .m3u8, .mpd and .mp4 Links
Drop a .har network export to list every video manifest, file and segment it holds, with the headers to replay them. Read in your browser, never uploaded.
How to Download an M3U8 Video to MP4 on Mac (and From Chrome)
An .m3u8 is a text playlist, not a video. What's inside one, why a browser save fails, and three tested ways to turn it into one MP4 on a Mac.
Trim with FFmpeg without re-encoding
Install FFmpeg on a Mac and cut the result losslessly.
Get the clip you need. Not the entire video.
A native Mac downloader that fetches the range you mark and cuts by copying streams. Requires macOS 14.0 Sonoma or later.
VidNeat is a software tool. You are responsible for having the rights or permission to access, use, edit and export the media you work with.