Intel® Distribution of OpenVINO™ Toolkit
Community support and discussions about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all things computer vision-related on Intel® platforms.
6060 Discussions

GStreamer Error when initiating OpenCV with filename as cv2.VideoCapture('filename.mp4')

RGVGreatCoder
Novice
7,223 Views

Hello,

I just experienced a GStreamer error when tried to initiate opencv with cv2.VideoCapture('<video-file-name.mp4>'). The error reads as follow:

 

[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (2057) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2h264dec0 reported: No valid frames decoded before end of stream
[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (1034) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (597) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
ERROR: Unable to read from webcam. Please verify your webcam settings.

 

Following is the gstreamer list:

 

$ apt list -i | grep gstreamer

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

gstreamer1.0-alsa/oldstable,now 1.14.4-2+deb10u1 armhf [installed]
gstreamer1.0-libav/oldstable,now 1.15.0.1+git20180723+db823502-2+deb10u1 armhf [installed]
gstreamer1.0-omx-rpi-config/oldstable,now 1.14.4-1+rpt1 armhf [installed,automatic]
gstreamer1.0-omx-rpi/oldstable,now 1.14.4-1+rpt1 armhf [installed,automatic]
gstreamer1.0-omx/oldstable,now 1.14.4-1+rpt1 armhf [installed]
gstreamer1.0-plugins-bad/oldstable,now 1.14.4-1+rvt+deb10u2 armhf [installed]
gstreamer1.0-plugins-base/oldstable,now 1.14.4-2+deb10u1 armhf [installed]
gstreamer1.0-plugins-good/oldstable,now 1.14.4-1+rpt1+deb10u1 armhf [installed]
gstreamer1.0-x/oldstable,now 1.14.4-2+deb10u1 armhf [installed]
libgstreamer-gl1.0-0/oldstable,now 1.14.4-2+deb10u1 armhf [installed,automatic]
libgstreamer-plugins-bad1.0-0/oldstable,now 1.14.4-1+rvt+deb10u2 armhf [installed,automatic]
libgstreamer-plugins-base1.0-0/oldstable,now 1.14.4-2+deb10u1 armhf [installed,automatic]
libgstreamer1.0-0/oldstable,now 1.14.4-1 armhf [installed,automatic]

 

I believe I already had ffmpeg installed but I tried installing it again anyway as follows:

 

$ sudo apt install ffmpeg
Reading package lists... Done
Building dependency tree
Reading state information... Done
ffmpeg is already the newest version (7:4.1.8-0+deb10u1+rpt1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

 

The following is installed in my Raspberry Pi 4 (4GB RAM):

Please let me know what I need to do (I will appreciate detailed steps), to fix this issue.

Thank you for all your support and will be waiting for your reply.

0 Kudos
8 Replies
Wan_Intel
Moderator
7,188 Views

Hi RGVGreatCoder,

Thanks for reaching out to us.

 

We are investigating this issue and we will update you at the earliest.

 

 

Regards,

Wan


Wan_Intel
Moderator
7,178 Views

Hi RGVGreatCoder,

Thanks for reaching out to us.

Referring to VideoCapture(index, apiPreference), the apiPreference for GStreamer is CAP_GSTREAMER.

I have tested it on Raspberry Pi 3. I’ll attach the sample script below.

 

 

import cv2 as cv

gst_str = ("filesrc location=bottle-detection.mp4 ! decodebin ! video/x-raw ! queue ! videoconvert ! appsink")
cap = cv.VideoCapture(gst_str, cv.CAP_GSTREAMER)

while cap.isOpened():
    ret, frame = cap.read()

    if not ret:
        print('fail')
        break
    
    gray = cv.cvtColor(frame, cv.COLOR_BGR2RGB)

    cv.imshow('frame', gray)
    if cv.waitKey(1) == ord('q'):
        break

cap.release()
cv.destroyAllWindows()

# Extra: Play video in terminal with the following command:
# gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! videoscale ! video/x-raw, width-640, height=360 ! autovideosink

 

 

gstreamer in raspberry pi ok.JPG

 

On another note, you may refer to Install GStreamer 1.18 on Raspberry Pi 4 to install the missing dependency.

Next, please refer to the OpenCV-Python tutorial for more OpenCV Python tutorials.

Furthermore, you can refer to the following sample, which uses the gst-launch-1.0 command: Vehicle and Pedestrian Tracking Sample (gst-launch command line)

 

 

Best regards,

Wan

 

RGVGreatCoder
Novice
7,169 Views

Thank you for responding fairly quick.

I ran sudo apt-get update && sugo apt-get upgrade. Then after, I installed GStreamer for Buster Version 1.14.4 (from the link you shared above) on my Rasbperry Pi 4 and even tested it by displaying the colored vertical bars screen. It displayed correctly.

I then updated my code, specifically these lines:

def detectVehicle(media_source_type, file_name, show_image):
   video = ("filesrc location=" + file_name + " ! decodebin ! video/x-raw ! queue ! videoconvert ! appsink")
   if media_source_type == 'V':
      # cap = cv.VideoCapture(0)  # 0 =capture video from first camera
      cap = cv.VideoCapture(video, cv.CAP_GSTREAMER) # <-- THIS LINE
   ...

 I ran my program and again, it crashed with the following WARNINGS:

[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (2057) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2h264dec0 reported: No valid frames decoded before end of stream
[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (1034) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (597) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

What calls my attention is it won't continue running despite these are only warnings.

The same program works well on another Raspbian OS (Buster) setup in another microSD Card without OpenVINO.

Did you setup your Rpi3 with the exact same OS and version libraries I setup on mine?

What else could we be missing that is crashing my program?

Wan_Intel
Moderator
7,151 Views

Hi RGVGreatCoder,

Glad to know that you’ve successfully displayed the colored vertical bars screen test which indicates that GStreamer is working properly in your system.

 

For your latest question, it appears to be an issue with your coding. 

We’ve successfully run your code with some modifications (called a function actually).

 

Here is our modified code:

 

 

import cv2 as cv

 

def detectVehicle(file_name,media_source_type):

gst_str = ("filesrc location=" + file_name + " ! decodebin ! video/x-raw ! queue ! videoconvert ! appsink")

if media_source_type == 'V':

cap = cv.VideoCapture(gst_str, cv.CAP_GSTREAMER)

 

while cap.isOpened():

   ret, frame = cap.read()

 

   if not ret:

       print('fail')

       break

   

   gray = cv.cvtColor(frame, cv.COLOR_BGR2RGB)

 

   cv.imshow('frame', gray)

   if cv.waitKey(1) == ord('q'):

       break

 

cap.release()

cv.destroyAllWindows()

 

def main():

detectVehicle('bottle-detection.mp4','V')

 

main()

 

# Extra: Play video in terminal with the following command:

# gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! videoscale ! video/x-raw, width-640, height=360 ! autovideosink

 

 

 

We've also set up our Raspberry Pi 4 with GStreamer for Buster Version 1.14.4 and OpenVINO 2021.4.2 according to your description. We've successfully run the modified code and here are the results:

MicrosoftTeams-image.png

 

 

Best regards,

Wan

 

RGVGreatCoder
Novice
7,127 Views

Well, like I said, my code works well in a program running in another Raspbian OS instance (separate microSD Card) without openvino and on my Windows 11 laptop with openvino (that I installed using PIP). I only shared with you a few lines of code of my program just to make reference of the change I did.

I created a new Python program with your entire code, as it is (providing proper indentation) and it crashed again with exact same GStreamer error. 

pi@raspberrypi:~/Documents/Programs $ python3 gstreamer-test-for-rpi4.py
[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (2057) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2h264dec0 reported: No valid frames decoded before end of stream
[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (1034) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../opencv/modules/videoio/src/cap_gstreamer.cpp (597) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

I also tested the last line that you have commented, and it crashed with this warning message (note: I am using a usb webcam and not the picamera):

$ gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! videoscale ! video/x-raw, width-640, height=360 ! autovideosink
WARNING: erroneous pipeline: could not parse caps "video/x-raw, width-640, height=360"

This is again the detailed information of my Raspbian OS, hardware and packages installed:

$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

$ uname -a
Linux raspberrypi 5.10.63-v7l+ #1496 SMP Wed Dec 1 15:58:56 GMT 2021 armv7l GNU/Linux

$ cat /proc/cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

processor       : 1
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

processor       : 2
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

processor       : 3
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

Hardware        : BCM2711
Revision        : c03112
Serial          : 1000000049ffca91
Model           : Raspberry Pi 4 Model B Rev 1.2

$ python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> import numpy as np
>>> import tflite_runtime as tfl
>>> print(cv.__version__)
4.5.3-openvino
>>> print(np.__version__)
1.21.5
>>> print(tfl.__version__)
2.7.0
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'

$ cmake --version
cmake version 3.16.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).

Questions:

  • How can I check the OpenVINO version installed in my Raspberry Pi 4 (I installed following this page: https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_raspbian.html#insta....)?
  • Notice numpy is version 1.21.5. Shouldn't it be a lower version? Is it relevant anyway for this particular issue?
  • Notice I also have tflite_runtime installed. Is it relevant anyway for this particular issue?
  • What other packages would you like for me to see if they are installed and provide you their respective versions?
  • Can you setup a rpi4 with the exact same hardware/software setup as mine to test again?

Thank you for your patience and will be waiting for your reply,

Wan_Intel
Moderator
7,096 Views

Hi RGVGreatCoder,

Regarding the commented code, it was meant only as a reference and unfortunately there was a typo error.

 

We would appreciate if you could look through any piece of code before executing on your side.

 

Here is the correct code to launch with USB Webcam device:

 

gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! videoscale ! video/x-raw, width=640, height=360 ! Autovideosink

 

 

And here is the result:

 result.png

 

On another note, I would suggest you post your query regarding the GStreamer warning errors in GStreamer Forum. From our side, we've tested and find no issues with GStreamer on our Raspberry Pi Setup.

 

Lastly, answers for your additional questions are given below :

  1. OpenVINO version can be found in this text file: /opt/intel/openvino_2021/inference_engine/version.txt
  2. Not relevant for this particular case.
  3. Not relevant for this particular case.
  4. If you've followed the OpenVINO™ toolkit for Raspbian OS installation guide, all required packages are automatically installed for you.
  5. The above result is replicated using the same hardware and software as yours.

 

 

Best Regards,

Wan

 

 

RGVGreatCoder
Novice
7,082 Views

I tried your line of script but failed with an error that read [...no element "Autovideosink"]. I thought for a moment that was the typo you referred to until I checked your screenshot and changed it to "autovideosink" and could finally see myself (opened the usb webcam connected to my rpi4). Then I couldn't distinguish any difference against the line I wrote before until I look hard for ten minutes and there it was! That hyphen where the equal sign should be... [width-640] Wow! ... XD

For some reason I can't find the folder [/opt/intel/openvino_2021/inference_engine/] when I followed all the installation steps. I recall downloading, unpacking and setting up the file "l_openvino_toolkit_runtime_raspbian_p_2021.4.752.tgz". I also recall being able to run openvino in my rpi4 using a downloaded IR model from your site. But after noticing it wouldn't reach 25FPS (even installing the NCS2 Stick) I moved on to a miniPC with Windows 10. Then I came back to the rpi4 and followed a separate tutorial about tensorflow where I installed many other libraries. I am not sure what happened. I guess I will reinstall openvino on the rpi4 again and test if the issue in this case shows up again.

 

Thank you for your patience. If I get the GStreamer error after reinstalling openvino I will let you know.

 

Wan_Intel
Moderator
7,009 Views

Hi RGVGreatCoder,

Thanks for your question.

 

This thread will no longer be monitored since we have provided suggestions.

If you need any additional information from Intel, please submit a new question.

 


Regards,

Wan


Reply