Hi, i tryed to record a video with the sample in the website, but it doesn't work https://wiki.sipeed.com/soft/maixpy3/zh/usage/Audio/play_mp4.html.
I use chatgpt to create this code, but i receive the below error an i don't know how to solve it.
Can anyone share with me the right code to record a video? Thanks
import av
from maix import camera, image
import numpy as np
# Impostazioni per la registrazione video
output_filename = '/root/output_video.mp4'
frame_width = 640
frame_height = 480
fps = 24
# Configura la fotocamera
camera.config(size=(frame_width,frame_height))
# Configura il codec video
output_options = {
'format': 'mp4',
'pix_fmt': 'yuv420p',
'framerate': fps,
'bit_rate': 4000000, # Bit rate desiderato
}
# Apri il file video per la scrittura
output_container = av.open(output_filename, 'w')
# Aggiungi uno stream video al contenitore di output
output_stream = output_container.add_stream('h264', rate=fps)
output_stream.width = frame_width
output_stream.height = frame_height
output_stream.pix_fmt = 'yuv420p'
output_stream.bit_rate = output_options['bit_rate']
output_stream.options = output_options
try:
# Ciclo di cattura e scrittura dei frame
while True:
# Cattura l'immagine dalla fotocamera
img = camera.capture()
numpydata = np.asarray(img)
# Converte l'immagine in un formato compatibile con av.VideoFrame
frame = av.VideoFrame.from_ndarray(numpydata , format='rgb8')
# Scrivi il frame nel contenitore di output
for packet in output_stream.encode(frame):
output_container.mux(packet)
finally:
# Chiudi la fotocamera e il contenitore di output
camera.close()
for packet in output_stream.encode():
output_container.mux(packet)
output_container.close()
ERROR :
========= Remote Traceback (1) =========
Traceback (most recent call last):
File "<string>", line 40, in <module>
File "av/video/frame.pyx", line 414, in av.video.frame.VideoFrame.from_ndarray
File "av/utils.pyx", line 70, in av.utils.check_ndarray
ValueError: Expected numpy array with dtype `uint8` but got `object`
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/rpyc/core/protocol.py", line 324, in _dispatch_request
File "/usr/lib/python3.8/site-packages/rpyc/core/protocol.py", line 592, in _handle_call
File "<string>", line 49, in <module>
File "av/stream.pyx", line 153, in av.stream.Stream.encode
File "av/codec/context.pyx", line 482, in av.codec.context.CodecContext.encode
File "av/codec/context.pyx", line 285, in av.codec.context.CodecContext.open
File "/usr/lib/python3.8/_collections_abc.py", line 832, in update
TypeError: Argument 'value' has incorrect type (expected str, got int)
Hi, i tryed to record a video with the sample in the website, but it doesn't work https://wiki.sipeed.com/soft/maixpy3/zh/usage/Audio/play_mp4.html.
I use chatgpt to create this code, but i receive the below error an i don't know how to solve it.
Can anyone share with me the right code to record a video? Thanks
ERROR :