2026-07-035 min readffmpeg m3u8 to mp4, convert m3u8 with ffmpeg, ffmpeg m3u8 command

Convert M3U8 to MP4 with FFmpeg: Complete Guide

Step-by-step guide to converting M3U8 streams to MP4 using FFmpeg. Fast, lossless, and fully customizable conversion commands.

Basic FFmpeg M3U8 to MP4 Command

The simplest FFmpeg command to convert an M3U8 stream to MP4:

ffmpeg -i "https://example.com/stream.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4

This downloads the stream and copies the video and audio streams directly into an MP4 container without re-encoding. It's fast (download speed limited only by your connection) and preserves original quality.

Understanding the Flags

  • -i — Input file (the M3U8 URL)
  • -c copy — Copy all streams without re-encoding (stream copy mode)
  • -c:v libx264 — Re-encode video using H.264 codec
  • -c:a aac — Re-encode audio using AAC codec
  • -bsf:a aac_adtstoasc — Bitstream filter for AAC audio (needed for MP4 compatibility)
  • -crf 23 — Quality level (lower = better, 18-28 typical range)

Re-encoding for Better Compatibility

Some streams use codecs not natively supported in MP4. In that case, re-encode:

ffmpeg -i "https://example.com/stream.m3u8" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k output.mp4

Selecting a Specific Quality Level

For multi-bitrate streams, select a specific variant:

ffmpeg -i "https://example.com/master.m3u8" -map 0:v:0 -map 0:a:0 -c copy output.mp4

The -map 0:v:0 selects the first video stream (usually the highest quality). Change the index to select different variants.

Troubleshooting Common Issues

  • "Protocol not found" — Add -protocol_whitelist file,http,https,tcp,tls,crypto
  • "Invalid data found" — Try adding -allowed_extensions ALL before -i
  • "Operation not permitted" — Check if the stream is encrypted (need decryption key)
  • No audio — Some streams have separate audio playlists. Use -map 0:a to include audio

Related Articles