This message was deleted.
# helpdesk
s
This message was deleted.
d
CC: @boundless-energy-78552
l
bump on this thread. I have to input BGRA data into an
rtc.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
Copy code
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)
b
Hey, this is a known issue, this should be resolved on the next update.
Thanks for the report
l
Thanks Theo!
f
This was my solution:
Copy code
#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()
                              ))