As an experiment, I adapted some of the c++ gstreamer examples from jetson-utils
(specifically these files: 1 & 2) to create the following simple python test script:
import cv2
def check_capture_object(cap):
r, f = cap.read()
print(f'Frame read was successful: {r}')
if r:
print(f'Frame rate: cap.get(cv2.CAP_PROP_FPS)')
print(f'Image dimensions: {f.shape}')
def create_gst_string(codec_as_str, video_options):
gst = f'v4l2src device=/dev/video0 ! {codec_as_str}, width=(int)3264, height=(int)2448 ! {video_options}, format=(string)YUY2 ! appsink'
print(f'Full gst string: {gst}')
return gst
def test_all_gst_strings():
all_codec_strs = [
'video/x-h264',
'video/x-h265',
'video/x-vp8',
'video/x-vp9',
'video/mpeg, mpegversion=(int)2',
'video/mpeg, mpegversion=(int)4',
'image/jpeg',
]
all_video_options = [
'h264parse ! omxh264dec ! video/x-raw',
'h265parse ! omxh265dec ! video/x-raw',
'omxvp8dec ! video/x-raw',
'omxvp9dec ! video/x-raw',
'mpegvideoparse ! omxmpeg2videodec ! video/x-raw',
'mpeg4videoparse ! omxmpeg4videodec ! video/x-raw',
'nvjpegdec ! video/x-raw',
]
for codec_str, vid_option in zip(all_codec_strs, all_video_options):
check_capture_object(cv2.VideoCapture(create_gst_string(codec_str, vid_option), cv2.CAP_GSTREAMER))
print('-----------')
None of the VideoCapture
objects work as expected. See below for the output of the script:
Full gst string: v4l2src device=/dev/video0 ! video/x-h264, width=(int)3264, height=(int)2448 ! h264parse ! omxh264dec ! video/x-raw, format=(string)YUY2 ! appsink
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src22 reported: Internal data stream error.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (886) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Frame read was successful: False
-----------
Full gst string: v4l2src device=/dev/video0 ! video/x-h265, width=(int)3264, height=(int)2448 ! h265parse ! omxh265dec ! video/x-raw, format=(string)YUY2 ! appsink
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (711) open OpenCV | GStreamer warning: Error opening bin: could not link v4l2src23 to h265parse2, v4l2src23 can't handle caps video/x-h265, width=(int)3264, height=(int)2448
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Frame read was successful: False
-----------
Full gst string: v4l2src device=/dev/video0 ! video/x-vp8, width=(int)3264, height=(int)2448 ! omxvp8dec ! video/x-raw, format=(string)YUY2 ! appsink
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src24 reported: Internal data stream error.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (886) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Frame read was successful: False
-----------
Full gst string: v4l2src device=/dev/video0 ! video/x-vp9, width=(int)3264, height=(int)2448 ! omxvp9dec ! video/x-raw, format=(string)YUY2 ! appsink
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src25 reported: Internal data stream error.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (886) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Frame read was successful: False
-----------
Full gst string: v4l2src device=/dev/video0 ! video/mpeg, mpegversion=(int)2, width=(int)3264, height=(int)2448 ! mpegvideoparse ! omxmpeg2videodec ! video/x-raw, format=(string)YUY2 ! appsink
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src26 reported: Internal data stream error.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (886) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Frame read was successful: False
-----------
Full gst string: v4l2src device=/dev/video0 ! video/mpeg, mpegversion=(int)4, width=(int)3264, height=(int)2448 ! mpeg4videoparse ! omxmpeg4videodec ! video/x-raw, format=(string)YUY2 ! appsink
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src27 reported: Internal data stream error.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (886) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Frame read was successful: False
-----------
Full gst string: v4l2src device=/dev/video0 ! image/jpeg, width=(int)3264, height=(int)2448 ! nvjpegdec ! video/x-raw, format=(string)YUY2 ! appsink
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (711) open OpenCV | GStreamer warning: Error opening bin: could not link nvjpegdec8 to appsink28, nvjpegdec8 can't handle caps video/x-raw, format=(string)YUY2
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Frame read was successful: False
-----------