Open IvanViale opened 1 year ago
Hi, i was able to record a video with the code below, using pillow=True in the camera.capture(pillow=True) function, but the frame rate is very low, how can i increase it?
import numpy as np
from maix import camera
import av
duration = 4
fps = 24
total_frames = duration * fps
# Configura il codec video
output_options = {
'format': 'mp4',
'pix_fmt': 'yuv420p',
'framerate': fps,
'bit_rate': 4000000, # Bit rate desiderato
}
container = av.open("/root/test1.mp4", mode="w")
# mpeg4
stream = container.add_stream("mpeg4", rate=fps)
stream.width = 1280
stream.height = 720
stream.pix_fmt = "yuv420p"
#stream.bit_rate = output_options['bit_rate']
#stream.options = output_options
camera.config(size=(stream.width,stream.height))
for frame_i in range(total_frames):
print("Frame")
img = camera.capture(pillow=True)
numpydata = np.array(img)
frame = av.VideoFrame.from_ndarray(numpydata, format="rgb24")
for packet in stream.encode(frame):
container.mux(packet)
# Flush stream
for packet in stream.encode():
container.mux(packet)
# Close the file
container.close()
I made a separate test with this simple code to test the framerate
from maix import camera
import time
width= 1280
height= 720
camera.config(size=(width,height))
while True:
start_time = time.time()
img = camera.capture(pillow=True)
#display.show(img)
print("FPS: ", 1.0 / (time.time() - start_time)) # FPS = 1 / time to process loop
and i got this results
[ rpyc-kernel ]( running at Fri Aug 18 08:21:34 2023 )
[camera] config input size(1280, 720)
FPS: 3.564402746617717
FPS: 3.787287951175157
FPS: 3.662776522203864
FPS: 5.015190357757796
FPS: 3.5689461225198302
FPS: 3.0321921145585278
FPS: 5.142038203285811
FPS: 4.453786027763531
FPS: 3.0478183591223735
FPS: 5.204716416873277
FPS: 5.290154139932976
FPS: 3.3642953338825117
FPS: 4.831819035342067
FPS: 4.688321849975632
FPS: 3.6132780497638275
FPS: 4.106804424922599
FPS: 4.133455403012257
FPS: 4.367938282610326
FPS: 4.1519828389228595
FPS: 3.8195837374385873
Can I reach in python 30fps in 720p quality video, or i need to switch in C++? Thanks
Can anyone help me, please? I can pay
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 :