Question / Help RTSP stream from IP camera delay in input in preview

Elijahkato

New Member
Found a reference to GStreamer on a VLC bugreport, tried it today. RTSP camera latency went from 1140ms (with built-in Media source) through 400ms (with VLC Video Source) to 60ms!!!!!!!!!! with GStreamer Source!!!! Just came here to spread the good news!

Project:

My steps:
Copy obs-gstreamer.dll from https://github.com/fzwoch/obs-gstreamer/releases/download/v0.1.0/obs-gstreamer.zip (\windows) to PathToOpenBroadcasterSoftware\obs-plugins\64bit\

Get https://gstreamer.freedesktop.org/d...0/mingw/gstreamer-1.0-mingw-x86_64-1.18.0.msi and install. Put PathTo\gstreamer\1.0\mingw_x86_64\bin\ into PATH (or copy libglib-2.0-0.dll, libgobject-2.0-0.dll, libgstapp-1.0-0.dll, libgstaudio-1.0-0.dll, libgstreamer-1.0-0.dll, libgstvideo-1.0-0.dll to PathToOpenBroadcasterSoftware\bin\64bit\, based on https://github.com/fzwoch/obs-gstreamer/issues/13#issuecomment-711106142 but this I have not tried yet...)

Start OBS and add GStreamer Source. We use HikVision IP cameras, my Pipeline looks like this:
Code:
uridecodebin uri=rtsp://username:password@ipaddress/Streaming/Channels/1 name=bin ! queue ! video.
Important to uncheck Sync appsinks to clock, and to my surprise the feed in OBS is lower latency than the feed in Internet Explorer.

Live test on Sunday.
Do you have any idea if there a resource that show how to construct the Gstreamer pipeline for OBS? i know the rtsp url for myy camera already but i cant seem to get it to stream when using gstreamer source. Please help.
 

STEPHANVS

Member
The code in my post is my pipeline in OBS, the uri part is the rtsp link to my camera. It also works without name=bin
I am currently testing with
Code:
uridecodebin uri=rtsp://username:password@ipaddress/Streaming/Channels/1 latency=40 ! queue ! video.
 

armosandor

New Member
I'm trying to get my Dahua rtsp feed into OBS with gstreamer but so far I haven't been able to figure out the correct pipeline. Anybody can provide an example code that works with Dahua?

The following works fine in VLC, but cannot make it work with gstreamer.
rtsp://USERNAME:PW@IP:PORT/cam/realmonitor?channel=1&subtype=2
 

STEPHANVS

Member
I'm trying to get my Dahua rtsp feed into OBS with gstreamer but so far I haven't been able to figure out the correct pipeline. Anybody can provide an example code that works with Dahua?

The following works fine in VLC, but cannot make it work with gstreamer.
rtsp://USERNAME:PW@IP:PORT/cam/realmonitor?channel=1&subtype=2
Maybe it helps, our HikVision camera streams h264, maybe that is why uridecodebin is used and no other elements are required in the pipeline...
See here for rtsp source pipeline builds.
Also, try to ask for help here directly from the developer.
 

armosandor

New Member
Maybe it helps, our HikVision camera streams h264, maybe that is why uridecodebin is used and no other elements are required in the pipeline...
See here for rtsp source pipeline builds.
Also, try to ask for help here directly from the developer.
Thanks, I did set my Dahua camera yesterday to stream h264 to make sure that's not the issue, however it didn't help.
Thanks for the links, I'll check them later.
 

Samalama

New Member
Found a reference to GStreamer on a VLC bugreport, tried it today. RTSP camera latency went from 1140ms (with built-in Media source) through 400ms (with VLC Video Source) to 60ms!!!!!!!!!! with GStreamer Source!!!! Just came here to spread the good news!

Project:

My steps:
Copy obs-gstreamer.dll from https://github.com/fzwoch/obs-gstreamer/releases/download/v0.1.0/obs-gstreamer.zip (\windows) to PathToOpenBroadcasterSoftware\obs-plugins\64bit\

Get https://gstreamer.freedesktop.org/d...0/mingw/gstreamer-1.0-mingw-x86_64-1.18.0.msi and install. Put PathTo\gstreamer\1.0\mingw_x86_64\bin\ into PATH (or copy libglib-2.0-0.dll, libgobject-2.0-0.dll, libgstapp-1.0-0.dll, libgstaudio-1.0-0.dll, libgstreamer-1.0-0.dll, libgstvideo-1.0-0.dll to PathToOpenBroadcasterSoftware\bin\64bit\, based on https://github.com/fzwoch/obs-gstreamer/issues/13#issuecomment-711106142 but this I have not tried yet...)

