saving video on SD card

I am trying to save a video from the camera feed onto the SD card. Here is the code:

import sensor, image, time, pyb, mjpeg

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

m = mjpeg.Mjpeg('openmv_video.mjpeg')

clock = time.clock()
time = [0]
start = pyb.millis()
while(True):
    clock.tick()
    time.append(pyb.elapsed_millis(start))
    m.add_frame(sensor.snapshot())
    print(clock.fps())
    if pyb.elapsed_millis(start) > 100000:
        print('over')
        print(time)
        m.close(clock.fps())
        break

I am having two problems when using this code. First, I get a very low frame rate, about 10 FPS. Secondly, the program will only run for like 10 seconds and stop receiving data. It eventually prints out the error message: “Timeout error while getting board architecture!”

How can I resolve this problem?

Hi:

  1. In regards to the frame rate, please keep in mind the camera has to jpeg compress images twice to send to the disk and display on the IDE. So, if you click the disable frame buffer option your FPS will go up to about 20 FPS. If you want to save the camera effort then do: sensor.snapshot().compress() to jpeg compress the frame buffer just once.

  2. “error message: “Timeout error while getting board architecture!”” → That would be an IDE issue… which should not be possible for you to run the script because the IDE would have not enabled control of the camera yet.

I’m getting some weird issues here however related to the new firmware. I keep getting a disk I/O error. I think it’s due to us upgrading the HAL to support the H7… man this stuff just keeps breaking… anyway, Ibrahim is debugging this.

Once other note - in your script you are endlessly appending time stamps to a list. You will run out of heap at some point and the system will fail.

I am still a little confused on what you mean by it’s an IDE error? What would I do to fix this error?

Okay, I got this working with no errors with the latest firmware for the M7:

import sensor, image, time, pyb, mjpeg

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

m = mjpeg.Mjpeg('openmv_video.mjpeg')

clock = time.clock()
#time = [0]
start = pyb.millis()
while(True):
    clock.tick()
    #time.append(pyb.elapsed_millis(start))
    m.add_frame(sensor.snapshot())
    print(clock.fps())
    if pyb.elapsed_millis(start) > 100000:
        print('over')
        #print(time)
        m.close(clock.fps())
        break

Um, I haven’t released the latest firmware with the IDE yet. But, It’s available on our github right now. Releases · openmv/openmv · GitHub

Use the Tools->Run bootloader option and pass the camera the OPENMV3/firmware.bin file. You are allowed to run this option before connecting… so, don’t hit that button.

As for saving the time stamps, please do that in another file.

Note that you may see time stamps not printed in the terminal when you print them all in one go. This is because the USB serial text fifo only holds about 512 bytes and we don’t block the camera when printing text, so, generally, text gets lost if you print too much at one time. The IDE polls the text buffer at 200 Hz so this is only an issue if you print out something very large.

so is it impossible to get the timestamps? because if I do it in another file (i assume you mean another python program), then it won’t be the timestamps for the same video…
Also, the program still did not work with the new firmware…

Hi, you can open two files at the same time. Just write the time stamps to the text file while also saving the video to a file. Then, close both at the same time.

ok like using tradition open() function in python? also, the code still doesn’t work… it sometimes abruptly stops in the middle, and openMV disconnects…

Yep, using the open method. Can you post your code?

Same code, but without the timestamps:

import sensor, image, time, pyb, mjpeg

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

m = mjpeg.Mjpeg('openmv_video.mjpeg')

clock = time.clock()
time = [0]
start = pyb.millis()
while(True):
    clock.tick()
    time.append(pyb.elapsed_millis(start))
    m.add_frame(sensor.snapshot())
    print(clock.fps())
    if pyb.elapsed_millis(start) > 10000:
        print('over')
        m.close(clock.fps())
        break

Hi, did you update your OpenMV Cam firmware? Also, please try formatting the disk. I’ve got it running without errors for the full 100 seconds.

Also, what OS are you on?

Don’t you mean 10 seconds?

Yes I am using the new firmware. I formatted and cleared out the SD card before using it with OpenMV but I don’t think that’s the problem because it’s the camera that keeps disconnecting from the IDE. I don’t think it’s due to the cable because I have tried several already. I am using Windows 10.

This works with the latest firmware:

import sensor, image, time, pyb, mjpeg

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

m = mjpeg.Mjpeg('openmv_video.mjpeg')

clock = time.clock()
start = pyb.millis()
with open("time_stamps.txt", "wb") as f:
    while(True):
        clock.tick()
        f.write("%d\n" % pyb.elapsed_millis(start))
        m.add_frame(sensor.snapshot())
        print(clock.fps())
        if pyb.elapsed_millis(start) > 10000:
            print('over')
            #print(time)
            m.close(clock.fps())
            break

There seems to be a problem with using a value of 100000 however. After about 20 seconds I get an EIO 5 error from the break line which doesn’t make sense.

Mmm, I can get it to run for 100 seconds on the H7 which records at about 27 FPS. On the M7 it only runs about 24 seconds before I get an EIO 5 error. I’ve asked Ibrahim to take a look.

As a matter of fact, even the example programs “mjpeg.py” and “gif.py” has the same problem… So there might be some other problem…

Hi, please verify that you’ve updated the firmware and reformated the SD card.

I did update the firmware (it says 2.8.0). I reformatted and it ran fine, then I tried to run again and the problem happened again. I reformatted again, and then the problem still happened. So yeah, the problem’s still there.

Is there a solution to this problem?

Hi, I’m fairly certain there’s a bug in this now with the M7. It seems to be fine on the H7. But, not the M7. I don’t know the plumbing of the HALs as well as Ibrahim however, so, I have to get him to fix it.

Sorry about this. We had all this stuff rather dialed in and bug free we we completed these features. But, trying to stay up to date with MicroPython has been a challenge. Every time we update our MP version stuff like this breaks. I’ve been able to keep the upper level vision code quite stable given this… but, lower level hardware drivers are a pain.

We’ll issue you a patch firmware soon.

No worries… Please let me know when the updated firmware is released.