Accessing gstreamer timestamp from python

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing gstreamer timestamp from python

Letty
Hi all, I am a beginner with gstreamer!

I successfully managed to create a gstreamer pipeline to read frames into
Python using OpenCV cv2.VideoCapture.
I understand that gstreamer has a buffer through which it is possible to
read the timestamp at which the current frame was taken, but it is not clear
to me if it is possible to access this information through python and how.

For completeness, this is my gstreamer pipeline:



which then I call through VideoCapture







--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Accessing gstreamer timestamp from python

Letty
Apologie but my code didn't show up. Here it is

This is my gstreamer pipeline:

gst_in =  ('nvarguscamerasrc sensor-id=0 ! '
    'video/x-raw(memory:NVMM), height=1080, width=1920,
framerate=(fraction)30/1, format=NV12 ! '
    'nvvidconv ! video/x-raw, height=1080, width=1920, format=BGRx ! '
    'videoconvert ! video/x-raw, format=BGR ! '
    'appsink')

which then I call through VideoCapture

cap = cv2.VideoCapture(gst_in, cv2.CAP_GSTREAMER)

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



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Accessing gstreamer timestamp from python

Michael Gruner
Hello Letty

The limitation here is OpenCV rather than Python. The way the GStreamer VideoCapture works is that it will make a copy of the GstBuffer’s data into a newly allocated cv::Mat. As such, once you do a cap.read(), you don’t have access to the GstBuffer nor its timestamp anymore.

Having said that, if you’re looking for a workaround, here’s the precise line that makes the copy:
https://github.com/opencv/opencv/blob/125b9f60574d40cbd59f5927646c385bba96f526/modules/videoio/src/cap_gstreamer.cpp#L1937

Maybe you can read the timestamp from there and embed this info in the first bytes of the image. Not the prettiest solution though ¯\_(ツ)_/¯.

You’ll need to build OpenCV from source, here are some instructions:
https://developer.ridgerun.com/wiki/index.php?title=Compiling_OpenCV_from_Source

Make sure to enable the GStreamer option.

Michael
www.ridgerun.com

> On 2 Apr 2021, at 04:26, Letty <[hidden email]> wrote:
>
> Apologie but my code didn't show up. Here it is
>
> This is my gstreamer pipeline:
>
> gst_in =  ('nvarguscamerasrc sensor-id=0 ! '
>    'video/x-raw(memory:NVMM), height=1080, width=1920,
> framerate=(fraction)30/1, format=NV12 ! '
>    'nvvidconv ! video/x-raw, height=1080, width=1920, format=BGRx ! '
>    'videoconvert ! video/x-raw, format=BGR ! '
>    'appsink')
>
> which then I call through VideoCapture
>
> cap = cv2.VideoCapture(gst_in, cv2.CAP_GSTREAMER)
>
> while True:
>    ret, frame = cap.read()
>
>
>
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Accessing gstreamer timestamp from python

Letty
I don't need to have the timestamp embedded in the frame as of now. The
reason I want it is to be able to synchronize and record multiple cameras,
some of which are accessed through gstreamer and some directly through
Python (and that can't be accessed by gstreamer). What I do is basically
load the frames from gstreamer in a loop as I showed and then send them to
another gstreamer pipeline to encode them and write them to a video file.

So far OpenCV VideoCapture and VideoWriter worked for me, but if there is a
better way to manage gstreamer capture in a loop I'm open to suggestions! I
am very new to gstreamer, I'm trying to learn my way through it.



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel