How Do I Stream Video From My Raspberry Pi Camera?

Are you looking for a way to stream video from your Raspberry Pi camera? If so, you’ve come to the right place! With a few simple steps, you can set up your Raspberry Pi to stream live video over the internet.

Step 1: Install the Required Software

The first thing you’ll need to do is install some software on your Raspberry Pi. Specifically, you’ll need to install the following:

  • FFmpeg: A cross-platform solution for streaming audio and video.
  • NGINX: A popular web server that can be used to serve the video stream.

To install FFmpeg and NGINX on your Raspberry Pi, open up a terminal window and run the following commands:

Installing FFmpeg:

$ sudo apt-get update
$ sudo apt-get install ffmpeg

Installing NGINX:

$ sudo apt-get update
$ sudo apt-get install nginx

Step 2: Connect Your Camera

Next, you’ll need to connect your camera module to your Raspberry Pi. This will vary depending on the type of camera you have. The official Raspberry Pi camera module connects via a ribbon cable that attaches to the camera port on the board.

Step 3: Start Streaming Video

To start streaming video from your Raspberry Pi camera, follow these steps:

Create a Configuration File for NGINX

First, create a new configuration file for NGINX by running the following command:

$ sudo nano /etc/nginx/sites-available/default

Add the following lines of code to this file:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
            push rtmp://;

http {
    sendfile off;
    tcp_nopush on;
    aio on;
    directio 512;

    server {
        listen 8080;

        location /hls {
            # Serve HLS fragments
            types {
                application/ m3u8;
                video/mp2t ts;
            root /tmp/;
            add_header Cache-Control no-cache;

            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;

Save and close the file.


Now start NGINX by running the following command:

$ sudo service nginx start

Stream Video from Your Raspberry Pi Camera

Finally, run the following command to start streaming video from your Raspberry Pi camera:

$ ffmpeg -f video4linux2 -i /dev/video0 -vcodec libx264 -preset ultrafast -tune zerolatency -f flv rtmp://localhost/live/mystream

This command will stream video from your camera to the NGINX server running on your Raspberry Pi. You can then view the stream by visiting http://yourpiaddress:8080/hls/index.m3u8 in your web browser.


In this tutorial, we’ve shown you how to stream live video from your Raspberry Pi camera using FFmpeg and NGINX. With these tools, you can easily set up a simple yet powerful video streaming solution that can be accessed from anywhere in the world.