ii-vision/frame_sequence.py
kris e4174ed10b Extract out input video decoding into separate module.
Prototype a threaded version of the decoder but this doesn't seem to be
necessary as it's not the bottleneck.

Opcode stream is now aware of frame cycle budget and will keep emitting
until budget runs out -- so no need for fullness estimate.
2019-02-23 23:32:07 +00:00

35 lines
704 B
Python

from typing import Iterable
import threading
import queue
import numpy
import skvideo.io
def frame_sequence(filename: str) -> Iterable[numpy.ndarray]:
yield from skvideo.io.vreader(filename)
# Version of the above that delegates decoding to a background thread; not
# clear that it's more efficient though
def frame_sequence2(filename: str) -> Iterable[numpy.ndarray]:
q = queue.Queue()
def worker():
for f in skvideo.io.vreader(filename):
q.put(f)
q.put(None)
t = threading.Thread(target=worker)
t.start()
while True:
frame = q.get()
if frame is None:
break
yield frame
q.task_done()
t.join()