Creative DIY

How to Live Stream to YouTube With a Raspberry Pi

Christian Cawley Updated 23-05-2019

By adding a camera module to your Raspberry Pi, you essentially get a portable, lightweight, and easy-to-hold-or-mount internet-connected camera.

So, it makes sense that you might want to stream footage with it. But how do you get started with this? Which Pi model should you use? Is one camera module solution better than another? And how the do you get the footage onto YouTube?

As with most things Raspberry Pi, it’s remarkably straightforward.

Why Live Stream With a Raspberry Pi?

With the availability of easy-to-use streaming services like Mixer and Twitch What Is Mixer? How to Start Streaming on This Twitch Alternative Here's everything you need to know about what is Mixer and how to start streaming on Mixer. Read More and so many different devices capable of streaming to YouTube, you might well be wondering “why choose the Pi”?

Well, its size certainly comes into play, enabling you to position the Raspberry Pi in almost any position. Using the Pi as a dedicated YouTube live streaming camera frees up your other devices, too.

And then, there’s that age-old reason: because you can! Setting up the Pi as a live video streamer gives an appreciation of what is going on in the background on other devices performing the same task. It’s a little bit untidy, requiring a long command string, but the result is satisfying.

What You Will Need

To live stream whatever is in front of your Raspberry Pi to YouTube, you’ll need the following:

  • A Raspberry Pi 3 or later.
  • Raspberry Pi Camera Module (original or NoIR revision, either is fine). (While a USB webcam can be used, these instructions assume a Raspberry Pi Camera Module is in use.)
  • Portable battery supply (optional).

For the operating system, the standard Raspbian Stretch will be fine. But you might prefer Ubuntu or Arch Linux, or any of the other Raspberry Pi distros 23 Operating Systems That Run on Your Raspberry Pi Whatever your Raspberry Pi project, there's an operating system for it. Here are the best Raspberry Pi operating systems! Read More currently available.

Next, connect the camera and boot up. Our previous guide to setting up the Raspberry Pi Camera Module How to Set Up a Raspberry Pi Camera Module If you haven't tried Raspberry Pi photography, the camera module is the easiest way to get started. Read More explains how to do this correctly.

You’ll also need a YouTube channel, for streaming your footage to. This isn’t as difficult to set up as you might think.

Set Up Your YouTube Channel

You probably already have a YouTube account. If you use Google Mail, there is an account ready for you to activate. You’ll need a special URL from here that directs the footage captured by the Raspberry Pi’s camera to YouTube.

This is called an RMTP address and is basically a specific media URL.

To find this, head to YouTube, sign in, and look for the Upload button. This is what you would normally use in YouTube to add a video. On this occasion, however, we’re going to ignore this and click Get started button under Live Streaming.

Use YouTube live streaming

In the subsequent screen, fill in the details you want for the live feed. This will be information about the subject of the feed, and a title, which you should add under Basic Info. You’ll also get the chance to set the privacy level of the stream; is it Public, Unlisted, or Private?

Input basic details and description for your stream

In the next tab, Stream key setup, look for the Stream URL and Stream name/key (you’ll need to click Reveal to see this). Note that the Stream key must be kept private—anyone with this information can stream to your YouTube channel!

Grab the rmtp feed link for your Raspberry Pi stream

(Setting up your Pi streaming camera via SSH? Simply copy the stream name/key from the YouTube browser window into your remote Raspberry Pi command line.)

For a look at the other options here, see our guide to setting up a YouTube channel How to Live Stream on YouTube In this article, we'll show you how to live stream on YouTube using both your computer and your smartphone. Read More .

Prepare the Raspberry Pi for Live YouTube Streaming

Now, it’s time to set up your Raspberry Pi for streaming.

Begin by upgrading. This ensures you’re running the most recent version of Raspbian, with all the necessary system and software updates, including raspivid.

sudo apt update
sudo apt upgrade

This will take a few minutes to complete. Once complete, open a terminal window and enter:

sudo raspi-config

Enable the Raspberry Pi camera module

Use the arrow keys to select Enable Camera, tap Enter, then select Yes. You’ll be prompted to reboot. When your Pi restarts, enter:

raspistill –o image.jpg

You’ll find the resulting snap in the Home directory. Once you know that your camera is working with your Raspberry Pi, you can proceed.

Set Up Streaming With avconv

