steep-balloon-41261
12/14/2023, 3:16 AMdry-elephant-14928
12/14/2023, 7:29 AMlimited-plumber-57970
12/22/2023, 8:04 PMrtc.ArgbFrame with rtc.VideoFormatType.FORMAT_ARGB in order to have the correct color scheme in my stream.
Here is a snippet of the relevant code that works for me
class _CameraTrack:
def __init__(self, ...):
self._argb_frame = rtc.ArgbFrame.create(
rtc.VideoFormatType.FORMAT_ARGB, _WIDTH, _HEIGHT
)
self._source: rtc.VideoSource
def add_frame(self, rgb_arr: np.ndarray) -> None:
bgra = cv2.cvtColor(rgb_arr, cv2.COLOR_RGB2BGRA)
arr = np.frombuffer(self._argb_frame.data, dtype=np.uint8)
arr[:] = bgra.flat
ts = 0
frame = rtc.VideoFrame(
ts, rtc.VideoRotation.VIDEO_ROTATION_0, self._argb_frame.to_i420()
)
self._source.capture_frame(frame)boundless-energy-78552
12/27/2023, 3:26 AMboundless-energy-78552
12/27/2023, 3:26 AMlimited-plumber-57970
12/27/2023, 3:38 AMfreezing-window-32354
12/29/2023, 5:39 PM#create image buffers
width = 1920
height = 1080
argb = np.zeros((height, width, 4), np.uint8)
argb_arr = np.frombuffer(argb.data, dtype=np.uint8)
bgra_video_frame = rtc.ArgbFrame.create(rtc.VideoFormatType.FORMAT_ARGB, width, height)
bgra_video_frame_arr = np.frombuffer(bgra_video_frame.data, dtype=np.uint8)
#copy bgr webcam frame from open cv into a argb numpy array.
@staticmethod
def copy_cv2_bgr_to_argb(cv2_frame : np.ndarray, argb_frame : np.ndarray):
b, g, r = cv.split(cv2_frame)
argb_frame[:,:,0] = b
argb_frame[:,:,1] = g
argb_frame[:,:,2] = r
#copy the argb numpy array to the rtc argb frame buffer
@staticmethod
def copy_cv2_bgr_to_livekit_bgra(argb_arr : np.ndarray, bgra_video_frame_arr : np.ndarray):
bgra_video_frame_arr[:] = argb_arr[:]
#send argbframe to the livekit room
@staticmethod
def sendframe(source: rtc.VideoSource, argbframe : rtc.ArgbFrame):
source.capture_frame(
rtc.VideoFrame(
0,
rtc.VideoRotation.VIDEO_ROTATION_0,
argbframe.to_i420()
))