我想通过树莓派pi 3模型b +使用picamera V2,它具有90 FPS的分辨率和1280x720的python脚本格式。根据{{3}},picamera V2应该可以在这些设置下运行,但不能在我的python脚本中运行。我该如何解决这个问题?是否有任何命令可以将python中的H.264级别提高到4.2?
如果我通过控制台使用命令raspivid -o video.h264 -md 6 -fps 90 -w 1280 -h 720
,我收到的消息是Too many macroblocks/s: Increasing H264 Level to 4.2
,但它确实以(接近)90 FPS录制了视频
如果我想使用相机运行以下代码,则会出现错误。通过camera.framerate = 60
使用相同的脚本可以很好地工作。
import picamera
import subprocess
camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.sensor_mode = 6
camera.framerate = 90
camera.start_recording('video.h264')
camera.wait_recording(10)
camera.stop_recording()
camera.close()
错误消息:
Traceback (most recent call last):
File "/home/pi/GEA/video.py", line 8, in <module>
camera.start_recording('video.h264')
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1046, in start_recording
camera_port, output_port, format, resize, **options)
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 723, in _get_video_encoder
self, camera_port, output_port, format, resize, **options)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 601, in __init__
parent, camera_port, input_port, format, resize, **options)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 187, in __init__
self._create_encoder(format, **options)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 736, in _create_encoder
'level' % macroblocks_per_s_limit)
picamera.exc.PiCameraValueError: output resolution and framerate exceeds macroblocks/s limit (245760) for the selected H.264 profile and level
```
答案 0 :(得分:0)
请参阅PiCamera API文档https://picamera.readthedocs.io/en/release-1.13/api_camera.html#picamera
从1.11版开始,它支持格式h264的附加级别选项。 下面的行对我有用:
camera.start_recording(video_file, format='h264', level='4.2')