Skip to main content

Streaming a Webcam with GStreamer and NanoPing

In this guide, we will use GStreamer to stream a webcam (/dev/video0) source from a sender device to a receiver device using NanoPing.

note

This guide assumes Ubuntu 24.10 (similar Linux distributions should work).

Installing Required Tools

On both the sender and receiver sides, install the required GStreamer tools by running:

sudo apt-get install gstreamer1.0-tools
sudo apt-get install gstreamer1.0-plugins-good
sudo apt-get install gstreamer1.0-plugins-ugly
sudo apt-get install gstreamer1.0-libav

Streaming Over NanoPing

This guide covers two basic ways to stream data using NanoPing:

  1. UDP Tunnel Mode The sender streams video to localhost UDP, which is picked up by a NanoPing Local UDP component. On the receiver side, NanoPing delivers the stream to localhost UDP, which is then consumed by GStreamer.

  2. TUN Tunnel Mode Devices must be configured so the receiver's TUN IP is reachable from the sender. If NanoPing is set up as a VPN, the TUN IP of the receiver must be reachable from the sender device.

Launching the GStreamer Sender

Once GStreamer is successfully installed, run the following command on the sender device:

gst-launch-1.0 v4l2src device=/dev/video0 ! \
video/x-raw,width=640,height=480 ! \
videoconvert ! \
x264enc tune=zerolatency ! \
rtph264pay config-interval=1 pt=96 ! \
multiudpsink clients=10.0.0.1:5000

What This Command Does

  • Captures video from /dev/video0
  • Sets resolution to 640x480
  • Converts the video format
  • Encodes the video using H.264 with low-latency tuning
  • Packages the stream in RTP
  • Sends the stream to 10.0.0.1 on UDP port 5000

Adjustments for NanoPing Modes

  • UDP Tunnel Mode: Change 10.0.0.1:5000 to the IP and port where your UDP Local component is configured.
  • TUN Tunnel Mode: Change 10.0.0.1:5000 to the IP and port of the remote device, typically the TUN IP of the receiver or another reachable IP.

Launching the GStreamer Receiver

On the receiver device, run:

gst-launch-1.0 udpsrc port=5000 caps="application/x-rtp, media=video, encoding-name=H264, payload=96" ! \
rtph264depay ! \
avdec_h264 ! \
videoconvert ! \
textoverlay text="UDP" valignment=top halignment=center font-desc="Sans, 36" ! \
autovideosink

What This Command Does

  • Listens for incoming RTP-encoded video on UDP port 5000
  • Uses the specified RTP caps to interpret the incoming stream as H.264 video
  • Removes the RTP header (rtph264depay)
  • Decodes the H.264 video (avdec_h264)
  • Converts the video format for display
  • Adds a text overlay labeled “UDP” at the top center
  • Displays the video in a window using the default video sink

Adjustments for NanoPing Modes

  • UDP Tunnel Mode: Use the port configured in the UDP Remote component.
  • TUN Tunnel Mode: Ensure the port matches the one used as the destination in the sender command.