Stream video from OpenCV into OBS

zappso

New Member
Hi,

Can anyone help me with streaming video from OpenCV (using Python, or C if necessary) into OBS?

I've had a look at the API docs but they're rather bewildering to a new OBS user, and I can't find any similar examples. I think I need to use obs_source_draw() using the frame data I have but I'm not sure how.

Here's some example Python code that captures the camera in OpenCV, displays it and writes the video out to a file. Frame data is in the "frame" variable, I'd like to have this as a custom source:

Python:
import cv2
import numpy as np

cap = cv2.VideoCapture(0)

ret, frame = cap.read()
h, w, c = frame.shape
print(h, w, c)

fourcc = cv2.VideoWriter_fourcc('m','p','4','v')
out = cv2.VideoWriter('output.mp4', fourcc, 15.0, (w, h))

while(True):
    ret, frame = cap.read()

    out.write(frame)

    frame = cv2.resize(frame, (0,0), fx=0.5, fy=0.5)
    cv2.imshow("Frame", frame)

    ch = cv2.waitKey(1)
    if ch & 0xFF == ord('q'):
        break

cap.release()
out.release()
cv2.destroyAllWindows()

Above code is just a simple example. My code is actually more complex than this; I'm doing object recognition and tracking, etc.

Any help would be greatly appreciated!

Many thanks,
Zappso
 

zappso

New Member
No. Abandoned OBS and piped output from my OpenCV script into ffmpeg with appropriate arguments for streaming to YT.
 

KennethKJ

New Member
Hi Zappso,

I am trying to do something similar (live camera -> OpenCV -> processing -> YouTube Live streaming). Would you mind sharing your solution using opencv, ffmpeg, and YT?

Thanks :)
 

vbfd

New Member
Also interested in this.
Can you achieve realtime performance (sub 1s delay) when using obs + opencv?
 

Nishanth in IDE

New Member
Hi Zappso,

I am trying to do something similar (live camera -> OpenCV -> processing -> YouTube Live streaming). Would you mind sharing your solution using opencv, ffmpeg, and YT?

Thanks :)
I've made this simple live stream ingestor(RTMP), processing and broadcasting to youtube (RTMP). to minimize/optimize delay an NGINX RTMP server can be used for things like stream authentication, rebroadcasting to multiple endpoints and basic load balancing.
 
Top