Appsink stops (pauses/freezes) after 2 frames.
Hjalmar Turesson
hturesson at gmail.com
Thu Mar 26 12:29:43 PDT 2015
Hi,
I'm trying to write the buffer timestamps (buf.pts) of a webcam steam to a
text file. I use appsink and a little callable function. This works fine
when I stream h.264 (apart from non-monotonical timestamps). But, it fails
if I stream raw or mpeg. I see no errors or warnings, but the stream
freezes/pauses after two frames (i.e. 2 timestamps written to file). When
streaming h.264 h264parse is necessary otherwise it too freezes after 2
frames. I tried using videoparse, but this crashes python, and jpegparse
does not make any difference.
Does anyone have advice?
Scripts (unfortunately not gst-launch since I do not know how to combine
that with the callback)
- - - - - - - - - - - - - - - - - -
Streaming h.264 (WORKS):
class Webcam_ts_h264:
def __init__(self, video_dev='/dev/video0', fps=15):
"""
"""
ts_log_fname = 'ts_test.log'
self.ts_log = open(ts_log_fname, 'w')
self.ts_log.write('n_buf, buf.pts\n')
self.n_frames = 0
self.pipeline = Gst.Pipeline()
def on_new_sample(appsink):
"""
Function called from the pipeline by appsink.
Writes the timestampes of frame capture to a log file.
"""
# Get the buffer
smp = appsink.emit('pull-sample')
buf = smp.get_buffer()
self.n_frames += 1
self.ts_log.write('%d,%0.9f\n' %
(self.n_frames, np.float64(1e-9) * buf.pts))
return Gst.FlowReturn.OK
# Video source:
self.v4l2src = Gst.ElementFactory.make('v4l2src', None)
self.v4l2src.set_property('device', video_dev)
self.v4l2src.set_property('do-timestamp', 'true')
# Formats available from C920 camera:
# 'image/jpeg', 'video/x-h264', 'video/x-raw'
vid_caps = Gst.Caps.from_string('video/x-h264,'
'width=%d,height=%d,'
'framerate=%d/1' % (640, 480, fps))
self.vid_filter = Gst.ElementFactory.make('capsfilter', None)
self.vid_filter.set_property('caps', vid_caps)
self.vid_parse = Gst.ElementFactory.make('h264parse', None)
self.ts_sink = Gst.ElementFactory.make('appsink', None)
# Setting properties of appsink
# Tell sink to emit signals
self.ts_sink.set_property('emit-signals', True)
self.ts_sink.set_property('sync', False) # No sync
# Connect appsink to my function (writing timestamps)
self.ts_sink.connect('new-sample', on_new_sample)
# Add elements to the pipeline
self.pipeline.add(self.v4l2src)
self.pipeline.add(self.vid_filter)
self.pipeline.add(self.vid_parse)
self.pipeline.add(self.ts_sink)
# link
self.v4l2src.link(self.vid_filter)
self.vid_filter.link(self.vid_parse)
self.vid_parse.link(self.ts_sink)
def run(self):
self.pipeline.set_state(Gst.State.PLAYING)
def quit(self):
self.pipeline.set_state(Gst.State.NULL)
self.ts_log.close()
Streaming raw (FAILS):
class Webcam_ts_raw:
def __init__(self, video_dev='/dev/video0', fps=15):
"""
"""
ts_log_fname = 'ts_test.log'
self.ts_log = open(ts_log_fname, 'w')
self.ts_log.write('n_buf, buf.pts\n')
self.n_frames = 0
self.pipeline = Gst.Pipeline()
def on_new_sample(appsink):
"""
Function called from the pipeline by appsink.
Writes the timestampes of frame capture to a log file.
"""
# Get the buffer
smp = appsink.emit('pull-sample')
buf = smp.get_buffer()
self.n_frames += 1
self.ts_log.write('%d,%0.9f\n' %
(self.n_frames, np.float64(1e-9) * buf.pts))
return Gst.FlowReturn.OK
# Video source:
self.v4l2src = Gst.ElementFactory.make('v4l2src', None)
self.v4l2src.set_property('device', video_dev)
self.v4l2src.set_property('do-timestamp', 'true')
# Formats available from C920 camera:
# 'image/jpeg', 'video/x-h264', 'video/x-raw'
vid_caps = Gst.Caps.from_string('video/x-raw,'
'width=%d,height=%d,'
'framerate=%d/1' % (640, 480, fps))
self.vid_filter = Gst.ElementFactory.make('capsfilter', None)
self.vid_filter.set_property('caps', vid_caps)
#self.vid_parse = Gst.ElementFactory.make('jpegparse', None)
self.ts_sink = Gst.ElementFactory.make('appsink', None)
# Setting properties of appsink
# Tell sink to emit signals
self.ts_sink.set_property('emit-signals', True)
self.ts_sink.set_property('sync', False) # No sync
# Connect appsink to my function (writing timestamps)
self.ts_sink.connect('new-sample', on_new_sample)
# Add elements to the pipeline
self.pipeline.add(self.v4l2src)
self.pipeline.add(self.vid_filter)
#self.pipeline.add(self.vid_parse)
self.pipeline.add(self.ts_sink)
# link
self.v4l2src.link(self.vid_filter)
self.vid_filter.link(self.ts_sink)
#self.vid_filter.link(self.vid_parse)
#self.vid_parse.link(self.ts_sink)
def run(self):
self.pipeline.set_state(Gst.State.PLAYING)
def quit(self):
self.pipeline.set_state(Gst.State.NULL)
self.ts_log.close()
Best regards,
Hjalmar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20150326/720b983a/attachment-0001.html>
More information about the gstreamer-devel
mailing list