Search code examples
streamudpvideo-streaminggstreamervpn

How can I view a UDP multicast video stream while away from my home network through OpenVPN?


I have a GStreamer pipeline running on a Raspberry Pi on my home's LAN that is multicasting a UDP video (h264) and audio (opus) stream.

MULTICAST_IP_ADDR=224.1.1.1
VIDEO_UDP_PORT=5001
AUDIO_UDP_PORT=5002

gst-launch-1.0 -v rpicamsrc vflip=true hflip=true \
           name=src preview=0 fullscreen=0 bitrate=10000000 \
           annotation-mode=time annotation-text-size=20 \
           ! video/x-h264,width=960,height=540,framerate=24/1 \
           ! h264parse \
           ! rtph264pay config-interval=1 pt=96 \
           ! queue max-size-bytes=0 max-size-buffers=0 \
           ! udpsink host=$MULTICAST_IP_ADDR auto-multicast=true port=$VIDEO_UDP_PORT \
           alsasrc device=plug:dsnooped provide-clock=false \
           ! audio/x-raw,rate=44100 \
           ! audiorate \
           ! audioconvert \
           ! audioresample \
           ! opusenc \
           ! rtpopuspay \
           ! queue max-size-bytes=0 max-size-buffers=0 \
           ! udpsink host=$MULTICAST_IP_ADDR auto-multicast=true port=$AUDIO_UDP_PORT 

I have verified that the multicast is working and is accessible to the devices on the LAN.

I also have an OpenVPN server configured through my router that allows me to access my home network while I'm away.

I realized today that, for some networking reason that i don't yet understand, I'm not able to access the multicast stream (e.g. udp://@224.1.1.1:5001) through my OpenVPN connection like I can when im directly connected to the LAN.

Can you help me find a way to view this stream while connected through OpenVPN?

Best case scenario:
  • We could access the combined video+audio while we are away (latency is not an issue)
Still okay:
  • Access to low frame-rate sample of the video stream (maybe 1 or 2 fps)
Some initial thoughts
  • I can add a Raspberry Pi to act as some kind of intermediary server
  • There's a NAS running Home Assistant in Docker, so I could somehow integrate the local stream there?

Any suggestions and ideas are greatly appreciated, let me know if any other details about my set up would help.


Solution

  • A nice solution was to use HTTP Live Streaming (HLS). On the same Raspberry Pi that is running the multicast video / audio I've done two things:

    1. Set up a new receiving pipeline with GStreamer that receives the H264 video / Opus audio and outputs an HLS feed to the disk:
    sudo rm /var/www/picam-viewer/hls/*.ts
    sudo rm /var/www/picam-viewer/hls/*.m3u8
    
    VIDEO_CAPS="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,payload=(int)96"
    AUDIO_CAPS="application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)OPUS"
    
    sudo gst-launch-1.0 -v udpsrc address=224.1.1.1 port=5002 caps=$AUDIO_CAPS  \
            ! rtpopusdepay \
            ! opusdec \
            ! audioconvert \
            ! avenc_aac \
            ! queue \
            ! combine_to_hls.audio \
            udpsrc address=224.1.1.1 port=5001 caps=$VIDEO_CAPS \
            ! rtph264depay \
            ! h264parse \
            ! queue \
            ! hlssink2 location="/var/www/picam-viewer/hls/%06d.ts" playlist-location="/var/www/picam-viewer/hls/list.m3u8" max-files=5 playlist-length=3 target-duration=2 name=combine_to_hls
    
    1. Set up an Nginx site that facilitates the transfer of the HLS content to the browser using a slightly modified version of this Picam Viewer project.

    So far this works very well while away from the house over an OpenVPN connection. I did have to reach out to my ISP to request a public IP address for the VPN to work. Thankfully my ISP is not evil and was very helpful with this request (local municipal ISP).