Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4875

General discussion • Problem Using `start_recording` with Picamera2 on Raspberry Pi

$
0
0
Hello everyone,
I'm working on a project with my Raspberry Pi, and I've hit a snag when trying to record a video using the `picamera2` library. I would appreciate any help or guidance you can give me.

Description of the problem:
I am trying to record a video by specifying the encoder and output file destination. However, I have encountered several error messages when trying to use the `start_recording` method of the `picamera2` library. Below, I describe the steps I followed and the corresponding errors:
  • 1. Initially, I received an error stating that a required positional argument called `output` was missing when calling `start_recording`.
    2. After adjusting my code to include this argument, I ran into a new error saying that the `str` object does not have the `output` attribute, leading me to believe that there is a misunderstanding in how the encoder and the output to the method.
Here is the basic outline of the code I am using (excluding failed attempts and adjustments to resolve the mentioned errors):

Code:

from picamera2 import Picamera2, Previewfrom picamera2.outputs import FileOutputimport timedef main():     picam2 = Picamera2()     preview_config = picam2.create_preview_configuration()     picam2.configure(preview_config)     picam2.start_preview(Preview.QTGL)     picam2.start()         video_output = FileOutput("/home/pi/video.mp4")     print("Starting video recording.")     picam2.start_recording(output=video_output)     time.sleep(5) # Recording duration in seconds     picam2.stop_recording()     print("Recording finished.")     picam2.stop()if __name__ == '__main__':     main()
Errors Received:
  • TypeError: Picamera2.start_recording() missing 1 required positional argument: 'output'`
    After adjusting the code: `AttributeError: 'str' object has no attribute 'output'`
I'm a little confused on how to resolve these issues and ensure that the recording starts correctly with the proper parameters. Could someone guide me on the correct way to use `start_recording` with `picamera2` or point out what I'm doing wrong?

Any help or suggestions would be greatly appreciated. Thanks in advance!.

Statistics: Posted by Baladier — Tue Apr 09, 2024 12:15 am



Viewing all articles
Browse latest Browse all 4875

Trending Articles