This pipeline sends a fleet's dashcam recordings through the triage a safety manager would do. Gemini reviews each drive for the events that need attention, and a filter ends the run when there are none. A manager reviews the events; approved ones are tracked frame by frame and rendered as coaching clips, with readable number plates and other road users' faces blurred.
The example ran on two recordings: a highway drive with no events and a city drive with one. See the coaching clip beside the other examples in the pipeline examples.
The highway drive had no safety events, so its run ended at the filter without a clip. The city drive had one.
events and overlay steps are llm steps. Editframe enables pipelines, and llm steps, for an organization after you tell us about your footage.What it produces
- For a drive without events, a run that ends
filteredathas_events, and theeventsstep's summary of why the drive is uneventful. Nothing after the filter runs. - For a drive with events, a 1920×1080 coaching clip of each approved event, as a file in your organization, with playback URLs from
publish. - The
eventsstep's answer: each event's kind, label, severity, confidence, a neutral account, coaching points, its span and the window of its clip. - The
overlaystep's answer: the tracks that follow each event's subject, and a box on every frame for each readable plate and identifiable face to blur.
The recordings carry no telemetry, so speed, distance and braking force are reported only when the footage itself shows them.
The pipeline
This is the example's pipeline.json, step by step. A step starts when the steps in its needs have finished; detect waits for the review, so frames are analyzed only for approved events. The long instructions and output.schema of each llm step are shown below it.
probe
Reads the recording's duration, frame size and tracks.
{ "probe": { "type": "probe" } }frames
Takes four frames a second.
{
"frames": { "type": "sample_frames", "needs": ["probe"], "with": { "every_ms": 250 } }
}events
Gemini reviews the drive for safety events, with times, severity, a neutral account and coaching points.
{
"events": {
"type": "llm",
"needs": ["probe", "frames"],
"with": {
"provider": "google",
"model": "gemini-4-carbon",
"attach_video": true,
"max_frames": 32,
"max_input_tokens": 300000,
"include": ["probe"],
"instructions": "…",
"output": { "mode": "json", "schema": "…" }
}
}
}Instructions of events
You review dashcam recordings for a commercial fleet's safety team, as the event review queue of
a video telematics product does. The vehicle carrying the camera is the fleet vehicle; its
driver is the one coached. The camera may be a windshield dashcam or a camera inside the cab.
There is no telemetry: speed, distance and braking force are unknown unless the footage shows
them. Watch the whole video. The sampled frames carry their t_ms; use them to time events to
within half a second.
Report only events a fleet safety manager must review:
- safety.near_miss: the fleet vehicle and another road user nearly collided: one of them braked
or steered hard to avoid contact, or the gap closed to about a car length or less at speed.
- safety.cut_in: another vehicle moved into the fleet vehicle's lane ahead of it and left a
short gap, roughly within two seconds of travel (at highway speed, about four car lengths or
less) when it crossed the lane line. A merge that leaves a long gap is not an event.
- safety.following_distance: the fleet vehicle stayed clearly closer than two seconds behind the
vehicle ahead for several seconds while moving. Stopped or crawling traffic is not an event.
- safety.hard_braking: the fleet vehicle braked abruptly: the view pitches down, the scene
decelerates sharply or the vehicle ahead looms quickly. Report it only when unmistakable.
- safety.vulnerable_road_user: a pedestrian, cyclist or motorcyclist was in the fleet vehicle's
path, crossed in front of it, or passed or rode within about a metre of it, including a
motorcycle or bicycle filtering between the fleet vehicle and a barrier, kerb or another
vehicle.
- safety.lane_departure: the fleet vehicle drifted across a lane line or onto the shoulder
without completing a deliberate lane change.
- safety.intersection: the fleet vehicle entered an intersection on red, rolled through a stop
sign, or conflicted with crossing or turning traffic.
- safety.distraction: in-cab footage shows the driver using a phone, looking away from the road
for more than about two seconds, or similar.
- safety.other: another clearly unsafe situation, such as debris in the lane or a wrong-way
vehicle.
Not events: cars, vans, buses and trucks overtaking or passing in other lanes, however large or
close, while they stay in their lane; lane changes and merges, by anyone, that leave an ample
gap; steady following at a normal distance; stopping or waiting in a queue or at a light; normal
turns; road works, signs and scenery. When nothing qualifies, return an empty events list: that
is the expected answer for most recordings, and an uneventful recording is discarded. Never add
an event to fill the list. Report each real event once, and at most four.
For each event:
- kind: one of the kinds above.
- label: a short title of at most 40 characters in sentence case.
- severity: high for a collision, near miss or hard evasive action; medium when paths converged
and the safety margin was lost without evasive action, such as a short-gap cut-in, close
following, a lane departure, or a vulnerable road user entering the fleet vehicle's path; low
when a road user passed close without converging on the fleet vehicle's path and nobody had to
react, or for another minor loss of margin worth a coaching conversation.
- start_ms and end_ms: the event itself, from the frame where the situation begins (for a
cut-in, when the other vehicle's wheels cross the lane line) to the frame where it is resolved
(a safe gap is restored or the hazard has passed).
- clip_start_ms and duration_ms: a coaching clip of 10000 to 20000 ms that starts about 4000 ms
before start_ms (0 when the event starts earlier than that) and ends about 3000 ms after
end_ms, within the video: clip_start_ms + duration_ms must not exceed the input duration. When
the recording is shorter than 10000 ms, use clip_start_ms 0 and a duration_ms about 3000 ms
longer than the recording, and at least 10000: the clip then ends on its last frame held
behind a coaching end card.
- text: the narrative, one or two sentences of at most 240 characters, in the past tense,
neutral and factual, describing what is visible from the fleet vehicle. Describe the fleet
vehicle's own lane position or lane change only when the lane markings clearly show it. Do not
blame, guess intent, or state speeds, distances in metres or time gaps; describe a distance in
car lengths only when you can see it. Never read out number plates, and do not name vehicle
brands or describe people's appearance.
- coaching: one or two points of at most 90 characters each, addressed to the fleet vehicle's
driver as an action for next time, specific to this event and consistent with the narrative.
When the driver handled it well, the first point may say so.
- subject: the other road user involved, such as "white van" or "cyclist", or "" when there is
none.
- visible_speed: a speed shown in the footage by a speedometer or an on-screen overlay, exactly
as shown (such as "62 km/h"), or "" when none is visible. Never estimate a speed.
- confidence: from 0 to 1, how sure you are that the event happened as described.
- name: a lowercase slug such as event-1-cut-in.
summary: one or two sentences on the recording (road, light, traffic) and why it has or has no
events.Output schema of events
{
"type": "object",
"properties": {
"summary": { "type": "string" },
"events": {
"type": "array",
"minItems": 0,
"maxItems": 4,
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"kind": {
"type": "string",
"enum": [
"safety.near_miss",
"safety.cut_in",
"safety.following_distance",
"safety.hard_braking",
"safety.vulnerable_road_user",
"safety.lane_departure",
"safety.intersection",
"safety.distraction",
"safety.other"
]
},
"label": { "type": "string" },
"severity": { "type": "string", "enum": ["low", "medium", "high"] },
"start_ms": { "type": "integer", "minimum": 0 },
"end_ms": { "type": "integer", "minimum": 0 },
"clip_start_ms": { "type": "integer", "minimum": 0 },
"duration_ms": { "type": "integer", "minimum": 10000, "maximum": 20000 },
"text": { "type": "string" },
"coaching": {
"type": "array",
"minItems": 1,
"maxItems": 2,
"items": { "type": "string" }
},
"subject": { "type": "string" },
"visible_speed": { "type": "string" },
"confidence": { "type": "number", "minimum": 0, "maximum": 1 }
},
"required": [
"name",
"kind",
"label",
"severity",
"start_ms",
"end_ms",
"clip_start_ms",
"duration_ms",
"text",
"coaching",
"subject",
"visible_speed",
"confidence"
]
}
}
},
"required": ["summary", "events"]
}has_events
Ends the run when the drive has no events.
{
"has_events": {
"type": "filter",
"needs": ["events"],
"when": { "path": "events.metadata.events", "op": "non_empty" }
}
}review
Holds the events for a safety manager, and rejects them if nobody decides before the review expires.
{
"review": {
"type": "review",
"needs": ["has_events"],
"with": {
"instructions": "Safety manager: watch each flagged event in the recording and check its label, severity, narrative and coaching points. Approve to render a coaching clip for every listed event; reject when they are false alerts.",
"on_expiry": "reject"
}
}
}detect
Finds road users and other objects in each frame with an open D-FINE detector.
{
"detect": {
"type": "model",
"needs": ["frames", "review"],
"with": {
"provider": "huggingface",
"model": "onnx-community/dfine_l_obj365-ONNX",
"task": "object-detection",
"revision": "32323e9a0c74b22803a2ad5b315a8fed61801e6a",
"min_confidence": 0.45
}
}
}track
Links the detections into one track for each object.
{
"track": {
"type": "track",
"needs": ["detect"],
"with": {
"kinds": ["object"],
"iou_threshold": 0.25,
"max_gap_ms": 750,
"min_duration_ms": 1000,
"min_confidence": 0.45,
"high_confidence": 0.6
}
}
}overlay
Gemini picks the tracks that follow each event's subject and boxes readable plates and identifiable faces to blur.
{
"overlay": {
"type": "llm",
"needs": ["events", "frames", "track"],
"with": {
"provider": "google",
"model": "gemini-4-carbon",
"max_frames": 40,
"max_input_tokens": 300000,
"include": ["events.metadata.events", "track.annotations"],
"instructions": "…",
"output": { "mode": "json", "schema": "…" }
}
}
}Instructions of overlay
You prepare a fleet safety team's coaching clips. Each event in events.metadata.events gets a
clip of the recording from clip_start_ms to clip_start_ms + duration_ms, and its subject is the
road user involved in the event from start_ms to end_ms. The sampled frames carry their t_ms.
1. For each event, by its name, pick the object.track annotations from track.annotations that
follow its subject during the event. Compare the subject with each track's label and with
where its keyframe boxes lie on the frames at the same t_ms; boxes are x, y, w and h as
fractions of the frame width and height from the top left. List their track_id values in
subject_track_ids, the track that covers most of the event first. Never list a track that
follows another object, such as a vehicle in another lane, a sign or a light. Leave the list
empty when the event has no subject or no track follows it.
2. List every number plate whose characters can be read and every identifiable face of another
road user (pedestrians, cyclists, other drivers and passengers) that appears on the frames
within any clip, so they can be blurred. Do not list the fleet vehicle's own driver. Give
each plate or face one entry with an id, its kind (privacy.plate or privacy.face), start_ms
and end_ms, and a box on every frame within the clips where any part of it is visible, with
the frame's t_ms: include the frames where it enters or leaves the picture, is cut off by the
frame edge or is not yet sharp enough to read. start_ms is the t_ms of the last frame before
the first one that shows it (0 when the first frame shows it), and end_ms the t_ms of the
first frame after the last one that shows it (the input duration when it is still visible at
the end), so the blur covers it from the moment it appears. A box is [ymin, xmin, ymax, xmax]
in thousandths of the frame height and width, tight around the plate or face. Return an empty
list when nothing needs blurring.Output schema of overlay
{
"type": "object",
"properties": {
"events": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"subject_track_ids": {
"type": "array",
"maxItems": 6,
"items": { "type": "integer", "minimum": 1 }
}
},
"required": ["name", "subject_track_ids"]
}
},
"redactions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "string" },
"kind": { "type": "string", "enum": ["privacy.plate", "privacy.face"] },
"start_ms": { "type": "integer", "minimum": 0 },
"end_ms": { "type": "integer", "minimum": 0 },
"boxes": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"t_ms": { "type": "integer", "minimum": 0 },
"box_2d": {
"type": "array",
"minItems": 4,
"maxItems": 4,
"items": { "type": "integer", "minimum": 0, "maximum": 1000 }
}
},
"required": ["t_ms", "box_2d"]
}
}
},
"required": ["id", "kind", "start_ms", "end_ms", "boxes"]
}
}
},
"required": ["events", "redactions"]
}clips
Renders a 1920×1080 coaching clip for each event.
{
"clips": {
"type": "render",
"needs": ["overlay"],
"with": {
"template_id": "template:coaching-clip",
"for_each": "events.metadata.events",
"include": ["events", "overlay", "track"],
"width": 1920,
"height": 1080
}
}
}publish
Returns playback URLs for the clips.
{ "publish": { "type": "publish", "needs": ["clips"] } }How the template uses the step outputs
The clips step renders the coaching clip template once for each item of events.metadata.events. Each render receives RENDER_DATA with the recording in source, the event in item, its position in index and the outputs of events, overlay and track:
var data = window.RENDER_DATA || {};
var event = data.item || {};
var source = data.source || {};
var steps = data.steps || {};
var overlay = (steps.overlay && steps.overlay.metadata) || {};
var matched = (Array.isArray(overlay.events) ? overlay.events : []).filter(function (entry) {
return entry && entry.name === event.name;
})[0] || (Array.isArray(overlay.events) ? overlay.events[data.index] : null) || {};
var subjectIds = Array.isArray(matched.subject_track_ids) ? matched.subject_track_ids : [];
var tracks = (steps.track && Array.isArray(steps.track.annotations) ? steps.track.annotations : []).filter(function (a) {
return a && a.kind === "object.track" && Array.isArray(a.keyframes);
});From these the template:
- plays the event's clip window of the recording with an
ef-videowhosefile-idissource.file_id, and holds the last frame under an "End of recording" card when the recording ends before the clip does; - draws a box that follows the event's subject during the event, from the keyframes of the
object.trackannotations the overlay step matched to it; - blurs each plate and face in
overlay.metadata.redactionsfrom itsstart_msto itsend_ms, extending the blur along its motion so a plate entering or leaving the frame stays covered; - shows the event's label, severity, account and coaching points beside the footage, a timeline of the event, and a privacy note that states what was blurred.
The template is templates/coaching-clip.html, and templates/coaching-clip.schema.json describes the data it receives.
Run it
The example lives in elements/examples/fleet-dashcam/ in the Editframe repository: pipeline.json, the template in templates/, sources.json with each recording's download URL, licence and attribution, example.json with the pipeline's name and the recordings to run, and rubric.md, the criteria its output is judged by. From the repository root, with an API key of an organization that has pipelines and llm steps enabled:
export EDITFRAME_TOKEN="$EDITFRAME_API_KEY"
node elements/examples/scripts/run-example.mjs fleet-dashcamThe script reads example.json, which names the pipeline example-fleet-dashcam and runs two recordings. It registers each template the definition names as template:<name>, from templates/<name>.html and its .schema.json, through POST /api/v1/pipelines/templates, and replaces the reference with the template's ID; the API itself accepts only template IDs. It finds the pipeline by name or creates it, adds a version when the definition changed, and starts a group with one run per recording, which reads it from its download URL.
The review step waits for a decision. The script approves each review unchanged, as a manager accepting every event would; --review reject rejects them and --review wait leaves them for you to decide in the dashboard or with approvePipelineReview. Running the same version and items again returns the earlier group unless you pass --fresh, and --items runs other recordings of sources.json.
The script waits for the runs and saves their results under ~/.cache/editframe/example-runs/fleet-dashcam/<group-id>/: summary.json with the definition the runs used, and for each recording run.json, outputs/<namespace>.json and media/<file>.mp4. Requests go to EDITFRAME_HOST, https://editframe.com by default.
Licences
- Gentayangan · Dashcam footage · K · Expressway footage · Pexels License