Video methods
Record a video
- Records a video for a specified
duration
, given in seconds. If no duration is specified, the video will record for 5 seconds. - Returns the
filename
of the video that was recorded.
Parameter | Data type | Default | Compulsory? | Description |
---|---|---|---|---|
filename | str or Path | None | Yes | A filename for a .mp4 video. This can also be a path to a file as either a string or a Path object. |
duration | int | 5 |
No | The length of time to record, in seconds. |
Example
A 10 second video called test_video.mp4
will be recorded and saved into the same folder as the Python script.
This method can also be called as take_video()
and will behave in exactly the same way.
Start recording
- Start recording a video. Use this method if you want to record for an unknown length of time.
Parameter | Data type | Default | Compulsory? | Description |
---|---|---|---|---|
filename | str or Path | None | Yes | A file name for a .mp4 video. This can also be a path to a file as either a string or a Path object. |
show_preview | bool | False |
No | Whether to show a preview. |
Example
This code will start recording a video called new_video.mp4
. The video will not finish recording until stop_recording()
is called.
Stop recording
- Stops a recording that is currently in progress.
Example
Record a video and take photos
- Record a video for a fixed
duration
, and while the video is running also take a photo at a specifiedstill_interval
.
Parameter | Data type | Default | Compulsory? | Description |
---|---|---|---|---|
filename | str or Path | None | Yes | A file name for a .mp4 video. This can also be a path to a file as either a string or a Path object. |
duration | int | 20 | No | The length of time to record, in seconds. |
still_interval | int | 4 | No | How frequently to take a photo, in seconds. If the duration is not exactly divisible by the interval specified, the method will ignore any remaining time. The first image will be taken after waiting for the specified interval. |
It may not be possible for the Raspberry Pi to capture images at the exact interval specified, particularly if the interval value is small.
Example
This will record a 16 second video called example.mp4
. It will also take a still image at 3, 6, 9, 12 and 15 seconds and save them as example-1.jpg
, example-2.jpg
etc.