Skip to content

Instantly share code, notes, and snippets.

@GunGunGun
Forked from qntmpkts/m3u8-to-youtube-live.md
Created March 22, 2024 00:44
Show Gist options
  • Save GunGunGun/8e002524616317e7a7c8eacbb89e9498 to your computer and use it in GitHub Desktop.
Save GunGunGun/8e002524616317e7a7c8eacbb89e9498 to your computer and use it in GitHub Desktop.
Restream m3u8 stream with ffmpeg to youtube live

Setup YouTube Live Event

Head on over to your YouTube live Events page (https://www.youtube.com/my_live_events).

Create a new live event that is unlisted (or private) and of Custom type.

Under Basic ingestion choose 1500 Kbps - 4000 kbps (720p).

Check the Enable 60fps box.

Note your Stream Name and Primary Server URL.

Restream With FFmpeg

Get FFmpeg for your machine (sudo apt-get install ffmpeg)

Run the following in a new terminal window (replacing <m3u8_5000kbps_url> and <youtube_rtmp_address>):

ffmpeg -re -i <m3u8_5000kbps_url> -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 "<youtube_rtmp_address>"

Example:

ffmpeg -re -i protocol://domain.tld/stream.m3u8 -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 3000k -f mp4 "rtmp://a.rtmp.youtube.com/live2/<STREAMNAME/KEY>"

Back To YouTube

Head back to your YouTube Live Event.

Click on the Live Control Room tab up top.

Click the Preview button.

The stream should take a moment to preview, then you can click the Start button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment