How To Live Stream To YouTube from a RetroPie

In my last post I showed how you can live stream to Twitch from a RetroPie and in this post I will build off of that and show how you can stream to YouTube.

The basics of this guide are very similar to the Twitch guide so I suggest you give it a read as I will assume that you already know how to do things like ssh into your RetroPie and work with the config files.

First Things First

Before you can stream to YouTube you need to have your RetroPie setup to record gameplace. To do so follow the instructions in this post: How To Record A GamePlay Video From A RetroPie. Once that is working come back and get YouTube streaming working.

YouTube Account and Stream Key

The first step is to get your YouTube live account setup. To do so visit: https://gaming.youtube.com/ and click the “Go Live” button at the top right. If you don’t have a YouTube live account you will be prompted to create one.

screenshot-from-2016-10-17-19-20-13

Then go to your YouTube Live dashboard and scroll to the bottom of the screen. At the bottom of the screen you will see your Encoder Server URL and Stream key:

screenshot-from-2016-10-17-19-14-03

You will need to press the reveal button to actually get your YouTube Stream key. Keep that around but like your Twitch stream key do not share it with anyone.

Streaming Config File

Now that our account is set up we will need to create an FFmpeg config file for our YouTube streaming. We could share the Twitch file but to make this guide easier we will create a new file, plus I think that their settings will need to be different. SSH into your RetroPie and create your YouTube config file with the following command:

$ nano /home/pi/RetroPie/recording/youtube.cfg

screenshot-from-2016-10-17-19-28-38

Then paste the following config settings into the file:

vcodec = libx264
acodec = libfdk_aac
pix_fmt = yuv420p
threads = 2
scale_factor = 1
format = flv
 
video_preset = ultrafast
video_profile = main
video_tune = animation
video_bufsize = 512k
video_minrate = 512k
video_maxrate = 512k
video_r = 60
video_g = 120
video_keyint_min = 60
 
sample_rate = 44100
audio_preset = aac_he_v2
audio_global_quality = 1

screenshot-from-2016-10-17-19-29-36

Then save (CTRL+O) and exit nano (CTRL+X).

Note: I’ve noticed that the video quality on YouTube using these settings is a little worse than what I was seeing on Twitch. So they will need to be tweaked a little bit in the future.

Emulator Configuration

Now we need to edit the config file for the emulators that we want to stream. More information on this can be found in my game play stream tutorial. All emulator config files can be found using the following path:

/opt/retropie/configs/$$SYSTEM$$/emulators.cfg

Where $$SYSTEM$$ is the name of the system that you want to configure. For this example we will be adding a YouTube livestream entry to the NES config file. To do so we edit it with the following command:

$ nano /opt/retropie/configs/nes/emulators.cfg

Then we will add a ‘lr-fceumm-record-youtube’ entry that will stream to YouTube:

lr-fceumm-record-youtube = "/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so --config /opt/retropie/configs/nes/retroarch.cfg --record rtmp://a.rtmp.youtube.com/live2/$$STREAM_KEY$$ --recordconfig /home/pi/RetroPie/recording/youtube.cfg %ROM%"

Where:

rtmp://a.rtmp.youtube.com/live2/$$STREAM_KEY$$

is the YouTube URL we are streaming to and $$STREAM_KEY$$ is the YouTube stream key we got earlier.

And:

--recordconfig /home/pi/RetroPie/recording/youtube.cfg

tells FFmpeg to use the config file we created earlier.

Then save (CTRL+O) and exit nano (CTRL+X).

Streaming Your GamePlay

screenshot-from-2016-10-17-21-22-34

Now that we have everything setup we can stream to YouTube by starting a NES game and then pressing the ‘A’ button while the game is loading. This will load the configuration screen, from there select ‘Select emulator for rom’. You will now see the new ‘lr-fceumm-record-youtube’ entry that we added. Select it (it will now be the default so be sure to change it if you don’t want to stream next time you play) and when you launch the game you should now be streaming to YouTube.

