Power safety with saving mjpeg to SD Card

When writing frames to a mjpeg file with mjpeg.add_frame(), if the board loses power unexpectedly and doesn’t get the chance to call mjpeg.close() the file on the SD card ends up being corrupted. Looking at the library for mjpeg there isn’t a way periodically save to the file without entirely closing it. When I try to open the file again using the same name and write frames it ends up overwriting the previous file instead of appending frames on the end. Is there a way to add power down resilience to creating mjpeg files?


I need to add a flush method. I’ve been thinking about doing that for a while but it’s always been a low priority.

So, I have free time right now! Make a big ticket on your GitHub and I’ll get this fixed, like, ASAP.

Send me a link to where to make a bug and I’ll create it! Thank you so much!!

I created this bug ticket here: Create a Flush Function for mjpeg for power safety · Issue #1819 · openmv/openmv · GitHub Thank you for getting to this so quickly! You’re awesome!

Thanks, I’ll get to it this weekend.

I see the pull request was merged and the issue marked resolved on github! Thank you so much for getting on this so quickly! What do I need to do to get access to this new feature? Is there a nightly build or early release branch I can get on to start utilizing it? I notice the docs around mjpeg still haven’t updated to reflect the change from add_frame → write and the addition of sync function.

Again, thank you for being so active here on the forum and helpful in responding to feedback and adding features! You’re awesome!

Yeah, our firmware rebuilds when a new PR is merged: Releases · openmv/openmv · GitHub

Also, there’s a button under tools in the IDE which will install the latest firmware for your board.

Yeah, docs are going to take a while. That’s not automatic. At all.

So, the best would be to read the PR code and pull the names of the new stuff from looking at the C code.

Anyway, for now, once the firmware is installed just do .sync() every so often. Note that it does introduce a performance impact so I wouldn’t do it more than once a second.