Capture camera video using h264

asked 2019-06-14 04:18:25 -0600

RomanS gravatar image

updated 2019-06-14 04:56:17 -0600

Hi

I have Logitech camera which allows yuyv422, h264, mjpeg according to v4l2-ctl report. The following code works well:

video_capture = cv2.VideoCapture(0)
video_capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
while video_capture.isOpened():
    ret, image = video_capture.read()
    if not ret:
        break
    process(image)

But if I replace 'MJPG' with 'X264' it works in yuyv422 according to print(video_capture.get(cv2.CAP_PROP_FOURCC)) and low fps. If I replace 'MJPG' with 'H264' it gives frames like this. How can I set h264/x264 mode for the camera?

One more thing. When I use ffmpeg it allows me to use h264 as pix_fmt option and works well. So, I'm pretty sure it is OpenCV problem.

edit retag flag offensive close merge delete