Start OBS and add GStreamer Source. We use HikVision IP cameras, my Pipeline looks like this:
Code:
uridecodebin uri=rtsp://username:password@ipaddress/Streaming/Channels/1 name=bin ! queue ! video.
Important to uncheck Sync appsinks to clock, and to my surprise the feed in OBS is lower latency than the feed in Internet Explorer.

Live test on Sunday.
Hi, I did exactly as you said but stil couldn see the gstreamer source in OBS. What version of OBS are you using?
In the OBS log i always get:
17:10:29.284: LoadLibrary failed for '../../obs-plugins/64bit/obs-gstreamer.dll': (null) (126)

17:10:29.284: Module '../../obs-plugins/64bit/obs-gstreamer.dll' not loaded
 

STEPHANVS

Member
Hi, I did exactly as you said but stil couldn see the gstreamer source in OBS. What version of OBS are you using?
In the OBS log i always get:
17:10:29.284: LoadLibrary failed for '../../obs-plugins/64bit/obs-gstreamer.dll': (null) (126)

17:10:29.284: Module '../../obs-plugins/64bit/obs-gstreamer.dll' not loaded
Looks like either gstreamer path is not present or required libraries are not in obs directory.
 

STEPHANVS

Member
What does this mean? Add that string to something called PATH? A path in OBS? Please help. I followed your detailed instructions and got to this last part and am stuck.
Open Run or CMD and execute "SystemPropertiesAdvanced", then click on "Environment Variables". There are 2 sections: User and System variables. I updated in both the Path variable.
 

STEPHANVS

Member
Today I got to fiddle around with settings, as our cameras might not be the best, there is jitter with "Sync appsinks to clock" disabled, both with
Code:
uridecodebin uri=rtsp://linktostream name=bin ! queue ! video.
Code:
rtspsrc location=rtsp://linktostream ! rtpjitterbuffer ! rtph264depay ! h264parse ! avdec_h264 ! queue ! video.

uridecodebin, rtspsrc, rtpjitterbuffer accept "latency=*", but it does not matter until "Sync appsinks to clock" is enabled.
Tested with the second pipeline and if "latency=0" is added to rtspsrc and rtpjitterbuffer, "Sync appsinks to clock" can be enabled and latency will stay low, with lower jitter rate. Will increase latency on rtpjitterbuffer over time if needed, with 1 frame (40ms) at a time.

I disabled "Use pipeline timestamps", as when I enabled it, video and audio desynced over time.
 
stepahnvs, i am highly interested in your rtspsrc pipeline, as i got the latency option to work only after ticking the "use pipeline timestamps". We have audio via a different path so it will not hurt us, but if i can prevent the desync would make me feel more relaxed...
 

Lars118

New Member
Found a reference to GStreamer on a VLC bugreport, tried it today. RTSP camera latency went from 1140ms (with built-in Media source) through 400ms (with VLC Video Source) to 60ms!!!!!!!!!! with GStreamer Source!!!! Just came here to spread the good news!

Project:

My steps:
Copy obs-gstreamer.dll from https://github.com/fzwoch/obs-gstreamer/releases/download/v0.1.0/obs-gstreamer.zip (\windows) to PathToOpenBroadcasterSoftware\obs-plugins\64bit\

Get https://gstreamer.freedesktop.org/d...0/mingw/gstreamer-1.0-mingw-x86_64-1.18.0.msi and install. Put PathTo\gstreamer\1.0\mingw_x86_64\bin\ into PATH (or copy libglib-2.0-0.dll, libgobject-2.0-0.dll, libgstapp-1.0-0.dll, libgstaudio-1.0-0.dll, libgstreamer-1.0-0.dll, libgstvideo-1.0-0.dll to PathToOpenBroadcasterSoftware\bin\64bit\, based on https://github.com/fzwoch/obs-gstreamer/issues/13#issuecomment-711106142 but this I have not tried yet...)

Start OBS and add GStreamer Source. We use HikVision IP cameras, my Pipeline looks like this:
Code:
uridecodebin uri=rtsp://username:password@ipaddress/Streaming/Channels/1 name=bin ! queue ! video.
Important to uncheck Sync appsinks to clock, and to my surprise the feed in OBS is lower latency than the feed in Internet Explorer.

Live test on Sunday.

Thank you so much for sharing!
This delay has been bugging me for years and I basically gave up hope!
Gstreamer works like a charm!
 

STEPHANVS

Member
If anyone follows this thread only, my test pipeline changed to:
rtspsrc location=rtspt://url latency=0 ! rtph264depay ! h264parse ! avdec_h264 ! video.

