Skip to content

Commit 227e992

Browse files
Merge pull request #4049 from raspberrypi/develop
roll out latest changes to production
2 parents ae362f7 + ecd49eb commit 227e992

14 files changed

+296
-59
lines changed

Diff for: CONTRIBUTING.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ Use the `gem` package manager to install the [Ruby bundler](https://bundler.io/)
8888
$ gem install bundler
8989
```
9090

91+
And then install the required Ruby gems:
92+
93+
```console
94+
$ bundle install
95+
```
96+
9197
Configure a Python virtual environment for this project:
9298

9399
```console
@@ -101,12 +107,12 @@ $ source .env/bin/activate
101107
```
102108

103109
> [!TIP]
104-
> When you're using a virtual environment, you should see a `(.venv)` prefix at the start of your terminal prompt. At any time, run the `deactivate` command to exit the virtual environment.
110+
> When you're using a virtual environment, you should see a `(.env)` prefix at the start of your terminal prompt. At any time, run the `deactivate` command to exit the virtual environment.
105111
106-
In the virtual environment, install the [YAML module for Python 3](https://formulae.brew.sh/formula/pyyaml#default):
112+
In the virtual environment, install the required Python modules:
107113

108114
```console
109-
$ pip3 install pyyaml
115+
$ pip3 install -r requirements.txt
110116
```
111117

112118
### Build HTML

Diff for: Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ GEM
6868
jekyll (>= 3.5, < 5.0)
6969
jekyll-feed (~> 0.9)
7070
jekyll-seo-tag (~> 2.1)
71-
nokogiri (1.18.2)
71+
nokogiri (1.18.3)
7272
mini_portile2 (~> 2.8.2)
7373
racc (~> 1.4)
7474
pathutil (0.16.2)

Diff for: documentation/asciidoc/computers/camera/camera_usage.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ Raspberry Pi produces several official camera modules, including:
1212
For more information about camera hardware, see the xref:../accessories/camera.adoc#about-the-camera-modules[camera hardware documentation].
1313

1414
First, xref:../accessories/camera.adoc#install-a-raspberry-pi-camera[install your camera module]. Then, follow the guides in this section to put your camera module to use.
15+
16+
[WARNING]
17+
====
18+
This guide no longer covers the _legacy camera stack_ which was available in Bullseye and earlier Raspberry Pi OS releases. The legacy camera stack, using applications like `raspivid`, `raspistill` and the original `Picamera` (_not_ `Picamera2`) Python library, has been deprecated for many years, and is now unsupported. If you are using the legacy camera stack, it will only have support for the Camera Module 1, Camera Module 2 and the High Quality Camera, and will never support any newer camera modules. Nothing in this document is applicable to the legacy camera stack.
19+
====

Diff for: documentation/asciidoc/computers/camera/rpicam_apps_multicam.adoc

+58-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,61 @@
88
99
To list all the cameras available on your platform, use the xref:camera_software.adoc#list-cameras[`list-cameras`] option. To choose which camera to use, pass the camera index to the xref:camera_software.adoc#camera[`camera`] option.
1010

11-
NOTE: `libcamera` does not yet provide stereoscopic camera support. When running two cameras simultaneously, they must be run in separate processes. This means there is no way to synchronise sensor framing or 3A operation between them. As a workaround, you could synchronise the cameras through an external sync signal for the HQ (IMX477) camera, and switch the 3A to manual mode if necessary.
11+
NOTE: `libcamera` does not yet provide stereoscopic camera support. When running two cameras simultaneously, they must be run in separate processes, meaning there is no way to synchronise 3A operation between them. As a workaround, you could synchronise the cameras through an external sync signal for the HQ (IMX477) camera or use the software camera synchronisation support that is described below, switching the 3A to manual mode if necessary.
12+
13+
==== Software Camera Synchronisation
14+
15+
Raspberry Pi's _libcamera_ implementation has the ability to synchronise the frames of different cameras using only software. This will cause one camera to adjust it's frame timing so as to coincide as closely as possible with the frames of another camera. No soldering or hardware connections are required, and it will work with all of Raspberry Pi's camera modules, and even third party ones so long as their drivers implement frame duration control correctly.
16+
17+
**How it works**
18+
19+
The scheme works by designating one camera to be the _server_. The server will broadcast timing messages onto the network at regular intervals, such as once a second. Meanwhile other cameras, known as _clients_, can listen to these messages whereupon they may lengthen or shorten frame times slightly so as to pull them into sync with the server. This process is continual, though after the first adjustment, subsequent adjustments are normally small.
20+
21+
The client cameras may be attached to the same Raspberry Pi device as the server, or they may be attached to different Raspberry Pis on the same network. The camera model on the clients may match the server, or they may be different.
22+
23+
Clients and servers need to be set running at the same nominal framerate (such as 30fps). Note that there is no back-channel from the clients back to the server. It is solely the clients' responsibility to be up and running in time to match the server, and the server is completely unaware whether clients have synchronised successfully, or indeed whether there are any clients at all.
24+
25+
In normal operation, running the same make of camera on the same Raspberry Pi, we would expect the frame start times of the camera images to match within "several tens of microseconds". When the camera models are different this could be significantly larger as the cameras will probably not be able to match framerates exactly and will therefore be continually drifting apart (and brought back together with every timing message).
26+
27+
When cameras are on different devices, the system clocks should be synchronised using NTP (normally the case by default for Raspberry Pi OS), or if this is insufficiently precise, another protocol like PTP might be used. Any discrepancy between system clocks will feed directly into extra error in frame start times - even though the advertised timestamps on the frames will not tell you.
28+
29+
**The Server**
30+
31+
The server, as previously explained, broadcasts timing messages onto the network, by default every second. The server will run for a fixed number of frames, by default 100, after which it will inform the camera application on the device that the "synchronisation point" has been reached. At this moment, the application will start using the frames, so in the case of `rpicam-vid`, they will start being encoded and recorded. Recall that the behaviour and even existence of clients has no bearing on this.
32+
33+
If required, there can be several servers on the same network so long as they are broadcasting timing messages to different network addresses. Clients, of course, will have to be configured to listen for the correct address.
34+
35+
**Clients**
36+
37+
Clients listen out for server timing messages and, when they receive one, will shorten or lengthen a camera frame duration by the required amount so that subsequent frames will start, as far as possible, at the same moment as the server's.
38+
39+
The clients learn the correct "synchronisation point" from the server's messages, and just like the server, will signal the camera application at the same moment that it should start using the frames. So in the case of `rpicam-vid`, this is once again the moment at which frames will start being recorded.
40+
41+
Normally it makes sense to start clients _before_ the server, as the clients will simply wait (the "synchronisation point" has not been reached) until a server is seen broadcasting onto the network. This obviously avoids timing problems where a server might reach its "synchronisation point" even before all the clients have been started!
42+
43+
**Usage in `rpicam-vid`**
44+
45+
We can use software camera synchronisation with `rpicam-vid` to record videos that are synchronised frame-by-frame. We're going to assume we have two cameras attached, and we're going to use camera 0 as the server, and camera 1 as the client. `rpicam-vid` defaults to a fixed 30 frames per second, which will be fine for us.
46+
47+
First we should start the client:
48+
[source,console]
49+
----
50+
$ rpicam-vid -n -t 20s --camera 1 --codec libav -o client.mp4 --sync client
51+
----
52+
53+
Note the `--sync client` parameter. This will record for 20 seconds but _only_ once the synchronisation point has been reached. If necessary, it will wait indefinitely for the first server message.
54+
55+
To start the server:
56+
[source,console]
57+
----
58+
$ rpicam-vid -n -t 20s --camera 0 --codec libav -o server.mp4 --sync server
59+
----
60+
61+
This too will run for 20 seconds counting from when the synchronisation point is reached and the recording starts. With the default synchronisation settings (100 frames at 30fps) this means there will be just over 3 seconds for clients to get synchronised.
62+
63+
The server's broadcast address and port, the frequency of the timing messages and the number of frames to wait for clients to synchronise, can all be changed in the camera tuning file. Clients only pay attention to the broadcast address here which should match the server's; the other information will be ignored. Please refer to the https://datasheets.raspberrypi.com/camera/raspberry-pi-camera-guide.pdf[Raspberry Pi Camera tuning guide] for more information.
64+
65+
In practical operation there are a few final points to be aware of:
66+
67+
* The fixed framerate needs to be below the maximum framerate at which the camera can operate (in the camera mode that is being used). This is because the synchronisation algorithm may need to _shorten_ camera frames so that clients can catch up with the server, and this will fail if it is already running as fast as it can.
68+
* Whilst camera frames should be correctly synchronised, at higher framerates or depending on system load, it is possible for frames, either on the clients or server, to be dropped. In these cases the frame timestamps will help an application to work out what has happened, though it's usually simpler to try and avoid frame drops - perhaps by lowering the framerate, increasing the number of buffers being allocated to the camera queues (see the xref:camera_software.adoc#buffer-count[`--buffer-count` option]), or reducing system load.

Diff for: documentation/asciidoc/computers/camera/rpicam_configuration.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Raspberry Pi OS recognises the following overlays in `/boot/firmware/config.txt`
3838

3939
To use one of these overlays, you must disable automatic camera detection. To disable automatic detection, set `camera_auto_detect=0` in `/boot/firmware/config.txt`. If `config.txt` already contains a line assigning an `camera_auto_detect` value, change the value to `0`. Reboot your Raspberry Pi with `sudo reboot` to load your changes.
4040

41+
If your Raspberry Pi has two camera connectors (Raspberry Pi 5 or one of the Compute Modules, for example), then you can specify which one you are referring to by adding `,cam0` or `,cam1` (don't add any spaces) to the `dtoverlay` that you used from the table above. If you do not add either of these, it will default to checking camera connector 1 (`cam1`). But note that for official Raspberry Pi camera modules, auto-detection will correctly identify all the cameras connected to your device.
42+
4143
[[tuning-files]]
4244
==== Tweak camera behaviour with tuning files
4345

Diff for: documentation/asciidoc/computers/camera/rpicam_options_common.adoc

+20-2
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,19 @@ Alias: `-t`
8989
9090
Default value: 5000 milliseconds (5 seconds)
9191
92-
Specify how long the application runs before closing. This applies to both video recording and preview windows. When capturing a still image, the application shows a preview window for `timeout` milliseconds before capturing the output image.
92+
Specify how long the application runs before closing. This value is interpreted as a number of milliseconds unless an optional suffix is used to change the unit. The suffix may be one of:
9393
94-
To run the application indefinitely, specify a value of `0`.
94+
* `min` - minutes
95+
* `s` or `sec` - seconds
96+
* `ms` - milliseconds (the default if no suffix used)
97+
* `us` - microseconds
98+
* `ns` - nanoseconds.
99+
100+
This time applies to both video recording and preview windows. When capturing a still image, the application shows a preview window for the length of time specified by the `timeout` parameter before capturing the output image.
101+
102+
To run the application indefinitely, specify a value of `0`. Floating point values are also permitted.
103+
104+
Example: `rpicam-hello -t 0.5min` would run for 30 seconds.
95105
96106
==== `preview`
97107
@@ -553,3 +563,11 @@ Flushes output files to disk as soon as a frame finishes writing, instead of wai
553563
Specifies a JSON file that configures the post-processing applied by the imaging pipeline. This applies to camera images _before_ they reach the application. This works similarly to the legacy `raspicam` "image effects". Accepts a file name path as input.
554564
555565
Post-processing is a large topic and admits the use of third-party software like OpenCV and TensorFlowLite to analyse and manipulate images. For more information, see xref:camera_software.adoc#post-processing-with-rpicam-apps[post-processing].
566+
567+
==== `buffer-count`
568+
569+
The number of buffers to allocate for still image capture or for video recording. The default value of zero lets each application choose a reasonable number for its own use case (1 for still image capture, and 6 for video recording). Increasing the number can sometimes help to reduce the number of frame drops, particularly at higher framerates.
570+
571+
==== `viewfinder-buffer-count`
572+
573+
As the `buffer-count` option, but applies when running in preview mode (that is `rpicam-hello` or the preview, not capture, phase of `rpicam-still`).

Diff for: documentation/asciidoc/computers/camera/rpicam_options_vid.adoc

+7
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,10 @@ Records exactly the specified number of frames. Any non-zero value overrides xre
132132

133133
Records exactly the specified framerate. Accepts a nonzero integer.
134134

135+
==== `low-latency`
136+
137+
On a Pi 5, the `--low-latency` option will reduce the encoding latency, which may be beneficial for real-time streaming applications, in return for (slightly) less good coding efficiency (for example, B frames and arithmethic coding will no longer be used).
138+
139+
==== `sync`
140+
141+
Run the camera in software synchronisation mode, where multiple cameras synchronise frames to the same moment in time. The `sync` mode can be set to either `client` or `server`. For more information, please refer to the detailed explanation of xref:camera_software.adoc#software-camera-synchronisation[how software synchronisation works].

Diff for: documentation/asciidoc/computers/camera/rpicam_vid.adoc

+22-2
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,32 @@ For example, the following command writes a ten-second video to a file named `te
1111
$ rpicam-vid -t 10s -o test.h264
1212
----
1313

14-
You can play the resulting file with VLC and other video players:
14+
You can play the resulting file with ffplay and other video players:
1515

1616
[source,console]
1717
----
18-
$ vlc test.h264
18+
$ ffplay test.h264
1919
----
2020

21+
[WARNING]
22+
====
23+
Older versions of vlc were able to play H.264 files correctly, but recent versions do not - displaying only a few, or possibly garbled, frames. You should either use a different media player, or save your files in a more widely supported container format - such as MP4 (see below).
24+
====
25+
2126
On Raspberry Pi 5, you can output to the MP4 container format directly by specifying the `mp4` file extension for your output file:
2227

2328
[source,console]
2429
----
2530
$ rpicam-vid -t 10s -o test.mp4
2631
----
2732

33+
On Raspberry Pi 4, or earlier devices, you can save MP4 files using:
34+
35+
[source,console]
36+
----
37+
$ rpicam-vid -t 10s --codec libav -o test.mp4
38+
----
39+
2840
==== Encoders
2941

3042
`rpicam-vid` supports motion JPEG as well as both uncompressed and unformatted YUV420:
@@ -76,3 +88,11 @@ To enable the `libav` backend, pass `libav` to the xref:camera_software.adoc#cod
7688
----
7789
$ rpicam-vid --codec libav --libav-format avi --libav-audio --output example.avi
7890
----
91+
92+
==== Low latency video with the Pi 5
93+
94+
Pi 5 uses software video encoders. These generally output frames with a longer latency than the old hardware encoders, and this can sometimes be an issue for real-time streaming applications.
95+
96+
In this case, please add the option `--low-latency` to the `rpicam-vid` command. This will alter certain encoder options to output the encoded frame more quickly.
97+
98+
The downside is that coding efficiency is (slightly) less good, and that the processor's multiple cores may be used (slightly) less efficiently. The maximum framerate that can be encoded may be slightly reduced (though it will still easily achieve 1080p30).

0 commit comments

Comments
 (0)