Reading frames one-by-one to python/numpy
Hjalmar Turesson
hturesson at gmail.com
Mon Dec 7 08:30:54 PST 2015
Hi,
I would like read individual frames to python/numpy for analysis. That is,
I want call a function that reads and returns 1 frame. I thought I could do
this with appsink, but I have 2 problems. 1) I cannot return a frame from
the callback function 2) It doesn't just read 1 frame.
Simple example that does not do what I want:
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, Gtk
GObject.threads_init()
Gst.init(None)
##########
CLI='filesrc location=testVideo.mp4 ! decodebin ! appsink name=sink'
pipeline=Gst.parse_launch(CLI)
appsink=pipeline.get_by_name("sink")
appsink.set_property("max-buffers",1)
appsink.set_property('emit-signals',True)
appsink.set_property('sync',False)
def on_new_buffer(appsink):
sample = appsink.emit('pull-sample')
#get the buffer
buf=sample.get_buffer()
data=buf.extract_dup(0,buf.get_size())
return False # Here I would like to return the frame
appsink.connect('new-sample', on_new_buffer)
pipeline.set_state(Gst.State.PLAYING)
pipeline.set_state(Gst.State.NULL)
Is it possible to do what I want to do using appsink?
Another strategy I tried is to use fdsink and read the data from that
location:
import os
readfd, writefd = os.pipe()
frame_size_bytes = 460800
CLI='filesrc location=testVideo.mp4 ! decodebin ! fdsink name=sink'
pipeline=Gst.parse_launch(CLI)
fdsink=pipeline.get_by_name("sink")
fdsink.set_property("fd", readfd)
pipeline.set_state(Gst.State.PLAYING)
data = os.read(readfd, frame_size_bytes)
pipeline.set_state(Gst.State.PAUSED)
This does not work either. The code hang at the data = os.read... line,
maybe trying to play the entire file before moving on.
How can I read only one frame?
Thanks,
Hjalmar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20151207/9571a3f3/attachment.html>
More information about the gstreamer-devel
mailing list