Question / Help Stream to OpenCV

brokndremes

New Member
Hello,

I'd like to be able to send the stream to a C++ program and mess with it using OpenCV. I found this link which explains how to create a udp stream. I was wondering if it would be possible to broadcast to 127.0.0.1 and then catch that using their videocapture class.

However I have zero experience with OBS at this time, and am clueless to test if the stream is even working. How can I test this? I've tried directing VLC to udp://127.0.0.1:9999. My current recording settings are attached. I'd appreciate any help I can get and will update if I manage to figure this out on my own.

edit1: First dumb mistake - should've been using udp://@127.0.0.1:9999. I was able to... sort of capture the screen using

cv::Mat frame;
cv::VideoCapture stream;
stream.open("udp://@192.168.1.1:9999");

However the frames I've been grabbing are very distorted.
 

Attachments

  • 16a8d0497b829edda9e93c443425d932.png
    16a8d0497b829edda9e93c443425d932.png
    57.3 KB · Views: 569
Last edited:

sam686

Member
In custom ffmpeg output, your video bitrate is too small, try 12000 as your video bitrate.

Maybe change keyframe interval (frames) down to 30.
 

brokndremes

New Member
In custom ffmpeg output, your video bitrate is too small, try 12000 as your video bitrate.

Maybe change keyframe interval (frames) down to 30.

Tried this - helped a bit, but image will still sometimes come out quite distorted. Am getting the following errors occasionally.
[mpeg2video @ 0000021b80059660] ac-tex damaged at NN NN
[mpeg2video @ 0000021b80059660] skipped MB in I-frame at NN NN
[mpeg2video @ 0000021b80059660] Warning MVs not Available
where NN are numbers.

Occasionally I'll grab frames that are simply blurry.


Maybe try https://obsproject.com/forum/threads/obs-virtualcam.71741/ and use a directshow input for OpenCV

Tried that - It's working wonderfully. Would be nice to reduce the latency a tad but for now this does what I need!

Edit: The virtual webcam does seem to be messing with the output resolution a bit.
Edit 2: Figured out the resolution issue - Had to set the expected resolution in my program using

stream.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
stream.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);

Also managed to reduce the latency a bit by reducing the number of buffer frames.
 
Last edited:

OZtwo

New Member
I'm very interested to learn if we can use OpenCV Python with the new scripting sub-system added?
 
Top