Downloads segments from .m3u8 files and combines them into a single video using ffmpeg.
This is a rewrite of the original m3u8_download written in Python. With Go, concurrent downloads are faster and more efficient and the program can be compiled into a standalone executable.
- Extremely Fast: Utilizes goroutines and concurrent downloads
- Configurable: Control concurrent downloads, segment extensions, URL prefixes, and more
- Caching: Optional caching of parsed m3u8 files for faster subsequent runs
- Flexible: Supports both relative and absolute URLs in m3u8 files
- Robust: Handles failed downloads gracefully with options to force combine or skip
-
Install Go 1.21 or later
-
Install dependencies:
go mod download
- Build the program:
go build
-
Make sure ffmpeg is installed and available in your PATH (or specify custom path with --ffmpeg)
-
Basic usage - download and combine segments:
./m3u8_download "https://example.com/video.m3u8" --combine output.mp4
./m3u8_download "https://example.com/video.m3u8"
./m3u8_download "https://example.com/video.m3u8" --combine output.mp4
In case some segments fail to download, use --force-combine to combine the downloaded segments anyway:
./m3u8_download "https://example.com/video.m3u8" --force-combine output.mp4
./m3u8_download "https://example.com/video.m3u8" --headers headers.json --combine output.mp4
./m3u8_download "https://example.com/video.m3u8" --fix segments
./m3u8_download "https://example.com/video.m3u8" --force-ext .ts --combine output.mp4
./m3u8_download "https://example.com/video.m3u8" --concurrent 5 --combine output.mp4
Arguments:
url URL to the m3u8 file
Optional arguments:
--segments-dir DIR Directory to store segments (default: segments)
--force-ext EXT Force specific extension for segments (e.g., .ts)
--force-url-prefix PREFIX Force URL prefix for segments
--cache FILE Path to cache parsed m3u8
--filelist FILE Path for ffmpeg filelist (default: filelist.txt)
--combine OUTPUT Combine segments into OUTPUT file after download
--force-combine OUTPUT Combine segments even if some failed to download
--cleanup Remove segments directory after successful combination
--fix DIR Fix missing segments in the specified directory
--verbose, -v Enable verbose output
--headers FILE Path to JSON file containing request headers
--skip N Skip the first N segments
--limit N Limit the number of segments to download
--concurrent N Number of concurrent downloads (default: 10)
--ffmpeg PATH Path to ffmpeg executable (default: uses ffmpeg from system PATH)
The headers file should be a JSON file containing key-value pairs of HTTP headers:
{
"User-Agent": "Mozilla/5.0 ...",
"Authorization": "Bearer token123"
}
The easiest way to get headers is to use a browser's "Inspect" feature and copy any request on the website as Copy as cURL (bash)
. Then, go to https://curlconverter.com/json/
and paste the cURL there. You will see the "headers" field in the resulting JSON.
This Google Chrome extension, The Stream Detector, captures all stream URLs on a website.
- Go 1.21+
- ffmpeg (in PATH or specified via --ffmpeg)
This project is open source and available under the MIT License.