Wanting to mirror a livestream to youtube used to require you to dedicate a single monitor to fullscreening a live stream then use OBS or different live streaming software to stream that screen to youtube/twitch, something that is by far not optimal and probably loses tons of quality over time.

Thanks to how ffmpeg has evolved over the years, you can seamlessly stream without almost any loss in quality by directly restreaming the m3u8 stream into the rtmp stream youtube and twitch gives you.

Here's the command if you want to get straight into it:

ffmpeg -re -i <https://M3U8 STREAM HERE> -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 3000k -f flv rtmp://a.rtmp.youtube.com/live2/<youtube-stream-key>

Broken down:

  • ffmpeg: the command
  • -re: crucial for some/most streams. Reads the input given at the native frame rate, instead of instantly pushing all frames or limiting to 24/30/60/etc.
  • -i <stream>: input stream for ffmpeg to continuously download from.
  • -c:v copy: c specifies the codec of the :v video part of the stream. In this case what it needs to do is copy
  • -c:a aac: c specifies the codec of the :a audio part of the stream. In this case what it needs to encode/decode in aac
  • -ar 44100: audio sampling rate in Hz
  • -ab 128k: audio bitrate, 128k is 128 kilobits
  • -ac 2: number of audio channels, 2 is stereo. Some streams may support 5/7 channels for surround sound
  • -strict -2 Make sure we use the default ffmpeg aac encoder (included for backwards compatibility)
  • -flags +global_header: forces a global header, instead of there being one in each packet.
  • -bsf:a aac_adtstoasc: bitstream filter instructing to convert mpeg 2/4 AAC ADTS to MPEG-4 audio.
  • -bufsize 3000k: buffer size, in this case it's 300 kilobits per second. You can turn it down to save on bandwidth if your connection is slow.
  • -f flv <youtube url+stream key>: Youtube takes in an FLV format stream. The youtube stream url is