简体   繁体   English

如何在python中使用picamera V2以90 FPS录制视频

[英]How to record a video with 90 FPS with picamera V2 in python

I want to use the picamera V2 via a raspberry pi 3 model b+ with 90 FPS and a resolution of 1280x720 in a python script.我想在 python 脚本中通过具有 90 FPS 和 1280x720 分辨率的树莓派 3 型号 b+ 使用 picamera V2。 According to https://picamera.readthedocs.io/en/release-1.13/fov.html the picamera V2 should be able to run with these settings but it doesn't in my python script.根据https://picamera.readthedocs.io/en/release-1.13/fov.html,picamera V2 应该能够使用这些设置运行,但它不在我的 python 脚本中。 How do I solve the issue?我该如何解决这个问题? Is there any command to increase the H.264 level to 4.2 in python?是否有任何命令可以在 python 中将 H.264 级别提高到 4.2?

If I use the command raspivid -o video.h264 -md 6 -fps 90 -w 1280 -h 720 via console I'm receiving the message Too many macroblocks/s: Increasing H264 Level to 4.2 but it does record a video with (close to) 90 FPS如果我通过控制台使用命令raspivid -o video.h264 -md 6 -fps 90 -w 1280 -h 720我会收到消息Too many macroblocks/s: Increasing H264 Level to 4.2 but it does Record a video with (接近)90 FPS

If i run the following code as I'd like to use the camera I'm getting an error.如果我想使用相机而运行以下代码,则会出现错误。 Using the same script using camera.framerate = 60 works completely fine.使用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()

Error Message:错误信息:

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
```

Please refer to PiCamera API documentation https://picamera.readthedocs.io/en/release-1.13/api_camera.html#picamera请参阅 PiCamera API 文档https://picamera.readthedocs.io/en/release-1.13/api_camera.html#picamera

Starting from release 1.11 it supports additional level option for format h264.从 1.11 版开始,它支持 h264 格式的附加级别选项。 Below line worked for me:下面这行对我有用:

camera.start_recording(video_file, format='h264', level='4.2')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM