-
Notifications
You must be signed in to change notification settings - Fork 11
Controlling cinepi‐raw using redis‐cli
When a cinepi-raw instance is started, a connection to the local redis-server is instantiated. This connection serves 2 main purposes:
-
Using redis as store for camera controls and other stateful parameters.
-
To provide bidirectional real-time control, statistics and per frame info to custom user applications via redis pub/sub model.
Listed below are the various channels and keys that perform specific functions within cinepi-raw. These are reserved for cinepi-raw and should be carefully avoided in uses outside of cinepi context.
cp_controls
cp_stats
iso
width
height
fps
is_recording
shutter_a
shutter_s
log_level
cg_rb
ucm
awb
thumbnail
thumbnail_size
For testing users can use the built in redis-cli
to test camera controls, for example:
pi@cinepi:~ $ redis-cli
127.0.0.1:6379> subscribe cp_stats
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "cp_stats"
3) (integer) 1
1) "message"
2) "cp_stats"
3) "{\n\t\"bufferSize\" : 0,\n\t\"colorTemp\" : 3333,\n\t\"focus\" : 22.0,\n\t\"frameCount\" : 0,\n\t\"framerate\" : 30.012004852294922\n}\n"
1) "message"
2) "cp_stats"
3) "{\n\t\"bufferSize\" : 0,\n\t\"colorTemp\" : 3333,\n\t\"focus\" : 22.0,\n\t\"frameCount\" : 0,\n\t\"framerate\" : 30.009302139282227\n}\n"
1) "message"
2) "cp_stats"
3) "{\n\t\"bufferSize\" : 0,\n\t\"colorTemp\" : 3333,\n\t\"focus\" : 22.0,\n\t\"frameCount\" : 0,\n\t\"framerate\" : 30.007501602172852\n}\n"
...
This example shows how to subscribe the statistics channel to retrieve per frame metadata and other stats.
Cameras controls follow a 2-step process for updating in real-time application.
- Setting the key value, as shown below
pi@cinepi:~ $ redis-cli
127.0.0.1:6379> set ***KEY_GOES_HERE***
Examples:
set iso 100
set fps 24
set shutter_a 180
set is_recording 1
Once the key value is set, the application must now indicate to cinepi-raw to read/update the specific key value within the running camera instance.
- Publish the key name to the
cp_controls
channel, as shown below
pi@cinepi:~ $ redis-cli
127.0.0.1:6379> publish cp_controls ***KEY_GOES_HERE***
Examples:
publish cp_controls iso
publish cp_controls fps
publish cp_controls shutter_a
publish cp_controls is_recording
Used in conjunction this is how you would for example change the iso
to 400
:
pi@cinepi:~ $ redis-cli
127.0.0.1:6379> set iso 400
OK
127.0.0.1:6379> publish cp_controls iso
(integer) 1
127.0.0.1:6379>
In the same way a setting a camera control, you can also read the current value of a camera parameter using a get
command:
pi@cinepi:~ $ redis-cli
127.0.0.1:6379> get iso
"400"
⚠ KEY TAKEAWAYS ⚠
- You MUST set the key/value first
- You MUST publish the key name to the cp_controls channel. ( without this the application will not update the camera setting during operation. )
Redis has a number of different client integrations through a number of different languages / frameworks, making it very versatile for using in your own control applications. For example, you can use the redis-py
python client to achieve the same level of controls as shown in the previous section.