Skip to content

Instantly share code, notes, and snippets.

@pojntfx
Last active August 22, 2022 03:00
Show Gist options
  • Save pojntfx/e44dd6faac063444108420fa24912442 to your computer and use it in GitHub Desktop.
Save pojntfx/e44dd6faac063444108420fa24912442 to your computer and use it in GitHub Desktop.
Low-latency, hardware-accelerated peer-to-peer video streaming over TCP/UDP with GStreamer
# Note: You can use `x-rtp` instead of `x-gdp`, `rtp<codec>pay` instead of `gdppay`, `rtp<codec>depay` instead of `gdpdepay` to use RTP instead of GStreamer's format
# Get available formats
v4l2-ctl -d /dev/video0 --list-formats-ext
# Raw (max: 24 FPS 480p)
gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=(int)864, height=(int)480, framerate=24/1' ! videoconvert ! queue ! rtpvrawpay ! queue ! udpsink host=127.0.0.1 port=1234
gst-launch-1.0 udpsrc address=127.0.0.1 port=1234 ! \
"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, \
sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)864, height=(string)480, \
ssrc=(uint)1825678493, payload=(int)96, clock-base=(uint)4068866987, seqnum-base=(uint)24582" ! \
rtpvrawdepay ! queue ! videoconvert ! glimagesink sync=false
# Raw (max: 2 FPS 1536p)
gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=(int)2304, height=(int)1536, framerate=2/1' ! videoconvert ! queue ! rtpvrawpay ! queue ! udpsink host=127.0.0.1 port=1234
gst-launch-1.0 udpsrc address=127.0.0.1 port=1234 ! \
"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, \
sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)2304, height=(string)1536, \
ssrc=(uint)1825678493, payload=(int)96, clock-base=(uint)4068866987, seqnum-base=(uint)24582" ! \
rtpvrawdepay ! queue ! videoconvert ! glimagesink sync=false
# H264 (max: 30 FPS 1080p)
gst-launch-1.0 v4l2src ! 'video/x-h264,width=1920,height=1080,framerate=30/1' ! rtph264pay ! udpsink host=127.0.0.1 port=1234
gst-launch-1.0 udpsrc address=127.0.0.1 port=1234 ! "application/x-rtp, payload=127" ! rtph264depay ! vaapih264dec ! videoconvert ! glimagesink sync=false # Use avdec_h264 to disable hardware acceleration
# MJPEG (max: 30 FPS 1080p - this is too slow to actually be used)
gst-launch-1.0 v4l2src ! 'image/jpeg,width=1920,height=1080,framerate=30/1' ! jpegparse ! rtpjpegpay ! udpsink host=127.0.0.1 port=1234
gst-launch-1.0 udpsrc address=127.0.0.1 port=1234 ! "application/x-rtp, payload=127" ! rtpjpegdepay ! jpegdec ! videoconvert ! glimagesink sync=false
# Raw via TCP over SSH
ssh -tt -R 127.0.0.1:1235:127.0.0.1:1234 root@5.161.147.170 socat TCP-LISTEN:1234,fork,bind=0.0.0.0 TCP:127.0.0.1:1235
gst-launch-1.0 tcpserversrc host=127.0.0.1 port=1234 ! \
"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, \
sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)864, height=(string)480, \
ssrc=(uint)1825678493, payload=(int)96, clock-base=(uint)4068866987, seqnum-base=(uint)24582" ! \
rtpjitterbuffer ! rtpvrawdepay ! queue ! videoconvert ! glimagesink sync=false
gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=(int)864, height=(int)480, framerate=24/1' ! videoconvert ! queue ! rtpvrawpay ! queue ! tcpclientsink host=5.161.147.170 port=1234
# H264 via TCP over SSH to simulate latency
ssh -tt -R 127.0.0.1:1235:127.0.0.1:1234 root@5.161.147.170 socat TCP-LISTEN:1234,fork,bind=0.0.0.0 TCP:127.0.0.1:1235
gst-launch-1.0 tcpserversrc host=127.0.0.1 port=1234 ! "application/x-gdp, payload=127" ! gdpdepay ! vaapih264dec ! videoconvert ! glimagesink sync=false # Use avdec_h264 to disable hardware acceleration
gst-launch-1.0 v4l2src ! 'video/x-h264,width=1920,height=1080,framerate=30/1' ! gdppay ! tcpclientsink host=5.161.147.170 port=1234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment