I’m working on an OpenMV N6 motion detection project. I maintain a circular RAM buffer containing the last 10 seconds of frames.
For testing purposes, I save the contents of the buffer to an MJPEG file after the buffer fills up. The problem is that when I write all buffered frames in a tight loop, the resulting MJPEG video plays back almost instantly (duration close to 0 seconds), even though the buffer represents about 10 seconds of real time.
The buffer contains 50 frames captured at 5 FPS (approximately 10 seconds of video).
Example:
video = mjpeg.Mjpeg(filename)
for frame in frame_buffer:
if frame is not None:
video.write(frame)
video.close()
The only method that currently produces the expected duration is:
for frame in frame_buffer:
if frame is not None:
video.write(frame)
time.sleep_ms(1000 // self._buf_fps) # 5 FPS
This suggests that playback timing may depend on the actual time between write() calls.
My question:
Is there a supported way to save a pre-recorded frame buffer to MJPEG while preserving the original timing/FPS, without introducing artificial delays during the save process?
HI, at the moment no, however, the mjpeg format is a pretty standard container. There are specific file offsets you can modify in the file to fix the timing of the data written.
You can also just not use the MJPEG class at all. You can do everything the class does in Python. It doesn’t really need to be in C anymore: