|
|
@ -2,10 +2,9 @@ import os |
|
|
|
import subprocess |
|
|
|
import subprocess |
|
|
|
import json |
|
|
|
import json |
|
|
|
from collections.abc import Iterator |
|
|
|
from collections.abc import Iterator |
|
|
|
|
|
|
|
from collections import OrderedDict |
|
|
|
|
|
|
|
|
|
|
|
import numpy as np |
|
|
|
import numpy as np |
|
|
|
from lru import LRU |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from openpilot.tools.lib.filereader import FileReader, resolve_name |
|
|
|
from openpilot.tools.lib.filereader import FileReader, resolve_name |
|
|
|
from openpilot.tools.lib.exceptions import DataUnreadableError |
|
|
|
from openpilot.tools.lib.exceptions import DataUnreadableError |
|
|
|
from openpilot.tools.lib.vidindex import hevc_index |
|
|
|
from openpilot.tools.lib.vidindex import hevc_index |
|
|
@ -16,6 +15,24 @@ HEVC_SLICE_P = 1 |
|
|
|
HEVC_SLICE_I = 2 |
|
|
|
HEVC_SLICE_I = 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LRUCache: |
|
|
|
|
|
|
|
def __init__(self, capacity: int): |
|
|
|
|
|
|
|
self._cache: OrderedDict = OrderedDict() |
|
|
|
|
|
|
|
self.capacity = capacity |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __getitem__(self, key): |
|
|
|
|
|
|
|
self._cache.move_to_end(key) |
|
|
|
|
|
|
|
return self._cache[key] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __setitem__(self, key, value): |
|
|
|
|
|
|
|
self._cache[key] = value |
|
|
|
|
|
|
|
if len(self._cache) > self.capacity: |
|
|
|
|
|
|
|
self._cache.popitem(last=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __contains__(self, key): |
|
|
|
|
|
|
|
return key in self._cache |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def assert_hvec(fn: str) -> None: |
|
|
|
def assert_hvec(fn: str) -> None: |
|
|
|
with FileReader(fn) as f: |
|
|
|
with FileReader(fn) as f: |
|
|
|
header = f.read(4) |
|
|
|
header = f.read(4) |
|
|
@ -135,7 +152,7 @@ class FrameReader: |
|
|
|
cache_size: int = 30, pix_fmt: str = "rgb24"): |
|
|
|
cache_size: int = 30, pix_fmt: str = "rgb24"): |
|
|
|
self.decoder = FfmpegDecoder(fn, index_data, pix_fmt) |
|
|
|
self.decoder = FfmpegDecoder(fn, index_data, pix_fmt) |
|
|
|
self.iframes = self.decoder.iframes |
|
|
|
self.iframes = self.decoder.iframes |
|
|
|
self._cache: LRU[int, np.ndarray] = LRU(cache_size) |
|
|
|
self._cache: LRUCache = LRUCache(cache_size) |
|
|
|
self.w, self.h, self.frame_count, = self.decoder.w, self.decoder.h, self.decoder.frame_count |
|
|
|
self.w, self.h, self.frame_count, = self.decoder.w, self.decoder.h, self.decoder.frame_count |
|
|
|
self.pix_fmt = pix_fmt |
|
|
|
self.pix_fmt = pix_fmt |
|
|
|
|
|
|
|
|
|
|
|