Anaconda, Python, OpenCV, Capture file with GStreamer error Plugin

Hi,

I am coding in python since 2 years now. I had setup anaconda using OpenCV and everything was working fine. My code is reading a video of a billiard table with balls on it and I extract the route of each ball on it. Unfortunately my Anaconda got corrupt and all my environment setup is lost now.
So I tried now to replicate the setup:

  • Windows 11
  • Anaconda 2.3.1,
  • with an environment using Python 3.9.15
  • OpenCV 4.6.0, just installed in anaconda

Now my code is not running anymore. Here is a snippet from the beginning:

import cv2

filename = “E:/DaVinciResolveProjects/20221208_OffsetSystem/20230115_2157/20230115_2157.mkv”
vs = cv2.VideoCapture(filename)

frames_total = int(vs.get(cv2.CAP_PROP_FRAME_COUNT))
fps = int(vs.get(cv2.CAP_PROP_FPS ))
frame_width = int(vs.get(3))
frame_height = int(vs.get(4))

It produces a error message when it calls the

cv2.VideoCapture(filename)

error message is:

[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (2060) cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin
[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (2076) cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module uridecodebin0 reported: Your GStreamer installation is missing a plug-in.>
[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (1053) cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (616) cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

I tried to search and fix the issue with installing gstreamer, tried older versions of python and openCV, but didn’t work.

I have tried to modified the code like following:

gst_str = (“filesrc location=E:/20230115_2157.mkv ! decodebin ! video/x-matroska ! queue ! videoconvert ! appsink”)
self.vs = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

But produced similar error:

[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (2060) cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin
[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (2076) cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module decodebin0 reported: Your GStreamer installation is missing a plug-in.
[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (1053) cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global …\modules\videoio\src\cap_gstreamer.cpp (616) cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

I read very often that others “built their openCV with GStreamer”. But this is only necessary if you compile a program. I instead just want to run my python scripts.

Actually I never noticed up to now that within openCV a backend is used for the video capturing, nor I have ever had heard about GStreamer…

I actually only want to run it within the python command window or Spyder.

So here are my questions:
Is there an obvious really simple reason why it can’t work as I have done it?
Do I have to install GStreamer libraries manually or is it sufficient when I add the Gstreamer with Anaconda in to my environment?
Is the key to “make an openCV built” with GStreamer?

Please give me a hint in which direction I have to dig.

you’re reading a video file? or from a live webcam? what is the goal?

webcams have native API backends (DSHOW, MSMF). video files are handled by ffmpeg.

gstreamer is not required and not recommended for these two sources. why do you bother with gstreamer pipelines at all? the “WARN” stuff is warnings, nothing else. that’s mostly noise.

Yes, actually I didn’t recognize that the code is still running. But it felt like it stopped and looked like it was frozen. The program continues running but it is very very slow, since I make a jump until I detect a movement and these jumping of 2 s = 120 frames with

vs.set(cv2.CAP_PROP_POS_FRAMES, fps*2)

is getting slower and slower. This was not the case before.

Anyhow: Any idea why I get the GStreamer warning? I don’t want to do anything with Gstreamer. May be I have some ffmpeg issue?

I made some trials with simple code showing the problem with the slow jump.

import cv2
import time

filename = “E:/DaVinciResolveProjects/20221208_OffsetSystem/20230115_2157/20230115_2157.mkv”
vs = cv2.VideoCapture(filename)

Here I just read 600 frames

print(‘Task: read 600 frames’)
framei = 0
tic = time.time()
while framei< 600:
framei = framei + 1
ret, frame = vs.read()

toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+‘fps’)

results in

Task: read 600 frames
11.78s - 50.933fps

Now look at this: If I try to jump further 600 frames the times are really slow

print(‘Task: Jump from frame 600 to 1200’)
tic = time.time()
framei = 1200
vs.set(cv2.CAP_PROP_POS_FRAMES, framei)

toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+‘fps’)

The time it takes :

Task: Jump from frame 600 to 1200
12.843s - 46.716fps

I think I will open just an other thread, since this problem not be related to the topic.