mirror of
https://github.com/KrisKennaway/ii-vision.git
synced 2024-12-21 20:29:21 +00:00
e4174ed10b
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.
35 lines
704 B
Python
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()
|