def addVideoFile(self, fname): fileitem = { 'filename': fname, 'class': 'video', 'frames': [], } # FIXME: OKAPI should provide a method to get all timestamps at once # FIXME: Some dialog should be displayed, telling the user that the # video is being loaded/indexed and that this might take a while LOG.info("Importing frames from %s. This may take a while..." % fname) video = okv.createVideoSourceFromString(fname) video = okv.toRandomAccessVideoSource(video) # try to convert to iseq, getting all timestamps will be significantly faster iseq = okv.toImageSeqReader(video) if iseq is not None: timestamps = iseq.getTimestamps() LOG.debug("Adding %d frames" % len(timestamps)) fileitem['frames'] = [{ 'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame' } for i, ts in enumerate(timestamps)] else: i = 0 while video.getNextFrame(): LOG.debug("Adding frame %d" % i) ts = video.getTimestamp() frame = { 'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame' } fileitem['frames'].append(frame) i += 1 self._model._root.appendFileItem(fileitem)
def addVideoFile(self, fname): sys.stderr.write("Loading videos isn't supported.") return None fileitem = { 'filename': fname, 'class': 'video', 'frames': [], } # FIXME: OKAPI should provide a method to get all timestamps at once # FIXME: Some dialog should be displayed, telling the user that the # video is being loaded/indexed and that this might take a while LOG.info("Importing frames from %s. This may take a while..." % fname) video = okv.createVideoSourceFromString(fname) video = okv.toRandomAccessVideoSource(video) # try to convert to iseq, getting all timestamps will be significantly faster iseq = okv.toImageSeqReader(video) if iseq is not None: timestamps = iseq.getTimestamps() LOG.debug("Adding %d frames" % len(timestamps)) fileitem['frames'] = [{'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame'} for i, ts in enumerate(timestamps)] else: i = 0 while video.getNextFrame(): LOG.debug("Adding frame %d" % i) ts = video.getTimestamp() frame = {'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame' } fileitem['frames'].append(frame) i += 1 self._model._root.appendFileItem(fileitem)