Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoWriter not working with 4.7.0.68 #23097

Open
3 of 4 tasks
robin-blanchard opened this issue Jan 4, 2023 · 6 comments
Open
3 of 4 tasks

VideoWriter not working with 4.7.0.68 #23097

robin-blanchard opened this issue Jan 4, 2023 · 6 comments

Comments

@robin-blanchard
Copy link

System Information

// example for python user
OpenCV python version: 4.7.0.68
Operating System / Platform: Ubuntu 20.04
Python version: 3.6.15

Detailed description

Writing a video with VideoWriter now prints some GStreamer error logs:

GStreamer-CRITICAL **: 16:14:00.768: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
[ WARN:0@17.055] global cap_gstreamer.cpp:2563 open OpenCV | GStreamer warning: cannot link element

It doesn't raise any Exception in Python but no video file has been created.

Downgrading to 4.6.0.66 fixes the problem

Steps to reproduce

>>> import cv2
>>> writer = cv2.VideoWriter("test.mp4", )
>>> fourcc = cv2.VideoWriter_fourcc(*'mp4v')
>>> writer = cv2.VideoWriter("test.mp4", fourcc, 10, (100, 100))
[ WARN:0@59.608] global cap_gstreamer.cpp:2563 open OpenCV | GStreamer warning: cannot link elements

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@24PaH
Copy link

24PaH commented Jan 5, 2023

A related issue seem to happen for video reading with cv2.VideoCapture.

System infos:

OS: ArchLinux
OpenCV package version: 4.6.0-7 (3rd January update)
Python package version: 3.10.9-1

Description

When reading an MP4 video, the following error happens

[ WARN:0@0.148] global /build/opencv/src/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (2386) handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin
[ WARN:0@0.148] global /build/opencv/src/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (2401) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module uridecodebin0 reported: Your GStreamer installation is missing a plug-in.
[ WARN:0@0.149] global /build/opencv/src/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@0.149] global /build/opencv/src/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

@asmorkalov
Copy link
Contributor

@robin-blanchard @24PaH Please add print(cv.getBuildInformation()) output to the ticket. OpenCV-Python packages for Pypi are built without GStreamer support. I just checked it with my Ubuntu:

  Media I/O: 
    ZLib:                        /usr/local/lib/libz.so (ver 1.2.13)
    JPEG:                        libjpeg-turbo (ver 2.1.3-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         /usr/local/lib/libpng.so (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES
      avcodec:                   YES (59.37.100)
      avformat:                  YES (59.27.100)
      avutil:                    YES (57.28.100)
      swscale:                   YES (6.7.100)
      avresample:                NO
    GStreamer:                   NO
    v4l/v4l2:                    YES (linux/videodev2.h)

GStreamer logs mean that you are using some self-built instance of OpenCV. GStreamer implements video formats and codecs as plugins. You need to switch to official package or install all required plugins for mp4.

@allsey87
Copy link

allsey87 commented Apr 18, 2023

I believe I stumbled across the same issue today when I upgraded to opencv-python 4.7.0.72 causing my code that used VideoWriter to stop working:

GStreamer-CRITICAL **: 16:14:00.768: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
[ WARN:0@17.055] global cap_gstreamer.cpp:2563 open OpenCV | GStreamer warning: cannot link element

After this error message, I reached and failed an assertion in CvCapture_Images class, how I reached that point of the code after calling into the Python constructor for the VideoWriter seems to suggest that the bindings are very broken somewhere. Incidentally, I suspect that the error that @24PaH is seeing on 4.6 is unrelated to this issue.

VideoWriter worked for me again after downgrading to 4.1.1.26. I know that is a huge change in the version number but I do not have time to look into this further unfortunately.

@asmorkalov
Copy link
Contributor

@allsey87 All Packages distributed over Pypi are built with FFmpeg support without GStreamer. Your error message says that GStreamer is used. It means, tha you use self-built OpenCV or you have several instances of OpenCV installed.
OpenCV does not implement video encoders adn decoders by itself, but relies on 3rdparty libraries like GStreamer or FFmpeg. You need to ensure that you use proper OpenCV instance and the requested is supported by OpenCV back-end.

@allsey87
Copy link

allsey87 commented Apr 18, 2023

@asmorkalov opencv-python was installed as an indirect dependency of YOLOX. I did not make any changes myself, however, it was compiled from source and (I guess that) it is possible that the wheel that depended upon opencv-python switched on GStreamer support?

In any case, and regardless of whether GStreamer support was compiled in, it seems pretty strange to end up failing an assertion in the class for reading a sequence of images when I called the VideoWriter constructor. I am pretty sure that I didn't have multiple versions of OpenCV installed, however, this does sound like a pretty plausible explanation for what I was observing. Sorry for the lack of certainly, I just don't have time to double check this.

@asmorkalov
Copy link
Contributor

@allsey87 GSreamer is plugin-based system. You need to install all required plugins to go forward with your OpenCV build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants