lets try this
This commit is contained in:
parent
ffe7f40e18
commit
e7309c6d44
2 changed files with 28 additions and 24 deletions
|
@ -2,6 +2,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
# GPL 2008
|
||||
import gobject
|
||||
gobject.threads_init()
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
|
@ -45,16 +45,22 @@ class Video(gst.Pipeline):
|
|||
|
||||
self.sbin.connect('pad-added', self._sbinPadAddedCb)
|
||||
self.set_state(gst.STATE_PAUSED)
|
||||
self.get_state()
|
||||
self.width = self.sink.width
|
||||
self.height = self.sink.height
|
||||
self.framerate = self.sink.framerate
|
||||
self.getDuration()
|
||||
self.frames = int((float(self.duration) / gst.SECOND) * float(self.framerate))
|
||||
|
||||
|
||||
def _sbinPadAddedCb(self, unused_sbin, pad):
|
||||
self.log("pad : %s" % pad)
|
||||
pad.link(self.csp.get_pad("sink"))
|
||||
pad.set_blocked_async (True, self._pad_blocked_cb)
|
||||
|
||||
def _pad_blocked_cb(self, pad, blocked):
|
||||
if blocked:
|
||||
#duration
|
||||
if self.duration < 0:
|
||||
q = gst.query_new_duration(gst.FORMAT_TIME)
|
||||
if pad.query(q):
|
||||
format, self.duration = q.parse_duration()
|
||||
|
||||
pad.link(self.csp.get_pad("sink"))
|
||||
pad.set_blocked_async (False, self._pad_blocked_cb)
|
||||
|
||||
def _frameCb(self, unused_thsink, frame, timestamp):
|
||||
self.log("image:%s, timestamp:%s" % (frame, gst.TIME_ARGS(timestamp)))
|
||||
|
@ -73,15 +79,6 @@ class Video(gst.Pipeline):
|
|||
# still some more thumbnails to process
|
||||
gobject.idle_add(self._getFrame, self.queue.pop(0))
|
||||
|
||||
def getDuration(self):
|
||||
if self.duration < 0:
|
||||
pads = self.sink.sink_pads()
|
||||
q = gst.query_new_duration(gst.FORMAT_TIME)
|
||||
for pad in pads:
|
||||
if pad.get_peer() and pad.get_peer().query(q):
|
||||
format, self.duration = q.parse_duration()
|
||||
return self.duration
|
||||
|
||||
def getFrame(self, timestamp, callback):
|
||||
"""
|
||||
Queue a frame request for the given timestamp,
|
||||
|
@ -90,12 +87,12 @@ class Video(gst.Pipeline):
|
|||
"""
|
||||
|
||||
self.log("timestamp %s" % gst.TIME_ARGS(timestamp))
|
||||
if self.duration < 0:
|
||||
self.getDuration()
|
||||
#if self.duration < 0:
|
||||
# self.getDuration()
|
||||
|
||||
if timestamp > self.duration:
|
||||
self.log("timestamp %s > duration %s" % (timestamp, self.duration))
|
||||
return False
|
||||
#if timestamp > self.duration:
|
||||
# self.log("timestamp %s > duration %s" % (timestamp, self.duration))
|
||||
# return False
|
||||
|
||||
self.callback[timestamp] = callback
|
||||
|
||||
|
@ -111,6 +108,11 @@ class Video(gst.Pipeline):
|
|||
def _getFrame(self, timestamp):
|
||||
if not self._ready:
|
||||
return
|
||||
if timestamp > self.duration:
|
||||
if self.mainloop:
|
||||
self.mainloop.quit()
|
||||
return
|
||||
|
||||
self.log("timestamp : %s" % gst.TIME_ARGS(timestamp))
|
||||
self.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
|
||||
gst.SEEK_TYPE_SET, timestamp,
|
||||
|
@ -118,13 +120,13 @@ class Video(gst.Pipeline):
|
|||
return False
|
||||
|
||||
def frame(self, timestamp):
|
||||
mainloop = gobject.MainLoop()
|
||||
self.mainloop = gobject.MainLoop()
|
||||
self._frames[timestamp] = None
|
||||
def callback(frame, timestamp):
|
||||
self._frames[timestamp] = frame
|
||||
mainloop.quit()
|
||||
self.mainloop.quit()
|
||||
if self.getFrame(timestamp, callback):
|
||||
mainloop.run()
|
||||
self.mainloop.run()
|
||||
frame = self._frames[timestamp]
|
||||
del self._frames[timestamp]
|
||||
return frame
|
||||
|
|
Loading…
Reference in a new issue