Question / Help Stream video from OpenCV into OBS

zappso

New Member
Hi,

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

I've had a look at the docs but I 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:

Python:
import cv2
import numpy as np
from textwrap import wrap

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()

BTW, yes I know I could just use the webcam as a source directly. 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
 
Top