The most recent versions of Raspbian have avconv preinstalled, so you shouldn’t need to install it. However, if you don’t want to upgrade your Raspberry Pi, you can simply install the libav-tools package:

sudo apt install libav-tools

With avconv installed, you’re ready to create the feed for YouTube. You’ll need the stream name/key that you noted down earlier for this.

The command, however, is long:

raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | avconv -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://[your-secret-key-here]

As you can see, it has a lot of elements to it. Now, if you want to go ahead and just run it, then copy the code, paste it into your terminal window, and hit enter. Remember to change [your-secret-key-here] for the Stream key you made a note of earlier.

If everything has worked as intended, you’ll end up with something like this:

Streaming video footage from the Raspberry Pi to YouTube

When this happens, switch back to the YouTube browser tab. A few moments later, the footage will start streaming:

Raspberry Pi video stream to YouTube

What the Stream Command Means

That long command above can be quite confusing to the untrained eye but features a collection of separate parameters. Let’s look at the most important.

-fps: This is the frames per second rate. For the best results it should be over 24, which is the speed movies traditionally ran at in order to create the illusion of movement. If performance is an issue, however, you may prefer to reduce this to improve steaming.

-w -h: These can be used to specify width and height. If you omit them, raspivid will use the full 1920×1080 high definition resolution (1080p).

-b: Output bitrate limit. YouTube’s recommendation is 400-600kbps. A lower figure will reduce upload bandwidth, in exchange for a lower quality video.

-acodec: This one is particularly important for streaming to YouTube. The service doesn’t allow video without an audio track (or audio without a video track) so we use this to create a fake audio track for the stream. As the Raspberry Pi doesn’t ship with a built-in mic, and the best audio results are gained from adding a sound card HAT, this is the easy solution.

-f: This is the output format; in this case it’s flv, the preferred format for YouTube live streams.

Detach Your SSH Session for the Stream to Continue

The raspivid command above initiates a stream, but if you’re connecting via SSH, when you disconnect the stream will close. Surely you can’t leave your PC running just for the Pi to keep streaming?

Fortunately, there is an answer: screen. This is a piece of software you can install that will keep the SSH session running once you disconnect.

Begin by ending the stream (Ctrl + X), then installing screen:

sudo apt install screen

Wait for it to install, then reboot the Pi.

sudo reboot

Reconnect over SSH, sign in, then enter the command to run screen:


This basically creates a separate environment for you to run the raspivid command in, one that will persist when you disconnect. Simply run raspivid as above, then when you’re ready to disconnect hit Ctrl + A.

Close the SSH window, and the stream will continue.

Your Raspberry Pi Camera Is Streaming to YouTube

With the Pi streaming video from the camera, everything should be working fine. All it takes is for you to:

  • Connect the camera module to the Raspberry Pi
  • Position the Pi to capture the scene
  • Run a system update
  • Set up a YouTube channel and copy the stream URL
  • Initiate a stream with the raspivid command

Note that with persistent streaming, there is a chance that things can overheat, which will slow down the stream. If this happens, consider some Raspberry Pi cooling solutions 5 Cool Ways to Keep Your Overclocked Raspberry Pi 3 Chilled With all the cool stuff you can do with a Raspberry Pi, it's no surprise they can get a bit hot. Here are the best ways to cool them down. Read More .

