Ask Your Question
0

Open videofile with using opencv and gstreamer

asked 2019-07-12 06:28:02 -0500

Olivia_Kelly gravatar image

updated 2019-07-12 08:39:59 -0500

supra56 gravatar image

I began to study opencv. Open with opencv a videofile so easy. But I do not understand how you can open the file using the gsteamer. I read the documentation. As written in the documentation,must do so:

filesrc location=videofile ! decodebin name=decoder decoder. ! queue !audioconvert !audioresample ! osssink decoder. ! videoconvert ! xvimagesink

or

filesrc location=something.mp4 ! matroskademux ! decodebin ! videoconvert ! appsink

But I don’t quite understand how to correctly set the path to any file and still use gstreamer. How can I open any video file using opencv and gstreamer? this me code

     import cv2

        #filepath = input("enter the path to the video")
        cap = cv2.VideoCapture("filepath",cv2.CAP_GSTREAMER)
        fps = cap.get(cv2.CAP_PROP_FPS)      # OpenCV2 version 2 used "CV_CAP_PROP_FPS"

        duration = frame_count/fps

        print('fps = ' + str(fps))
        print('duration (S) = ' + str(duration))
        minutes = int(duration/60)
        seconds = duration%60
        print('duration (M:S) = ' + str(minutes) + ':' + str(seconds))
       cap.release()

P.S: Gstreamer is working. I checked the command print(cv2.getBuildInformation()). My OS windows 8.1.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2019-07-12 21:05:29 -0500

supra56 gravatar image

I am using linux, raspberry pi 4b, python 3.8.x:

cap_send = cv2.VideoCapture('videotestsrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
edit flag offensive delete link more

Comments

I'm using windows. But i installed openvc with gstreamer. Python 2.7. And i just paste your code, a i has errors WARNING: no real random source present!

(python.exe:4872): GLib-GObject-CRITICAL **: g_param_spec_boxed: assertion 'G_TY PE_IS_BOXED (boxed_type)' failed

(python.exe:4872): GLib-GObject-CRITICAL **: g_object_class_install_property: as sertion 'G_IS_PARAM_SPEC (pspec)' failed

(python.exe:4872): GLib-GObject-CRITICAL **: g_object_new_valist: object class ' GstPadTemplate' has no property named 'caps' VIDEOIO(cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename)): raised unk nown C++ exception!

Olivia_Kelly gravatar imageOlivia_Kelly ( 2019-07-12 22:32:07 -0500 )edit

Gstreamer will merely worked with python 3. The python 2 will discontinued Dec 2019. That why I'm moving forward. Do not copy and paste to python 2.

supra56 gravatar imagesupra56 ( 2019-07-12 23:13:09 -0500 )edit

I tried to open the file like this cap = cv2.VideoCapture('filesrc location-aaaa.mp4 ! videotestsrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! appsink', cv2.CAP_GSTREAMER), but I got a lot of errorsOpenCV Error: Unspecified error (GStreamer: unable to start pipeline ) in cvCaptureFromCAM_GStreamer, file /home/kelly/opencv-3.4.0/modules/videoio/src/cap_gstreamer.cpp, line 890 VIDEOIO(cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename)): raised OpenCV exception:

/home/kelly/opencv-3.4.0/modules/videoio/src/cap_gstreamer.cpp:890: error: (-2) GStreamer: unable to start pipeline in function cvCaptureFromCAM_GStreamer

what i did wrong?

Olivia_Kelly gravatar imageOlivia_Kelly ( 2019-07-13 09:51:04 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-07-12 06:27:37 -0500

Seen: 66 times

Last updated: Jul 12