Raspberry Pi Webcam Server for OBS Streaming
by jacobalze in Circuits > Raspberry Pi
565 Views, 8 Favorites, 0 Comments
Raspberry Pi Webcam Server for OBS Streaming
I was looking for a solution to live stream with a camera on a Raspberry Pi to OBS Studio. I was trying to install OBS directly on the Pi, but I learned that OBS is not directly supported by Raspberry Pi. I found a tutorial here to set up the Pi to steam the cameras to a webserver, then I would pick up the webserver on my PC running OBS. I will use the tutorial I linked above for setting up the server then I will show you how to get it working with OBS Studio.
*Note - If you would like this project to just have the webcam servers as security cameras or something, then skip any of the parts dealing with OBS Studio.
Supplies
This project requires just some basic components for Raspberry Pi:
- Raspberry Pi (I'm using a 3B but any standard Pi model will work)
- Micro SD Card (For Raspberry Pi OS)
- As Many Cameras as you want that can fit on the Pi:
- Raspberry Pi Camera Module AND/OR
- USB Camera
- Some way to interact with your Pi for setup:
- USB Keyboard and Mouse OR
- Touchscreen
- Case and Power Supply
- Windows PC Or Mac
Installing Raspberry Pi OS and OBS Studio
- If you haven't already, install the Raspberry Pi Imager and flash the Raspberry Pi OS onto the Micro Sd Card.
- After setting up, connect your Raspberry Pi to the same network as your PC or Mac.
- Confirm your Pi is up to date:
- Now on your PC or Mac, install OBS Studio through any of these ways:
- OBS Studio Website (PC or Mac)
- Windows App Store (PC only)
- Open the app and configure it how you would like.
Setting Up the Webcam Server on the Raspberry Pi
- Open a terminal on your Raspberry Pi.
- Use the following command to install all needed packages:
- Run the following commands to install Motion from GitHub:
Configuring Motion
- Before configuring, check your camera sources by running the following command:
- Make note of the one(s) you plan to use. Note the first line under your video source (usually something like /dev/video0)
- USB Cams are listed under the device name. If you are unsure of the device name, hook the camera up to your PC or Mac to get the name.
- Pi cam should be listed under something like unicam.
- See the image attached for example.
- You will have to have a separate configuration for each camera. Go to Step 4 to find instructions for doing this.
*Note - If using a Raspberry Pi camera, additional configuration needs to be done. Go to Step 5 for instructions.
- To open the configuration file for Motion, run the following command:
- Find the following lines and ensure they are set to the values below:
- daemon off
- stream_localhost off
- picture_output off
- movie_output off
- stream_maxrate 100
- video_device /dev/video0 (change to respective video device)
- Optional (Don’t include the text after the #):
- framerate 100 # Changing this option will allow for 100 frames to be captured per second, allowing for smoother video. Default is 50
- width 640 # This line changes the width of the image displayed. Default is 640
- height 480 # This option changes the height of the image displayed. Default is 480
- text_left YOUR TEXT and text_right YOUR TEXT # These will add text to the bottom corners. change YOUR TEXT to whatever you want or remove the YOUR TEXT part. Defaults are Camera1 and Date and Time
- Altering these options can drastically affect the performance. You may need to tinker to get the best results.
- IF USING MULTIPLE CAMERAS:
- stream_port 8081 # This is the port your camera feed will go on. Take note of this number because you will need it to access the stream. If adding additional cameras, change it to 8082, 8083, etc..
- Once done, save and exit by pressing CTRL + X then Y, then ENTER.
- Enable the motion service to start at boot:
- Start Motion:
- If you need to stop Motion, run the following line:
- Now, time to check if your server is running.
- First, Get the IP address of your Raspberry Pi:
- Navigate to the following website (replace placeholders with your data):
- Example:
- You should now see your live camera feed!
Adding Additional Cameras
- First, duplicate the configuration file:
- (You can change cam2 to whatever you want just make sure you remember it and use a new one for each additional camera)
- Next, duplicate the service file:
- Open the new service file:
- Edit the following line to use the new configuration file:
- Save and exit by pressing CTRL + X then Y, then ENTER.
- Reload systemd to recognize the new service:
- Now you have another camera setup! Now repeat Step 3 with the new configuration file, and make sure that replace every command that has motion to motion_cam2 or whatever you called your configuration file, and make sure you change the stream port.
- If using a Pi cam, follow Step 5 to configure (unless your first camera was also a Pi cam, the configuration would have copied over)
Additional Steps for Using a Raspberry Pi Camera
- Since the Raspberry Pi camera relies on a library called libcamera we will need to edit the service file. To do this, enter the following line:
- In this file, find the line that contains the following text:
- Or if you added another camera it might look like this:
- Update the line to the following text:
- Or if you have the multi camera setup:
- Save and exit by pressing CTRL + X then Y, then ENTER.
- Reload the systemctl daemon and restart the Motion service:
Configuring OBS Studio
- Now we will configure OBS Studio to use these Cameras.
- At the bottom of the screen there will be a whole bunch of different controls. Find the one named "Sources"
- Hit the + Button under sources.
- Select Browser.
- Select Create New and type in an identifier for your camera (Examples: Front Camera, Camera 1, USB Camera)
- Under URL, Enter the source of your camera (YOUR_PI_IP_ADRESS:YOUR_PORT_NUMBER)
- Scroll down and check the box Refresh browser when scene becomes active.
- Hit OK.
- Adjust The Camera video how you would like it on your screen.
Repeat these steps for multiple cameras.
All Done!
Congratulations! You now have an Raspberry Pi Camera Setup with OBS Studio! You are now able to stream with all of your cameras connected to the Raspberry Pi.
If you are having issues with basic camera configuration, view the tutorial I used to make this here.
If you are having issues when adding multiple cameras or with OBS Studio or are confused with the instructions, let me know in the comments below and I will try to help you.
Thanks for reading!