Making a video with opencv and ffmpeg. How to find the right color format?

前端 未结 5 1675
天涯浪人
天涯浪人 2021-02-08 13:18

I have a webcam video recorder program built with python, opencv and ffmpeg

It works ok except that the color of the video is more blue than the reality. The problem see

5条回答
  •  误落风尘
    2021-02-08 13:39

    The libx264 codec is able to process BGR images. No need to use any conversion to YCbCr. NO need to give a spcific pix_ftm to ffmpeg. I was using RGB and it was causing the blueish effect on the video.

    The solution was simply to use the original image retuned by the camera without any conversion. :)

    I tried this in my previous investigation and it was crashing the app. The solution is to copy the frame returned by the camera.

        frame = opencv.QueryFrame(camera)
        if not frame:
            return None, None
    
        # RGB : use this one for displaying on the screen
        im_rgb = opencv.CreateImage(self.size,  opencv.IPL_DEPTH_8U, 3)
        opencv.CvtColor(frame, im_rgb, opencv.CV_BGR2RGB)
    
        # BGR : Use this one for the video
        im_bgr = opencv.CreateImage(self.size,  opencv.IPL_DEPTH_8U, 3)
        opencv.Copy(frame, im_bgr)
    
        return im_rgb, im_bgr
    

提交回复
热议问题