Why when i run pipeline on OpenCV-Python do not work correctly


i try to stream video.mp4 file from opencv-python by using Gstream pipeline. but when i run the pipeline in terminal it 's work successful. my problem is when i try to read a video file by Opencv + pipeline:
-My configuration is: jetson Xavier, jetpack 4.4, Opencv-python V4.5. gst-launch-1.0.

This pipeline is work :

gst-launch-1.0 filesrc location=video.mp4 ! qtdemux name=demux demux.video_0 ! queue ! h264parse ! omxh264dec ! nvoverlaysink -e

But when i run this follow program i have in result any stream but just message “empty frame”:

import cv2
def _gst_cap_pipeline():
return “filesrc location=video.mp4 ! qtdemux name=demux demux.video_0 ! queue ! h264parse ! omxh264dec ! appsink sync=false”

source = cv2.VideoCapture(_gst_cap_pipeline(), cv2.CAP_GSTREAMER)

while True:
ret, frame = source.read()
if not ret:
print(‘empty frame’)
cv2.imshow(‘send’, frame)
if cv2.waitKey(1)&0xFF == ord(‘q’):

Please, anyone can help me to solve the problem !! .

Please refer to this sample:
Displaying to the screen with OpenCV and GStreamer - #9 by DaneLLL

1 Like


i had try this code in my Jetson AGX but it dos’nt work, may be it is the problem of version OpenCV-Pyhton !!!.

i have this erroor when i use your code:

[ERROR:0] VIDEOIO(cvCreateFileCapture_Images(filename.c_str())): raised OpenCV exception:

OpenCV(3.4.14) /tmp/pip-req-build-n7x7y8an/opencv/modules/videoio/src/cap_images.cpp:246: error: (-5:Bad argument) CAP_IMAGES: can’t find starting number (in the name of file): filesrc location=/opt/nvidia/deepstream/deepstream-5.0/samples/streams/sample_1080p_h264.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink in function ‘icvExtractPattern’

Src opened, 0x0 @ 0 fps
Failed to open output

can you tell me if it is the OpenCV(3.4.14) that do not take charge pipeline gst-stream !!!, please

The default OpenCV is 4.1.1 and it enables gstreamer by default. Please do re-installation through SDKManager and try again. Probably 3.4.14 is a bit old.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.