Need to read video in MJPEG format using VideoCapture

asked 2017-03-25 11:52:22 -0500

amie gravatar image

updated 2017-03-25 12:42:13 -0500

I need to read video in MJPG format. I tried the following -

import cv2
cap1 = cv2.VideoCapture(0)
cap1.set(CV_CAP_PROP_FOURCC, ('M', 'J', 'P', 'G'))

It is throwing this error - NameError: name 'CV_CAP_PROP_FOURCC' is not defined

After which I tried -

cap1.set(6, ('M', 'J', 'P', 'G'))

Now, the error is - TypeError: a float is required

How do I capture a video in MJPEG format from the webcam?

edit retag flag offensive close merge delete

Comments

and the error is ? also, please show the exact code, you're trying to use

berak gravatar imageberak ( 2017-03-25 11:54:59 -0500 )edit

I tried the following. Errors follow -

Code:

import cv2

cap1 = cv2.VideoCapture(0) cap1.set(CV_FOURCC('M', 'J', 'P', 'G')) cap1.set(3,320) cap1.set(4,240) cap1.set(5,15)

Error: NameError: name 'CV_FOURCC' is not defined

Code: import cv2

cap1 = cv2.VideoCapture(0) cap1.set(CV_CAP_PROP_FOURCC, ('M', 'J', 'P', 'G')) cap1.set(3,320) cap1.set(4,240) cap1.set(5,15)

Error: NameError: name 'CV_CAP_PROP_FOURCC' is not defined

Code: import cv2

cap1 = cv2.VideoCapture(0) cap1.set(6, ('M', 'J', 'P', 'G')) cap1.set(3,320) cap1.set(4,240) cap1.set(5,15)

Error: TypeError: a float is required

amie gravatar imageamie ( 2017-03-25 12:25:07 -0500 )edit

please put that code into your question, not a comment.

and the syntax is: capture.set(flag(integer), value(double))

berak gravatar imageberak ( 2017-03-25 12:36:33 -0500 )edit

more and more, i think, what you want is not supported at all. (you cannot switch arbitrary webcams to mjpg mode)

WHY do you think, you need this feature ?

berak gravatar imageberak ( 2017-03-25 12:49:36 -0500 )edit

I am using Ubuntu 16.04 on Odroid with oCam. Ocamviewer (default viewer of oCam) is streaming with MJPEG. But when I try the same with openCV, I am not successful.

amie gravatar imageamie ( 2017-03-25 12:51:22 -0500 )edit

I need to stream videos from two cameras in parallel. If I stream raw, without compression, CPU is used up.

amie gravatar imageamie ( 2017-03-25 12:53:18 -0500 )edit