Redis API quick start#
Redis-cli#
# List all keys
redis-cli KEYS '*'
# Read the current ISO value
redis-cli GET iso
# Start a recording (same as pressing the Rec button)
redis-cli SET is_recording 1
redis-cli PUBLISH cp_controls is_recording
You can also type:
redis-cli
This will open the redis cli.
cp_controls#
Both CinePi-raw and Cinemate writes values and immediately publish the key name. The recorder only reacts when it receives that publish event.
Any key may be sent this way. For example, to adjust the preview zoom:
# Set preview zoom level
redis-cli SET zoom 1.5
redis-cli PUBLISH cp_controls zoom
Note that for the is_recording key Cinemate stops recording upon edge detection (the variable changes from 0 to 1 or vice versa). The reason for this exception has to do with how the CinePi-raw fork handles recording with multiple cameras
# Start recording
redis-cli SET is_recording 1 # triggers 0 → 1 edge
# Stop recording
redis-cli SET is_recording 0 # triggers 1 → 0 edge
cp_stats#
Every frame, cinepi-raw sends a small JSON object containing live statistics.
Json::Value data;
Json::Value histo;
data["framerate"] = completed_request->framerate;
data["colorTemp"] = info.colorTemp;
data["focus"] = info.focus;
data["frameCount"] = app_->GetEncoder()->getFrameCount();
data["bufferSize"] = app_->GetEncoder()->bufferSize();
// per-camera timestamps in nanoseconds
data["timestamp"] = info.timestamp; // single sensor
data["timestamp_cam0"] = info.timestamp_cam0; // multi-sensor
data["timestamp_cam1"] = info.timestamp_cam1; // multi-sensor
redis_->publish(CHANNEL_STATS, data.toStyledString());
CineMate’s RedisListener
parses these messages and updates Redis keys like framecount
, BUFFER
and fps_actual
.
The timestamp fields are converted to SMPTE timecode based on fps_user
and
written to tc_cam0
and tc_cam1
. Values are only updated when the underlying
timestamp changes so Redis clients receive a new timecode once per frame.
Controlling the camera from your own script#
Below is a very small example using redis-py
.
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
# toggle recording
current = r.get('is_recording')
new_value = b'0' if current == b'1' else b'1'
r.set('is_recording', new_value)
r.publish('cp_controls', 'is_recording')
Note that in this example, the publishing of the is_recording key is not strictly needed for recording to start/stop, but for formality's sake I think we should keep the publish command.
Info
This is basically what Cinemate does: it keeps track of variables being set by cinepi-raw, and also sets variables itself.