Introduction
This guide explains how to convert M3U8 streaming files to MP4 format using FFmpeg on Linux. M3U8 files are playlist files used for streaming media that point to various media segments, typically in TS (Transport Stream) format.
Prerequisites
- FFmpeg installed on your Linux system
- A locally downloaded M3U8 file
Step-by-Step Process
Method 1: Two-Step Conversion (Recommended for Remote Streams)
This method works well when your M3U8 file contains references to remote HTTP/HTTPS streams:
-
Download all segments to a single TS file
ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i your-file.m3u8 -c copy segments.ts
-
Convert the TS file to MP4
ffmpeg -i segments.ts -c copy output.mp4
Method 2: Direct Conversion (For Local Files)
If your M3U8 file and all its segments are already downloaded locally:
ffmpeg -i your-file.m3u8 -c copy output.mp4
Method 3: Specifying a Program Stream
If your M3U8 file contains multiple quality variants:
ffmpeg -i your-file.m3u8 -map p:2 -c copy output.mp4
Replace p:2
with the program number you want to select (higher
numbers typically indicate higher quality).
Troubleshooting
Protocol Not on Whitelist Error
If you see an error like Protocol 'https' not on whitelist 'file,crypto,data'
, use the protocol whitelist parameter:
ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i your-file.m3u8 -c copy output.mp4
Empty Segment Errors
If you encounter empty segment errors, it might indicate that:
- The stream requires authentication
- The links in the M3U8 file have expired
- The server blocks direct access to media segments
Solution: Try downloading the stream with a specialized tool like youtube-dl or yt-dlp before conversion.
Command Options Explained
-protocol_whitelist
: Specifies which protocols FFmpeg is allowed to use-c copy
: Copies streams without re-encoding (preserves quality and speeds up conversion)-map p:X
: Selects a specific program stream (quality variant) from the M3U8 file
Final Notes
- This process works best for M3U8 files that you have the right to download and convert
- Some streaming services use DRM or other protection measures that may prevent successful conversion
- For the highest quality, select the program stream with the highest bitrate