Ah, I completely missed that, should be exactly what I need. Unfortunately, I get an exception when I use that. I tried with threshold 17, 50 and 500 just to be sure, and it's always the same error. When this happens, no stream files are saved.
non-existing PPS 0 referenced
non-existing PPS 0 referenced
decode_slice_header error
no frame!
Exception in thread Thread-6:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/mnt/ssd/collision-avoidance/luxonis/.venv/lib/python3.8/site-packages/sentry_sdk/integrations/threading.py", line 69, in run
reraise(*_capture_exception())
File "/mnt/ssd/collision-avoidance/luxonis/.venv/lib/python3.8/site-packages/sentry_sdk/_compat.py", line 60, in reraise
raise value
File "/mnt/ssd/collision-avoidance/luxonis/.venv/lib/python3.8/site-packages/sentry_sdk/integrations/threading.py", line 67, in run
return old_run_func(self, *a, **kw)
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/mnt/ssd/collision-avoidance/luxonis/.venv/lib/python3.8/site-packages/depthai_sdk/record.py", line 27, in _run
recorder.write(name, frames[name])
File "/mnt/ssd/collision-avoidance/luxonis/.venv/lib/python3.8/site-packages/depthai_sdk/recorders/video_recorder.py", line 97, in write
self._writers[name].write(frame)
File "/mnt/ssd/collision-avoidance/luxonis/.venv/lib/python3.8/site-packages/depthai_sdk/recorders/video_writers/av_writer.py", line 157, in write
shape = self.get_dimension(frame)
File "/mnt/ssd/collision-avoidance/luxonis/.venv/lib/python3.8/site-packages/depthai_sdk/recorders/video_writers/av_writer.py", line 90, in get_dimension
frames = self._codec.decode(enc_packets[-1])
File "av/codec/context.pyx", line 492, in av.codec.context.CodecContext.decode
File "av/codec/context.pyx", line 507, in av.codec.context.CodecContext.decode
File "av/codec/context.pyx", line 404, in av.codec.context.CodecContext._send_packet_and_recv
File "av/error.pyx", line 328, in av.error.err_check
av.error.InvalidDataError: [Errno 1094995529] Invalid data found when processing input; last error log: [h264] no frame!
I suspect it's because the very first frame pair only has 1 valid frame. But I monkey-patched the function that throws an error, and now it works and both streams have exactly the same number of frames.
# .../depthai_sdk/recorders/video_writers/av_writer.py
def get_dimension(self, img: dai.ImgFrame) -> Optional[Tuple[int, int]]:
enc_packets = self._codec.parse(img.getData())
if len(enc_packets) == 0:
return None
try:
frames = self._codec.decode(enc_packets[-1]) # this throws the error
except:
return (1280, 800) # I hardcoded the size I'm using
if not frames:
return None
return frames[0].width, frames[0].height
This is not a robust solution though...