Skip to content

Repo for storing the real-time streaming approach and Raspberry Pi code for future use.

Notifications You must be signed in to change notification settings

Park-Ease/ParkEase-Raspberry-Pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Real Time Streaming Process

This is an explanation on how we proceeded with 2 different versions of the process that helped us to complete the project and send the stream from local IP camera to EC2 on another network and run the backend there.

Previous Version:

We currently have a WIFI camera(EZVIZ H6C PRO) that cannot have Tailscale installed instead of a mobile phone(IP WEBCAM APP) that can actually have Tailscale installed and therefore streams can be directly sent to S3.

So we use the Raspberry Pi to forward the streams. Since raspberry pi is in the same network as the IP camera it can easily access it and forward it somewhere.

Now Tailscale is installed and setup in both the Raspberry Pi and EC2 instance. So through that connection now the EC2 is able to access the streams forwarded by Raspberry Pi.

1. Install Tailscale on Both Devices

  • On the Raspberry Pi:

    • Execute the following command to install Tailscale:

      curl -fsSL https://tailscale.com/install.sh | sh
    • Start Tailscale and authenticate:

      sudo tailscale up
    • Follow the provided URL to authenticate and connect the Pi to your Tailscale network.

  • On the EC2 Instance:

    • SSH into your EC2 instance.

    • Install Tailscale:

      curl -fsSL https://tailscale.com/install.sh | sh
    • Start Tailscale and authenticate:

      sudo tailscale up
      sudo tailscale ip
    • Authenticate the EC2 instance to your Tailscale network.

This setup ensures both devices are on the same Tailscale network, allowing secure communication.

2. Verify Network Connectivity

  • Ensure both devices can communicate over Tailscale:
    • On the Pi, ping the EC2 instance's Tailscale IP (e.g., 100.86.12.58):

      ping 100.86.12.58
    • On the EC2 instance, ping the Pi's Tailscale IP (e.g., 100.96.210.51):

      ping 100.96.210.51
    • Successful responses confirm connectivity.

3. Install and Configure FFmpeg on the Raspberry Pi

  • Install FFmpeg:

    sudo apt update
    sudo apt install ffmpeg
  • Test the RTSP stream locally:

    ffplay rtsp://admin:XHNHXP@192.168.227.121/rtsp

    If the stream doesn't play, verify the RTSP URL and camera settings.

4. Stream the RTSP Feed to the EC2 Instance

  • On the EC2 instance, set up a listening port using netcat:

    nc -l -p 8554 | ffplay -
  • On the Pi, stream the RTSP feed to the EC2 instance:

    ffmpeg -i rtsp://admin:XHNHXP@192.168.227.121/rtsp -f mpegts udp://100.86.12.58:8554
    • Replace 100.86.12.58 with your EC2 instance's Tailscale IP if different.

5. Access the stream from the EC2

  • On the EC2 instance, you can access the stream using:

    udp://100.86.12.58:8554

Current Version (Nginx-RTMP on EC2)

1. Configure Nginx with RTMP Module on EC2

# Install dependencies
sudo apt update
sudo apt install -y build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev

# Download and compile Nginx with RTMP
wget http://nginx.org/download/nginx-1.25.3.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/refs/tags/v1.2.2.tar.gz

tar -zxvf nginx-1.25.3.tar.gz
tar -zxvf v1.2.2.tar.gz

cd nginx-1.25.3
./configure --add-module=../nginx-rtmp-module-1.2.2 --with-http_ssl_module
make
sudo make install

2. Configure Nginx RTMP

Edit /usr/local/nginx/conf/nginx.conf:

rtmp {
    server {
        listen 1935;
        chunk_size 4096;
        allow publish 127.0.0.1;
        
        application live {
            live on;
            record off;
            allow play all;
        }
    }
}

Start Nginx:

sudo ./objs/nginx

3. Security Group Setup

  • Open TCP port 1935 in EC2 security group
  • (Optional) Restrict to your public IP for security

4. Raspberry Pi Streaming Setup

ffmpeg -rtsp_transport tcp \
       -i "rtsp://admin:XHNHXP@192.168.1.40" \
       -fflags nobuffer \
       -flags low_delay \
       -vcodec libx264 \
       -preset ultrafast \
       -tune zerolatency \
       -f flv \
       rtmp://<EC2_PUBLIC_IP>/live/stream

Check the stream: ffplay rtmp://<EC2_PUBLIC_IP>/live/stream

This RTMP link can now be used inside the EC2 instance for the backend code.

About

Repo for storing the real-time streaming approach and Raspberry Pi code for future use.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages