Failing to launch a VideoCapture

I am noticing a failure to open a video capture using openCV and gstreamer. I am using openCv 4.6.0. I can’t seem to open a pipeline on a Debian based system. It seems to work fine with mannually launching it wiht a gst-launch system and not using Open CV.

From my understanding I’m using the same version of OpenCV as the original author of this code who used it successfully, so it tells me the issue is related to many library or my setup. The pipeline specifically seeks to capture in MJPG mode.

The code is:

    video = cv2.VideoCapture("v4l2src device=/dev/video0 ! image/jpeg,format=MJPG,width=1600,height=1200 ! jpegdec ! video/x-raw ! appsink drop=1", cv2.CAP_GSTREAMER)
print(video.isOpened())

The video does not open and ultimatelly there is a failure, here is what I can see of failure logs:

0:00:00.088544893  4906      0xad225e0 INFO                 v4l2src gstv4l2src.c:708:gst_v4l2src_query_preferred_size:<v4l2src0> Detect input 0 as `Camera 1`
0:00:00.088610809  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:764:gst_v4l2src_setup_source_crop:<v4l2src0> No cropping requested, keep current preferred size
0:00:00.089283669  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:808:gst_v4l2src_negotiate:<v4l2src0> caps of src: video/x-raw, format=(string)YUY2, width=(int)1600, height=(int)1200, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1; video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1; video/x-raw, format=(string)YUY2, width=(int)800, height=(int)600, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)5/1; image/jpeg, width=(int)1600, height=(int)1200, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1 }; image/jpeg, width=(int)1280, height=(int)960, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1, 5/1 }; image/jpeg, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1, 5/1 }; image/jpeg, width=(int)800, height=(int)600, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1, 5/1 }; image/jpeg, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1, 5/1 }; image/jpeg, width=(int)320, height=(int)240, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1, 5/1 }; image/jpeg, width=(int)160, height=(int)120, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1, 5/1 }
0:00:00.089622579  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:816:gst_v4l2src_negotiate:<v4l2src0> caps of peer: image/jpeg, format=(string)MJPG, width=(int)1600, height=(int)1200, framerate=(fraction)[ 0/1, 2147483647/1 ]
0:00:00.089696077  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:822:gst_v4l2src_negotiate:<v4l2src0> intersect: image/jpeg, format=(string)MJPG, width=(int)1600, height=(int)1200, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1 }, pixel-aspect-ratio=(fraction)1/1
0:00:00.089858824  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:556:gst_v4l2src_fixate:<v4l2src0> Fixating caps image/jpeg, format=(string)MJPG, width=(int)1600, height=(int)1200, framerate=(fraction){ 50/1, 30/1, 15/1, 10/1 }, pixel-aspect-ratio=(fraction)1/1
0:00:00.089895865  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:557:gst_v4l2src_fixate:<v4l2src0> Preferred size 1600x1200
0:00:00.089943405  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:580:gst_v4l2src_fixate:<v4l2src0> sorted and normalized caps image/jpeg, format=(string)MJPG, width=(int)1600, height=(int)1200, framerate=(fraction)50/1, pixel-aspect-ratio=(fraction)1/1
0:00:00.107149036  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:638:gst_v4l2src_fixate:<v4l2src0> fixated caps image/jpeg, format=(string)MJPG, width=(int)1600, height=(int)1200, framerate=(fraction)50/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
0:00:00.107202993  4906      0xad225e0 INFO                 v4l2src gstv4l2src.c:854:gst_v4l2src_negotiate:<v4l2src0> fixated to: image/jpeg, format=(string)MJPG, width=(int)1600, height=(int)1200, framerate=(fraction)50/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
0:00:00.845027426  4906      0xad225e0 DEBUG                v4l2src gstv4l2src.c:1277:gst_v4l2src_create:<v4l2src0> ts: 0:34:51.235781000 now 0:34:51.352002733 delay 0:00:00.116221733
0:00:00.845086925  4906      0xad225e0 LOG                  v4l2src gstv4l2src.c:1314:gst_v4l2src_create:<v4l2src0> sync to 0:00:00.020000000 out ts 0:00:00.640506087
[ WARN:0@0.942] global /root/opencv/build/tempinstall/opencv/modules/videoio/src/cap_gstreamer.cpp (2401) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0@0.975] global /root/opencv/build/tempinstall/opencv/modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@0.975] global /root/opencv/build/tempinstall/opencv/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

However, if I just use the GST-launch tool on Debian, the pipeline works fine

gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,format=MJPG,width=1600,height=1200 ! jpegdec ! video/x-raw ! appsink drop=1

Is there anything I’m doing wrong? I can’t figure this out!

crosspost:

1 Like