That’s it.

You can check out my live YouTube here: https://gaming.youtube.com/user/selsine/live

Published by

Mark Mruss

Mark Mruss is a computer programmer by nature and by profession. He's written Android apps, win32 apps (we called them applications back then), apps in python, and even a website or two. He is currently fascinated by all things mobile. He likes computers, beer, and his family (not in that order). Find him on twitter @MarkMruss

14 thoughts on “How To Live Stream To YouTube from a RetroPie”

  1. there is any way to debug the connection? Or maybe some package must be installed? I’m able to recreate your setup but doesn’t connect or work the “record”

    1. Yes, you can check for errors in the runcommand.log file.

      After you try to record, SSH into your pi and then run the following command to see what happened:

      nano /dev/shm/runcommand.log

    1. Hmm which emulator are you trying to connect to YouTube? Maybe share the contents of your emulators.cfg file so that I can take a look at it. Be sure to remove your streamkey when you share it.

  2. Hey,

    I’m using snes, with snes9x2010, I copy my log and config:

    Executing: /opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-snes9x2010/snes9x2010_libretro.so –config /opt/retropie/configs/snes/retroarch.cfg –record rtmp://x.rtmp.youtube.com/live2/SECRET_KEY –recordconfig /home/pi/RetroPie/recording/youtube.cfg “/home/pi/RetroPie/roms/snes/Super Mario World 2 – Yoshi’s Island (U) (M3) (V1.1).smc” –appendconfig /dev/shm/retroarch.cfg
    PPU.RenderSub = 0
    PPU.FullClipping = 1
    Settings.Transparency = 1
    Settings.SpeedhackGameID = 0
    PPU.SFXSpeedupHack = 0
    coldata_update_screen = 1

    pisnes = “/opt/retropie/emulators/pisnes/snes9x %ROM%”
    snes9x = “/opt/retropie/emulators/snes9x/snes9x %ROM%”
    lr-armsnes = “/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-armsnes/libpocketsnes.so –config /opt/retropie/configs/snes/retroarch.cfg %ROM%”
    lr-snes9x2005 = “/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-snes9x2005/snes9x2005_libretro.so –config /opt/retropie/configs/snes/retroarch.cfg %ROM%”
    lr-snes9x2002 = “/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-snes9x2002/snes9x2002_libretro.so –config /opt/retropie/configs/snes/retroarch.cfg %ROM%”
    lr-snes9x2010 = “/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-snes9x2010/snes9x2010_libretro.so –config /opt/retropie/configs/snes/retroarch.cfg %ROM%”
    default = “lr-fceumm-record-youtube”
    lr-fceumm-record-youtube = “/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-snes9x2010/snes9x2010_libretro.so –config /opt/retropie/configs/snes/retroarch.cfg –record rtmp://x.rtmp.youtube.com/live2/SECRET_KEY –recordconfig /home/pi/RetroPie/recording/youtube.cfg %ROM%”

        1. No problem, I’m glad you got it to work. I’ve updated the post to make it more clear for future readers. Happy streaming.

  3. Hey pal, from your later streams it looks like you figured out better settings for streaming this to youtube. Any chance you can share that with us?

    Your guides have been a great help, however, I am seeing a pretty low quality output like you mention.

    Thank you!

    1. Also, is there a way to add a camera to your stream if you are doing it this way?

      Not sure what to look for online in terms of guides/tutorials on how to do this since most of them have to do with people streaming themselves from their PCs. Thanks again!

      1. I have tried to figure out how to do this but I could not. It should be possible but I couldn’t figure out a way to pass some of the additional command line arguments that I needed.

    2. Right now my computer is packed away, when I unpack it I will check my latest settings and let you know.

      1. Bummer about not being able to put a camera feed in there and thanks for getting back to me.

        Waiting for your reply. Thank you! 😀

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: