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.
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.58with your EC2 instance's Tailscale IP if different.
- Replace
5. Access the stream from the EC2
-
On the EC2 instance, you can access the stream using:
udp://100.86.12.58:8554
# 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 installEdit /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- Open TCP port 1935 in EC2 security group
- (Optional) Restrict to your public IP for security
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/streamCheck the stream: ffplay rtmp://<EC2_PUBLIC_IP>/live/stream
This RTMP link can now be used inside the EC2 instance for the backend code.