By adding a camera module to the Raspberry Pi, you basically get a mobile Internet camera, compact and easy to hold or attach somewhere.
If you want to stream footage with this module, do you know where to start? Which Pi model should you use? Where is the camera module solution better in this case? And how do you live streaming YouTube footage? As with most things on Raspberry Pi, these things are very simple.
Guide to streaming videos to YouTube with Raspberry Pi
Why choose live streaming with Raspberry Pi?
With so many different devices capable of streaming live on YouTube, are you wondering why you chose Pi?
First, the size of the Raspberry Pi certainly works, allowing you to position Raspberry Pi in almost every position. Secondly, using Pi as a dedicated YouTube live camera also frees other devices.
Operations can be a bit lengthy, requiring a long series of commands, but the results will definitely satisfy you.
What do you need to prepare?
To stream anything with the Raspberry Pi directly to YouTube, you'll need the following:
For the operating system, standard Raspbian Stretch will be fine. But you can also choose Ubuntu or Arch Linux or any other Raspberry Pi distribution available.
Next, connect the camera and start up. You will also need a YouTube channel to stream your footage live. This process is not as difficult to set up as you think.
Set up YouTube channel
You may already have a YouTube account. If you use Google Mail, there is an account ready to activate. You will need a special URL from here to transfer the footage recorded by the Raspberry Pi camera to YouTube.
This is called the RMTP address and is basically a specific media URL.
To find this address, visit YouTube, log in and find the Upload button . Here are the steps you usually use in YouTube to add videos. However, in this case, we will ignore this and click the Get started button in Live Streaming.
In the next screen, fill in the details you want for the live feed. This will be information related to the topic of the feed and the title you should add in Basic Info. You will also have the opportunity to set privacy levels for streams ( Public, Unlisted or Private ).
In the next tab, Stream key setup , find Stream URL and Stream name / key (you need to click Reveal to see this information). Note that the Stream key must be secure because anyone with this information can stream it directly to your YouTube channel!
(If you want to set up Pi streaming via SSH, just copy the Stream name / key from the YouTube browser window to the command line of Raspberry Pi remotely).
To see other options here, see the tutorial: How to play live video on YouTube? from TipsMake.com.
Prepare Raspberry Pi to stream directly to YouTube
Now, it's time to set up Raspberry Pi for streaming.
Start by upgrading. This step ensures you can run the latest Raspbian version, with all necessary system and software updates, including raspivid.
sudo apt update sudo apt upgrade
This step will take a few minutes to complete. Once completed, open a terminal window and enter:
sudo raspi-config
Use the arrow keys to select Enable Camera, press Enter
, then select Yes. You will be prompted to restart. When Pi restarts, enter:
raspistill –o image.jpg
You will find results in the Home folder. When you know for sure that the camera is working with the Raspberry Pi, you can continue.
Establish transmission with avconv
The most recent versions of Raspbian have been pre-installed with avconv, so you don't need to install it. However, if you don't want to upgrade your Raspberry Pi, just install the libav-tools package :
sudo apt install libav-tools
Once avconv is installed, you are ready to create a feed for YouTube. You may need Stream name / key that you recorded earlier for this.
However, the command is quite 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://a.rtmp.youtube.com/live2/[your-secret-key-here]
As you can see, the command has many factors. Now, if you want to continue and run it, copy the code, paste it into the terminal window and press Enter
. Remember to change the [your-secret-key-here] to Stream key that you noted earlier.
If everything works as intended, you'll end up with the following result:
When this happens, return to the YouTube browser tab. A moment later, the footage will start streaming:
What does the stream command mean?
The long command above can be quite confusing for beginners, but contains a separate set of parameters. Look at the most important thing.
Split session SSH to play online
The raspivid command above will initialize a stream, but if you are connecting via SSH, when you disconnect, the thread will close. Surely you can't let the computer run just so that Pi continues to transmit, right?
Fortunately, there is a solution to this problem. It is a screen. This is a software you can install, which helps keep the SSH session running when you disconnect.
Start by ending the stream ( Ctrl
+ X
), then install the screen:
sudo apt install screen
Wait for the installation screen to finish, then restart Pi.
sudo reboot
Reconnect via SSH, log in, then enter the command to run the screen:
screen
This basically creates a separate environment for you to run the raspivid command, an environment that will exist when you disconnect. Simply run raspivid as above, then when you are ready to disconnect, press Ctrl
+ A
Close the SSH window and the stream will continue.
With live video from the camera on Pi, everything will work well. All you need is:
Note that with continuous streaming, it is possible that all devices may be too hot, this will slow down the stream. If this happens, consider some Raspberry Pi cooling solutions.
Hope you are succesful.
ncG1vNJzZmismaXArq3KnmWcp51ktbDDjK2mZqukp7KiuYyloK%2BdXam8bsXOrquumpVixKrAx2apmqugl7Kzvthmp6I%3D