logo

录制MJPEG时,结束录制时主程序就必须停止吗?否则会报错?

2020-10-30 13:28
D
m1bo
# MJPEG Video Recording Example
#
# Note: You will need an SD card to run this demo.
#
# You can use your OpenMV Cam to record mjpeg files. You can either feed the
# recorder object JPEG frames or RGB565/Grayscale frames. Once you've finished
# recording a Mjpeg file you can use VLC to play it. If you are on Ubuntu then
# the built-in video player will work too.

import sensor, image, time, mjpeg, pyb

RED_LED_PIN = 1
BLUE_LED_PIN = 3

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.

pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.

pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()

m = mjpeg.Mjpeg("example.mjpeg")

print("You're on camera!")
while(True):
    for i in range(20):
        clock.tick()
        m.add_frame(sensor.snapshot())
        print(clock.fps())
    
    m.close(clock.fps())
    pyb.LED(BLUE_LED_PIN).off()
    print("Done! Reset the camera to see the saved recording.")
I
网红小智智 星瞳科技

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/omv.mjpeg.html#mjpeg.mjpeg.close

close是结束。

你说的是什么报错?

D
m1bo
eadb745e-9d16-4afe-b555-cc4fd4f9b561.png
D
m1bo

@kidswong999 OSError: The file/directory object is invalid

D
m1bo

@kidswong999是这样的报错 OSError: The file/directory object is invalid

2020-10-31 11:36
I
网红小智智 星瞳科技

你是不是没有插SD卡?

2020-11-03 11:15
D
m1bo

@kidswong999 插了SD卡

2020-11-05 13:35
I
网红小智智 星瞳科技

你的代码不对。

死循环里面,31行循环20次后,会close。然后下一次add_frame就会失败。因为close了,就不能add了。

正确的程序:

https://book.openmv.cc/example/06-Video-Recording/mjpeg.html