I would like to send processed frames in OpenCV format from my python script to OBS Studio for display. I've tried to use the Flask method outlined here and add the generated webpage to OBS as "Browser", but it was buggy and slow when used from within my current python code.
Is there any way to just stream the OpenCV frames to OBS directly? E.g. generate an RTSP stream that I can then read in OBS with the "VLC Video Source" input?
Any help would be much appreciated.
Skeleton code:
import cv2
output_to_obs = True
output_to_cv2 = True
camera = cv2.VideoCapture(0)
def frame_to_obs(frame):
# ==========================
# don't know what to do here
# ==========================
pass
def process_frame(frame):
# just an example
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
return frame_gray
while (camera.isOpened()):
ret, frame = camera.read()
if ret == True:
frame = process_frame(frame)
if output_to_obs:
frame_to_obs(frame)
if output_to_cv2:
cv2.imshow('frame',frame)
if cv2.waitKey(1) == 27:
# escape was pressed
break
else:
break