I have a USB camera, which could produce MJPG(with 30 fps)/YVY2(with 5-25fps, depending on resolution) and H264 (with 30fps) format video stream. I want to use it for capturing video stream and work on OpenCV.
Firstly I tried cap=cv2.VideoCapture(1)
, which only gives me 5 fps 1080p video.
Then I read some relative guidance, and they suggested me using:
gst-launch-1.0 -v v4l2src device=/dev/video1 ! image/jpeg, width=1920, height=1080 ! nvjpegdec ! "video/x-raw(memory:NVMM), format=I420" ! nvoverlaysink
It works fine on command line and gave me 30 fps 1080,
But it did not work on OpenCV and gave me error.
If I try:
cv2.VideoCapture("v4l2src device=/dev/video1 ! image/jpeg, width=1920, height=1080 ! nvjpegdec ! video/x-raw, format=I420 ! nvvidconv ! video/x-raw ! videoconvert ! appsink",cv2.CAP_GSTREAMER)
It gives me 6-7fps and a little high CPU occupation rate.
Finally, I tried
cv2.VideoCapture(“v4l2src device=/dev/video1 ! image/jpeg, width=1920, height=1080 ! jpegparse ! jpegdec ! video/x-raw, format=I420 ! nvvidconv ! video/x-raw ! appsink”,cv2.CAP_GSTREAMER)
(Note that replace nvjpegdec with jpegdec)
It works with 30fps, but with high CPU/GPU occupation. Maybe it is using CPU decoding…
Is there any other methods to decode camera stream with 30fps, full 1080p resolution and low CPU occupation? Or maybe any H264 decoding methods?