Related topics: DIY Project Tutorials, Media Streaming, Raspberry Pi, Webcam, YouTube.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. parth kanani
    July 28, 2020 at 5:05 pm

    Instead of video from camera I would like to live stream my raspberry pi screen. How can i do that?

  2. Yrjo
    December 19, 2019 at 10:43 am

    I use this comands and my stream works but after a couple of hours it breaks down. I got myself a raspberry fan for cooling but it works for even less time. I can not take picture with my cam. Ok the picture shows after raspistil command but the file isn`t saved to the drive. I have no idea what to do to make raspberry stream 24/7.

  3. Wisse
    June 9, 2019 at 2:32 pm

    Hi all,
    How do I play a live mp3 stream as background music?

  4. I.D.G.
    August 19, 2018 at 5:14 pm

    I’ve been having trouble finding a way to use a USB WebCam to stream to YouTube. As on this page it says a usb camera can be used I would love some guidance.

  5. I.D.G.
    August 19, 2018 at 5:10 pm

    On this page it says that a usb camera can be used to stream from the pI . I’ve been having trouble find out to do this I would love it if someone could help.

  6. Wesley
    May 15, 2018 at 5:06 am

    I have a raspberry pi camera module v2 and I am running this script on a raspberry pi model 3, yet I am getting a low frame rate like 7fps.

  7. andrew
    December 12, 2017 at 1:32 pm

    in the code line it has "raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000" is the -vf supposed to be -wf for video width??


    • brad
      May 30, 2020 at 1:00 pm

      I thought this as Vertical Flip as in changes the view.

  8. Ana
    September 6, 2017 at 2:19 pm

    Hello everyone. I have been struggling a lot with this. It makes no difference if I use ffmpeg or avconv - The camera streams the video on the PI for about 30 seconds ( Input #0 and Input #1) and then I get the same error: "Option re (read input at native frame rate) cannot be applied to output file acodec -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to. Error parsing options for output file codec. Error opening output files: Invalid argument" If I try moving the input option before the file it belongs to, I get another error: "[NULL 0xb60170] Unable to find a suitable output format for 'acodec'" this does not work for me. It is frustrating seeing how many people can use this. Can you help me get it working? Thank you in advance for any suggestions you may have.

    • Ron
      September 29, 2017 at 4:54 pm

      I had the same problem and went back to look at my command line. Did you copy/paste or type it in ? You have to be very careful with the characters since it's easy to mix up a one and lower case 'L'. So the part "pcm_s16le -f s16le" is actually " s6 e". Check the rest of your line and run again.

  9. Dave
    August 13, 2017 at 7:45 am

    I see for audio input is /dev/zero

    I would like to replace this with a USB Mic or some other Mic input on the Raspberry Pi 3. What would be the best command line options to get a USB Mic or equivalent device working with this example that was given by this article?

  10. Wiebe
    June 6, 2017 at 6:12 pm

    I have tryed on my Raspberry Pi 3, and i am using a Logitech C920 webcam, with Motion it works.. and i am now trying it with this, and i am have a error:

    mmal: mmal_vc_component_create: failed to create component '' (1:EN OMEM)
    mmal: mmal_component_create_core: could not create component '' (1)
    mmal: Failed to create camera component
    mmal: main: Failed to create camera component
    mmal: Camera is not detected. Please check carefully the camera module is instal led correctly

    avconv version 11.9-6:11.9-1~deb8u1+rpi1, Copyright (c) 2000-2017 the Libav deve lopers
    built on Apr 26 2017 06:57:28 with gcc 4.9.2 (Raspbian 4.9.2-10)
    [s16le @ 0x1188cc0] Estimating duration from bitrate, this may be inaccurate
    Guessed Channel Layout for Input Stream #0.0 : stereo
    Input #0, s16le, from '/dev/zero':
    Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0.0: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
    [h264 @ 0x1193400] Could not find codec parameters (Video: h264)
    [h264 @ 0x1193400] Estimating duration from bitrate, this may be inaccurate
    pipe:: could not find codec parameters

  11. Matt
    April 18, 2017 at 2:26 pm

    I get the same issue as all the other commenters. It just sits there on "Starting".

  12. John
    April 6, 2017 at 9:34 am

    Hye, i seem to be having a small problem, in youtube i get stuck on the starting part, it doesn't stream. Got any idea what the problem could be?

    • Matt
      April 18, 2017 at 2:27 pm

      I'm wondering if these instructions are now out of date.

  13. Andy
    March 20, 2017 at 12:18 am

    I'm using an RPi3, and I'm unable to start streaming. When I run the code, the image appears on the screen, rather than the code that you have shown in your screen shot. Suggestions

    • Emilio
      March 20, 2017 at 11:53 pm

      If you want to see the terminal, add the -n tag for "no output" for raspivid.

  14. Noam
    February 27, 2017 at 12:14 am

    Do you have an extra 0 in the -b variable?
    Seems like you have 6Mil instead of 6k

  15. kedar
    February 24, 2017 at 5:44 am

    Can we make that live streaming from youtube for private, I have to use it for office purpose. Is it possible?

    • Emilio
      March 21, 2017 at 12:12 am

      On your YouTube Live dashboard, there is an option for privacy where you can select "Private".

  16. Scott
    February 19, 2017 at 2:37 pm

    Followed your tutorial and it still doesn't work.

    I can take an image with raspi-still and it works fine

    I run your command and it shows green on Youtube but it always says I'm offline.

    • Christian Cawley
      February 21, 2017 at 7:45 am

      Recent testing unreliable, however, and best plan would seem to be to manually compile ffmpeg, or wait for it to be reintroduced to Raspbian.

      We'll be updating the article in due course to reflect this.

  17. dTA
    February 15, 2017 at 2:08 pm

    I was a bit confused as to what this thing is about ffmpeg being a precursor to avconv is. I looked it up and it seems avconv is a fork and both are maintained with debian in fact having switched back to ffmpeg apparently. In my opinion as such this article is a bit misleading in that regard.

    • Christian Cawley
      February 21, 2017 at 7:42 am

      At time of writing, avconv was being used in Raspbian Pixel. So hardly misleading!

    • brad
      May 30, 2020 at 1:06 pm

      raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp:// your youtube code here

      All you need to do is change AVCONV in code to FFMPEG.

      It works a treat.

      Only trouble I have now is my video is upside down while streaming so hopefully where it shows -vf I can figure out the number that goes in here to flip it.

  18. suhail
    January 31, 2017 at 4:46 pm

    hi sir, I have one problem with it....
    whenever I stream the video I receive only a blank screen but buffering in terminal window. Can you help to resolve this.

  19. bubiman
    January 25, 2017 at 4:38 pm

    Hi, I got it kind of working. The Pie is streaming to youtube and youtube in receiving data. Youtube even claims the stream quality as good (green) but youtube will simply not start the stream. After 1-2min the stream quality turns to red but still not video visible on youtube.

    Is there a way to hide the video output on the raspi so I can still see the console?

    Thanks for your help and time

    • bubiman
      January 26, 2017 at 1:26 pm

      I tried to stream to twitch because they got a nice Stream Inspector.
      It recognize the video resolution but neither video codec, audio codec, fps nor bitrate.
      Somthing wrong with muxing video and audio? Missing some headers?

  20. Bill Bradstreet
    January 21, 2017 at 8:39 pm

    Thanks for putting this together. I'm weighing in solely so you have more information. I trust you are trying to figure this all out yourself?

    So, I have tested things and I get as far as YouTube telling me that I have started a livestream, but I never get an image. I see my pi is sending up to YouTube at 7Mbps, which is above the -b 6000000 parameter setting, but still YouTube won't show an image. Eventually, it tells me my upload speed isn't fast enough and that users may experience buffering. I never get more than a black screen on the livestream (I see an image on the display connected to the pi).

    I have tried to set -w & -h to 800x600 and -b to something much lower, but with any different settings, I do not get any response from YouTube's livestream page.

    This is my first pi project. I haven't used unix-ish in a long time!! I appreciate you sharing all the commands I've forgotten!

    • Christian Cawley
      January 22, 2017 at 8:28 am

      Thanks Bill. Some more spare time coming this week, so hoping to find some answers...

  21. Techguy
    January 11, 2017 at 3:07 pm

    Has anyone got this to work. I am getting an error "Failed to read RTMP Packet Header"

    • Christian Cawley
      January 11, 2017 at 10:42 pm

      Planning to mount this project again over the weekend, and see what's causing some of these problems.

      • techguy
        January 17, 2017 at 3:51 pm

        Figure anything out on this? Appears to be something with youtube servers.

        • Christian Cawley
          January 18, 2017 at 1:57 pm

          No, still trying. Problem I think is confusing success with stability. We will get this right, however, and make the tutorial more accurate, as soon as it becomes stable.

        • Techguy
          January 19, 2017 at 2:46 am

          There seems to be some issue with Youtube and this. A couple users on a google group forum had posted similar errors streaming to Youtube.

    • kim kloster
      January 23, 2017 at 6:20 pm

      I had my 'secret' in brackets, when I removed them the error vanished. But that was probably just me.

    • brad
      May 30, 2020 at 1:08 pm

      I have it working a treat just have a live stream upside down but it works.

      I have a Pi3B+ with the V2 camera and it all works well, took 24 hours for youtube to verify me but its working woohoo!

  22. Kyle
    January 10, 2017 at 8:36 pm

    Hi! I've followed your instructions, but can't seem to get streaming. I'm using a USB webcam, and am able to get stills from the camera using fswebcam. I tried substituting fswebcam for raspivid in your code, but am getting the following script:

    avconv version 11.8-6:11.8-1~deb8u1+rpi1, Copyright (c) 2000-2016 the Libav developers
    built on Oct 8 2016 02:37:00 with gcc 4.9.2 (Raspbian 4.9.2-10)
    [s16le @ 0x540cc0] Estimating duration from bitrate, this may be inaccurate
    Guessed Channel Layout for Input Stream #0.0 : stereo
    Input #0, s16le, from '/dev/zero':
    Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0.0: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
    [h264 @ 0x553ba0] missing picture in access unit
    [h264 @ 0x553ba0] no frame!
    [h264 @ 0x54b400] Could not find codec parameters (Video: h264)
    [h264 @ 0x54b400] Estimating duration from bitrate, this may be inaccurate
    pipe:: could not find codec parameters

    I'm a total rookie at linux and coding, so any help would be GREATLY appreciated!

  23. Kyle
    January 10, 2017 at 8:32 pm

    Thanks for this! I'm struggling to get it working with a USB webcam and hoped you might have some insight. I have the camera working for stills via fswebcam. I tried replacing '''raspivid''' with '''fswebcam''' in the command and get the following errors:
    [h264 @ 0x553ba0] missing picture in access unit
    [h264 @ 0x553ba0] no frame!
    [h264 @ 0x54b400] Could not find codec parameters (Video: h264)
    [h264 @ 0x54b400] Estimating duration from bitrate, this may be inaccurate
    pipe:: could not find codec parameters

    any help would be greatly appreciated!

  24. Matt
    January 6, 2017 at 1:59 pm

    I plan to follow this guide pretty much later today, but I did have a question I wanted to see about: are there any good solutions for audio? To my knowledge the Pi and the Camera module both lack a built in Mic. Is it possible to just plug in a USB Mic and have it 'just work' or is there further configuration?

    • Christian Cawley
      January 11, 2017 at 10:40 pm

      The audio side of this isn't supported by a device, AFAIK, which is why we add a silent audio track.

  25. Josh
    December 31, 2016 at 11:14 pm

    In your example you reference raspistill to test your R_Pi camera module OR webcam and then in the stream you use raspivid to send the data to Youtube. You cannot use raspistill or raspivid with a webcam, so you might want to remove that reference from your article. (Well, cannot might be too strong of a word.) Fswebcam will work on taking the still, but I haven't tested (nor do I know) if that will send a stream.

    • Christian Cawley
      January 11, 2017 at 10:41 pm

      Thanks Josh, will look into this.

      • p8blr
        January 14, 2018 at 6:25 pm

        Guide works perfect with the official raspberry pi camera, not sure what to do to make it work with my webcam. Would really appreciate it if you could add a second command for use with a usb webcam.

        Thank you!

  26. Ernie
    December 29, 2016 at 6:05 pm

    I followed the detailed tutorial. From the PI side of things it seems that I am transferring Video ok. 31fps @ 6000Kbps, on the you tube side it says stream starting like in the screenshot above, but I never see the live feed. Eventually on the you tube side it says not enough data received. After stopping the encoder on the raspberry pi, a video of the stream is added in you tube. In these videos I can see a few seconds of the feed from the pi, and that is it. Any thoughts?

    • Christian Cawley
      December 29, 2016 at 8:11 pm

      31fps/6000k seems a little to high to me, it would be wise to reduce both of these -- certainly worth experimenting with different rates.

    • ossama
      January 11, 2017 at 1:51 am

      I had the same issue when using avconv, however when using ffmpeg instead, the video started working. you will notice audio delay above 5seconds. i solved this by using -itsoffset 6

  27. Jeff Burr
    December 28, 2016 at 4:38 pm

    This is awesome stuff. I'd really like to make one of these, but I've never done anything with Raspberry Pi before - should be fun!

    How are you powering this setup? Will the USB bring enough power for everything if I just use a USB "wall charger"?

    • PacoOtaktay
      May 28, 2017 at 4:25 am

      You should be using a 5V 2A at least for the Raspberry Pi 2 and a 5V 2.5A for the Raspberry Pi 3. Most cheap cell phone chargers are not enough for stable operation of the Raspberry Pi's.

  28. Dale
    December 23, 2016 at 9:47 pm

    Thanks for sharing this! Do you know if it is possible to stream more than one video at a time?

    • That guy
      December 28, 2016 at 2:27 pm

      Probably not on the same Pi. 2 different Pi's would work.