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 opens the Redis CLI.

cp_controls#

Both CinePi-raw and Cinemate write values and then publish the key name on the cp_controls channel. The supported control path is therefore:

  1. SET <key> <value>
  2. PUBLISH cp_controls <key>

Any controllable key may be sent this way. For example, to adjust preview zoom:

redis-cli SET zoom 1.5
redis-cli PUBLISH cp_controls zoom

Recording uses two related keys:

  • is_recording is the requested record state. This is the key you write from scripts, and it is edge-triggered: 0 -> 1 starts a take and 1 -> 0 stops it.
  • rec is a derived runtime state generated by Cinemate from live framecount movement. It flips to 1 when frames actually start increasing and back to 0 when they stop rising or reset to zero. Use rec for "is the recorder really active right now?" indicators.

During a storage warm-up, Cinemate also raises storage_preroll_active=1 so other components can ignore the temporary clip.

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 keys such as:

  • framecount, buffer, buffer_size, and fps_actual
  • tc_cam0 and tc_cam1, derived from the nanosecond timestamps
  • drop-frame keys such as drop_frame, drop_frame_count, and drop_frame_during_last_take
  • frames_in_sync, which flips to 0 during a real take as soon as live frame-slot sync drifts outside the configured live tolerance (default +/- 2 frames), and fps_correction_suggestion after the take finishes and buffered frames have flushed. The final analysis uses the configured final tolerance (default +/- 1 frame). Storage pre-roll clips are excluded from this analysis.

Separately, the Redis controller starts a recording timer whenever rec=1. That timer updates:

  • recording_time as elapsed seconds
  • recording_tc_rec as elapsed record timecode
  • recording_time_tod as time-of-day timecode

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')

Info

This is basically what Cinemate does: it keeps track of values coming from CinePi-raw, adds higher-level state of its own, and republishes control changes through Redis.