Our camera supports TCP rtsp = rtspt, so jitter should be cut down even further. The latency=0 is ridiculous, I know, but I like testing. My findings are: in the beginning video feed had lower latency than the (windows, directsound) audio feed from the USB (~ -80ms), yes the video was realtime, however over time the latency climbed to +120ms, and seemed to stabilize there. So, my pipeline candidate will be

rtspsrc location=rtspt://url latency=120 ! rtph264depay ! h264parse ! avdec_h264 ! video.

I might add the jitterbuffer back, just for extra safety.
 

ClarksonCote

New Member
If you want to delay audio stream and be able to hear it through monitoring it is best to use VST plugin for sound delay, than it works. I recomend ReaDelay
It is free and works fine. Just turn down the dry fader and the feedback fader and set your delay time.

Thank you for your suggestion. We're using a Macbook now, is there anything similar for MacOS?

I guess it's too much to hope for the support for this - and the stream delay variations - to be native/corrected in OBS? :)
 

STEPHANVS

Member
Hello Stephanvs, may be playing a bit around with the sync options can stabilise the latency ?
Using pipeline timestamps will make video-audio sync unreliable over time if I'm using low latency. My new issue is 3 x h264 stream decode will saturate my graphics card, and interestingly the 3D part gets high and the decode part is not used at all. More weird behaviour is, that it will get high when OBS window lost the window focus. This results in lagging frames...
 

STEPHANVS

Member
Using pipeline timestamps will make video-audio sync unreliable over time if I'm using low latency. My new issue is 3 x h264 stream decode will saturate my graphics card, and interestingly the 3D part gets high and the decode part is not used at all. More weird behaviour is, that it will get high when OBS window lost the window focus. This results in lagging frames...
Nevermind, downgrading to 26.0.2 fixed the issue.
 

STEPHANVS

Member
While at this issue, I found this. Basically:
Code:
gst-inspect-1.0.exe d3d11
shows me the following:
Code:
Plugin Details:
  Name                     d3d11
  Description              Direct3D11 plugin
  Filename                 D:\Programok\gstreamer\1.0\mingw_x86_64\lib\gstreamer-1.0\libgstd3d11.dll
  Version                  1.18.0
  License                  LGPL
  Source module            gst-plugins-bad
  Source release date      2020-09-08
  Binary package           GStreamer Bad Plug-ins source release
  Origin URL               Unknown package origin

  d3d11upload: Direct3D11 uploader
  d3d11download: Direct3D11 downloader
  d3d11convert: Direct3D11 colorspace converter and scaler
  d3d11videosinkelement: Direct3D11 video sink
  d3d11videosink: Direct3D11 video sink bin
  d3d11h264dec: Direct3D11 H.264 NVIDIA GeForce GT 640 Decoder
  d3d11h265dec: Direct3D11 H.265 NVIDIA GeForce GT 640 Decoder

  7 features:
  +-- 7 elements
(in a more colored way...)

Anyway, my current pipeline:
Code:
rtspsrc location=rtspt://url latency=100 ! rtpjitterbuffer latency=0 ! rtph264depay ! h264parse ! d3d11h264dec ! video.
This removes decoding overhead from the CPU and adds it to the GPU.

Still not sure about the rtpjitterbuffer option, so it stays there until further testing.
 

STEPHANVS

Member
While at this issue, I found this. Basically:
Code:
gst-inspect-1.0.exe d3d11
shows me the following:
Code:
Plugin Details:
  Name                     d3d11
  Description              Direct3D11 plugin
  Filename                 D:\Programok\gstreamer\1.0\mingw_x86_64\lib\gstreamer-1.0\libgstd3d11.dll
  Version                  1.18.0
  License                  LGPL
  Source module            gst-plugins-bad
  Source release date      2020-09-08
  Binary package           GStreamer Bad Plug-ins source release
  Origin URL               Unknown package origin

  d3d11upload: Direct3D11 uploader
  d3d11download: Direct3D11 downloader
  d3d11convert: Direct3D11 colorspace converter and scaler
  d3d11videosinkelement: Direct3D11 video sink
  d3d11videosink: Direct3D11 video sink bin
  d3d11h264dec: Direct3D11 H.264 NVIDIA GeForce GT 640 Decoder
  d3d11h265dec: Direct3D11 H.265 NVIDIA GeForce GT 640 Decoder

  7 features:
  +-- 7 elements
(in a more colored way...)

Anyway, my current pipeline:
Code:
rtspsrc location=rtspt://url latency=100 ! rtpjitterbuffer latency=0 ! rtph264depay ! h264parse ! d3d11h264dec ! video.
This removes decoding overhead from the CPU and adds it to the GPU.

Still not sure about the rtpjitterbuffer option, so it stays there until further testing.
Nevermind again... d3d11h264dec uses MORE CPU than avdec_h264... Weird...
 
Top