Skip to content

Instantly share code, notes, and snippets.

@philhartung
Last active October 2, 2023 12:33
Show Gist options
  • Save philhartung/8e56a11350f8448a0fa281c4f1716463 to your computer and use it in GitHub Desktop.
Save philhartung/8e56a11350f8448a0fa281c4f1716463 to your computer and use it in GitHub Desktop.
Stream a video via network to OBS with low latency (<100ms)
#!/bin/sh
# host is the IP of the receiving computer
host="192.168.0.101"
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-h264, width=1920, height=1080, framerate=30/1 ! rtph264pay ! udpsink host=$host port=5004
#!/bin/sh
gst-launch-1.0 udpsrc port=5004 ! application/x-rtp, encoding-name=H264 ! rtph264depay ! h264parse ! d3d11h264dec ! autovideosink
@philhartung
Copy link
Author

philhartung commented Nov 30, 2020

In OBS with obs-gstreamer Plugin, add a GStreamer Source:
Nvidia GPU: udpsrc port=5004 ! application/x-rtp, encoding-name=H264 ! rtpjitterbuffer latency=50 ! rtph264depay ! h264parse ! nvh264dec ! video.
GPU: udpsrc port=5004 ! application/x-rtp, encoding-name=H264 ! rtph264depay ! h264parse ! d3d11h264dec ! video.
CPU: udpsrc port=5004 ! application/x-rtp, encoding-name=H264 ! rtph264depay ! h264parse ! openh264dec ! video.
libav: udpsrc port=5004 ! application/x-rtp, encoding-name=H264 ! rtph264depay ! h264parse ! avdec_h264 ! video.

@philhartung
Copy link
Author

Streaming mjpeg via network:

#!/bin/sh
# host is the IP of the receiving computer
host="239.69.2.1"
gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg, width=1920, height=1080, framerate=30/1 ! rtpjpegpay ! udpsink host=$host port=5004

And for receiving: gst-launch-1.0 udpsrc address=239.69.2.1 port=5004 ! application/x-rtp, encoding-name=JPEG ! rtpjpegdepay ! jpegdec ! autovideosink

@philhartung
Copy link
Author

philhartung commented Nov 30, 2022

Streaming H264 on Windows
gst-launch-1.0 videotestsrc ! video/x-raw, width=1920, height=1080, framerate=30/1 ! mfh264device1enc ! video/x-h264, width=1920, height=1080, framerate=30/1 ! rtph264pay ! udpsink host=192.168.1.165 port=5004

Nvidia GPU:
gst-launch-1.0 videotestsrc ! videoconvert ! nvh264enc preset=4 zerolatency=true ! video/x-h264, width=1920, height=1080 ! rtph264pay mtu=9000 ! udpsink host=192.168.1.165 port=5004

@philhartung
Copy link
Author

philhartung commented Dec 4, 2022

ffmpeg stream OBS virtual camera: ffmpeg -f dshow -i video="OBS Virtual Camera" -vcodec h264 -an -f rtp rtp://127.0.0.1:5004
or with QuickSync encoding: ffmpeg -f dshow -i video="OBS Virtual Camera" -vcodec h264_qsv -an -f rtp rtp://127.0.0.1:5004
or with NVENC: ffmpeg -f dshow -i video="OBS Virtual Camera" -vcodec h264_nvenc -an -f rtp rtp://127.0.0.1:5004
or OMX: ffmpeg -f lavfi -i testsrc=size=1280x720:rate=30 -vcodec h264_omx -an -f rtp rtp://192.168.1.165:5004

@philhartung
Copy link
Author

philhartung commented Dec 4, 2022

Playback with Nvidia GPU decoding: gst-launch-1.0 udpsrc port=5004 ! application/x-rtp, encoding-name=H264 ! rtpjitterbuffer latency=60 ! rtph264depay ! h264parse ! nvh264dec ! autovideosink

@philhartung
Copy link
Author

AVMatrix UC2018 streaming (H264 encoding via QuickSync):

@echo off
:loop
ffmpeg -f dshow -rtbufsize 10M -i video="AVMATRIX USB Capture Video" -vcodec h264_qsv -tune zerolatency -an -f rtp rtp://192.168.1.165:5004
goto loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment