ImageIO with compressed Images gives corrupted File

Hello

I’m having an issue when recording videos with compressed images:
When using an ImageIO object to record raw images (i.e. result from sensor.snapshot()) everything works fine, and I can play and convert the recorded video file afterwards.
But when recording compressed images, the recording itself goes on without any error messaged, but when I try to open or convert the file, I always get a “File is corrupt!” error from the IDE.
I don’t think this is an issue with the SD card, as the behaviour is consistent and the raw recording, with its higher data rate, is working flawlessly.
Also this used to work a while back ago (Sep/Oct perhaps), but I haven’t tried to get the exact firmware version where this stopped working for me.

Am I missing something here?

My actual script is a bit more complex and recording gray scale VGA pictures, but I can reproduce the very same behaviour with a slightly modified imageio_write.py example script (GRAYSCALE to suit my global shutter sensor, and reduced recording time):

import sensor, image, pyb, time

record_time = 2000 # 10 seconds in milliseconds

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

stream = image.ImageIO("/stream.bin", "w")

# Red LED on means we are capturing frames.
pyb.LED(1).on()

start = pyb.millis()
while pyb.elapsed_millis(start) < record_time:
    clock.tick()
    img = sensor.snapshot()
    # Modify the image if you feel like here...
    stream.write(img)
    print(clock.fps())

stream.close()

# Blue LED on means we are done.
pyb.LED(1).off()
pyb.LED(3).on()

The above works fine. If I replace the line stream.write(img) with stream.write(img.compress()) the recorded file gets corrupted.

HW: H7 or H7+
Firmware: 4.2.0 (but also happening with 4.1.4., possibly older ones as well, not checked)
IDE: 2.8.1
OS: Win 10

Thanks
Felix

Hi, no, that’s just broken right now. We updated the image format and then released before back porting the changes.

Can I ask you not to use that feature right now. I’ll try to get it fixed this week. Also, I need to do an IDE release too in-order to unbreak this.

This feature was intended for raw images, where each frame is the same size, it was never designed for JPEG images. If you want to save a JPEG stream that’s basically mjpeg or you could save individual frames. We may be able to update it to support JPEG, anyway just saying this isn’t a bug it’s how it’s intended to work.

It’s broken with respect to the IDE too.

Thanks!
I wasn’t aware I’m using a somewhat “unintended” feature.
But mjpeg is exactly what I need/want anyway, and it’s working just fine.

Regards
Felix

Hi, I’ve got a PR that makes it do everything you think coming soon. Then I’ll update the IDE to handle this.

It’s hard for us to keep all features super current as we change anything big. E.g. last year we updated the frame buffer system to hit the maximum possible performance. This is how we are actually able to hit the max camera FPS now. We also updated the image format info internally to support more image types. ImageIO was designed primarily to deal with previously deficiencies in the system. However, it’s not quite as useful as before but we will keep it around. Annoyingly, it exposes how our internal code is structured so anytime we change anything it can break.