Revision history [back]

Capture camera video using h264

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():
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. 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.

Capture camera video using h264

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():

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.