Highlight reels from a full game

Turn a game recording into a 16:9 recap reel and a 9:16 reel: cuts, motion, ball detection, plays ranked by Gemini and two render templates.

This pipeline turns the full recording of an amateur game into highlight reels. Gemini watches the game and ranks the plays worth showing. One template cuts each play twice, as a 16:9 clip and as a tall clip whose window follows the ball, and a second template assembles a 75-second 16:9 reel and a 30-second 9:16 reel from those clips.

The example ran on ten minutes of a Slovenian women's league basketball game from one courtside camera. See the reels beside the other examples in the pipeline examples.

Highlight reel, 16:91:15
Vertical reel, 9:160:30
The moments step is an llm step. Editframe enables pipelines, and llm steps, for an organization after you tell us about your footage.

What it produces

  • The 75-second 16:9 reel (reel) and the 30-second 9:16 reel (vertical), as files in your organization, with playback URLs from publish.
  • A 1280×720 clip (plays_wide) and a 1080×1100 clip (plays_tall) of every ranked play, which the reels play.
  • The moments step's answer: the sport, the two teams, an opener and a closer, and the ranked plays, each with its span, the time of the action, its kind, team, label and caption.
  • Camera cuts, motion marks, transcript and per-frame boxes of players and the ball, readable by namespace.

The pipeline

This is the example's pipeline.json, step by step. A step starts when the steps in its needs have finished. frames and detect are segment steps: they work through the recording in 30-second windows. The long instructions and output.schema of the llm step are shown below it.

probe

Reads the recording's duration, frame size and tracks.

json
{ "probe": { "type": "probe" } }

transcript

Transcribes any announcer or commentary, in the language it detects.

json
{
  "transcript": {
    "type": "transcribe",
    "needs": ["probe"],
    "with": { "language": "auto" }
  }
}

scenes

Finds the camera cuts.

json
{
  "scenes": {
    "type": "detect_scenes",
    "needs": ["probe"],
    "with": { "threshold": 0.2 }
  }
}

motion

Marks small changes between frames, from which the templates tell live play from slow-motion replays.

json
{
  "motion": {
    "type": "detect_scenes",
    "needs": ["probe"],
    "granularity": { "mode": "segment", "window_ms": 30000 },
    "with": { "threshold": 0.01 }
  }
}

frames

Takes a frame every 0.75 seconds, in 30-second windows.

json
{
  "frames": {
    "type": "sample_frames",
    "needs": ["probe"],
    "granularity": { "mode": "segment", "window_ms": 30000 },
    "with": { "every_ms": 750 }
  }
}

detect

Finds the players and the ball in each frame with an open D-FINE detector.

json
{
  "detect": {
    "type": "model",
    "needs": ["frames"],
    "granularity": { "mode": "segment", "window_ms": 30000 },
    "with": {
      "provider": "huggingface",
      "model": "onnx-community/dfine_l_obj2coco_e25-ONNX",
      "task": "object-detection",
      "revision": "60e6123fe13da26a6e1dafc9d608ddeb5c393dcc",
      "min_confidence": 0.4
    }
  }
}

moments

Gemini watches the game and ranks the plays worth showing, with a caption for each.

json
{
  "moments": {
    "type": "llm",
    "needs": ["transcript", "scenes"],
    "with": {
      "provider": "google",
      "model": "gemini-4-carbon",
      "attach_video": true,
      "max_frames": 0,
      "max_input_tokens": 400000,
      "include": ["transcript", "scenes"],
      "instructions": "…",
      "output": { "mode": "json", "schema": "…" }
    }
  }
}
Instructions of moments
text
You are the video editor of an amateur sports club, cutting the highlight reel of a game from
the club's own recording. The input is a game recording from a courtside camera with the natural
sound of the venue. Watch and listen to all of it. The transcript (speech.word annotations)
holds any announcer or commentary; it may be empty or hold words misheard from crowd noise, so
trust what you see and hear over it. The scene.cut annotations mark camera cuts and edits; each
cut happens at its start_ms.

Live play and replays. Some recordings are already edited: a play is shown live, at normal speed
with the sound of the venue, and then repeated as a replay, often in slow motion, with music or
without crowd sound, sometimes after a transition. Each replay repeats a play shown live just
before it.

Find every moment a club would put in its highlight reel:
- Scoring plays where you can see the ball go in: three-pointers, drives and lay-ups, jump
  shots, put-backs, and-ones, fast breaks, buzzer beaters; in football, goals.
- Defensive plays where a defender clearly wins the ball: a block that touches the ball, a
  steal, a charge taken; in football, a save. A missed shot or a contested miss is not a block.
- Reactions: the bench or the crowd erupting right after a big play. Include at most two, and
  only when they are emotional.
Skip warm-ups, introductions, timeouts, free throws (unless they decide the game), dead balls,
substitutions, missed shots and any play whose outcome you cannot see. Never invent a moment.
Include every made basket or goal of either team that the footage shows, so the reel can show
both teams: a recording one club edited often favours it, so check the shirts of the scorer on
every made basket and list the other team's too. Never pad the list with routine plays. A basket
counts only when you see the ball drop through the net: after a make the other team inbounds the
ball from behind the baseline, after a miss a player rebounds it. A foul on a missed shot is not
an and-one. A shot that misses and a team-mate's score on the rebound right after are one
moment, a put-back, timed on the shot that goes in.

Choose plays a fan can follow from the build-up to the ball dropping through the net. Rank a
play lower when its footage starts only as the shot is taken, or the camera loses the basket as
the ball goes in, and leave it out when the recording has enough other plays.

List 10 to 14 moments when the recording has them (fewer for a short clip), in the order they
happen, each play once. Time a moment on its live footage whenever the live play is visible,
even when the live shot is short or the camera is far away; when you can place a play only on
its replay, time it on the replay.

Timing, in milliseconds of the input video. Be as exact as you can; check each time against the
video at normal speed.
- action_ms: the instant of the decisive action: the ball dropping through the net (for a
  put-back, the put-back's), the block, the steal, the save, or the peak of a reaction.
- start_ms: exactly action_ms - 20000, or 0 when that is negative, and end_ms: exactly action_ms
  + 4000. The editing template picks the clip's footage in that span from the recording's frame
  changes, so moments may overlap.

For each moment give:
- kind: "highlight".
- name: a short lowercase slug such as "q1-three-14".
- label: the play type, exactly as it happened: a finish at the rim off a drive, cut or lob is a
  layup; a one-handed shot lofted over defenders from the lane is a floater; jump_shot is a shot
  taken in a jump away from the basket.
- team: "light" for the team in the lighter shirts, "dark" for the team in the darker shirts,
  "none" for a neutral moment.
- text: a caption of at most 56 characters in sentence case that says what happens, such as
  "Guard drives baseline for the lay-up". Describe the player by role (guard, wing, forward,
  center); give no jersey numbers, which are rarely legible at the recording's distance, and
  never name players. Do not say where on the court a shot was taken, such as the corner or the
  top of the key, nor left or right (the camera's left is not the court's left). No exclamation
  marks and no hype words.
- rank: 1 to 10, how much a fan of either team wants to see it (10 is game-defining).
- confidence: 0 to 1, how sure you are that the outcome happened as described.
- score: the score on the venue scoreboard right after the play, as "<light team points>-<dark
  team points>", only when the venue scoreboard is legible in the video at that time (it may sit
  at the edge of some shots); otherwise "". Never compute or guess a score.
- focus_start, focus_action and basket_x, for a vertical crop, as fractions of the frame width
  (0 left edge, 1 right edge): focus_start is the horizontal centre of the ball handler 3000 ms
  before action_ms; focus_action is the player who makes the play, such as the shooter as the
  ball leaves the hands, not the passer; basket_x is where the basket or goal they attack is at
  action_ms.
- build_up_ms: where the possession or move that leads to the play starts, in live footage at
  normal speed: the inbound, the steal, the tip-off or the first dribble of the drive. For a
  play the recording shows live to the finish it lies in that shot; for a play it slows down or
  replays, in the live footage just before.
- why: one sentence on why it belongs in the reel.

Also give:
- sport.
- light_team and dark_team: kit, a short description of the shirt colours such as "white with
  green"; color, the dominant shirt colour as #rrggbb (for white shirts give the trim colour);
  name, only when the team name is clearly legible on shirts, banners or the scoreboard,
  otherwise "". Words on shirts are often sponsors, not team names.
- opener: 3000 to 5000 ms of live footage for the title card's background: a calm wide view of
  the court or pitch, the line-up or the tip-off, without a scene cut inside.
- closer: 4000 to 6000 ms of live footage for the end card's background: a celebration,
  handshakes, the bench or a wide view, without a scene cut inside.
Output schema of moments
json
{
  "type": "object",
  "properties": {
    "sport": {
      "type": "string",
      "enum": ["basketball", "football", "volleyball", "handball", "hockey", "other"]
    },
    "light_team": {
      "type": "object",
      "properties": {
        "kit": { "type": "string" },
        "color": { "type": "string" },
        "name": { "type": "string" }
      },
      "required": ["kit", "color", "name"]
    },
    "dark_team": {
      "type": "object",
      "properties": {
        "kit": { "type": "string" },
        "color": { "type": "string" },
        "name": { "type": "string" }
      },
      "required": ["kit", "color", "name"]
    },
    "opener": {
      "type": "object",
      "properties": {
        "start_ms": { "type": "integer", "minimum": 0 },
        "end_ms": { "type": "integer", "minimum": 0 }
      },
      "required": ["start_ms", "end_ms"]
    },
    "closer": {
      "type": "object",
      "properties": {
        "start_ms": { "type": "integer", "minimum": 0 },
        "end_ms": { "type": "integer", "minimum": 0 }
      },
      "required": ["start_ms", "end_ms"]
    },
    "moments": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "kind": { "type": "string", "enum": ["highlight"] },
          "name": { "type": "string" },
          "label": {
            "type": "string",
            "enum": [
              "three_pointer",
              "layup",
              "dunk",
              "floater",
              "jump_shot",
              "putback",
              "and_one",
              "fast_break",
              "buzzer_beater",
              "free_throw",
              "block",
              "steal",
              "assist",
              "goal",
              "save",
              "shot",
              "skill",
              "crowd_reaction",
              "celebration",
              "big_play"
            ]
          },
          "team": { "type": "string", "enum": ["light", "dark", "none"] },
          "start_ms": { "type": "integer", "minimum": 0 },
          "action_ms": { "type": "integer", "minimum": 0 },
          "end_ms": { "type": "integer", "minimum": 0 },
          "text": { "type": "string" },
          "rank": { "type": "integer", "minimum": 1, "maximum": 10 },
          "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
          "score": { "type": "string" },
          "focus_start": { "type": "number", "minimum": 0, "maximum": 1 },
          "focus_action": { "type": "number", "minimum": 0, "maximum": 1 },
          "basket_x": { "type": "number", "minimum": 0, "maximum": 1 },
          "why": { "type": "string" },
          "build_up_ms": { "type": "integer", "minimum": 0 }
        },
        "required": [
          "kind",
          "name",
          "label",
          "team",
          "start_ms",
          "action_ms",
          "end_ms",
          "text",
          "rank",
          "confidence",
          "score",
          "focus_start",
          "focus_action",
          "basket_x",
          "why",
          "build_up_ms"
        ]
      }
    }
  },
  "required": ["sport", "light_team", "dark_team", "opener", "closer", "moments"]
}

plays_wide

Cuts each play as a 1280×720 clip.

json
{
  "plays_wide": {
    "type": "render",
    "needs": ["moments", "motion"],
    "with": {
      "template_id": "template:sports-play",
      "for_each": "moments.metadata.moments",
      "include": ["motion"],
      "width": 1280,
      "height": 720
    }
  }
}

plays_tall

Cuts each play as a 1080×1100 clip whose window follows the ball, or else the players.

json
{
  "plays_tall": {
    "type": "render",
    "needs": ["moments", "motion", "detect"],
    "with": {
      "template_id": "template:sports-play",
      "for_each": "moments.metadata.moments",
      "include": ["motion", "detect"],
      "width": 1080,
      "height": 1100
    }
  }
}

reel

Assembles the 75-second 16:9 reel with a title card, lower thirds and an end card.

json
{
  "reel": {
    "type": "render",
    "needs": ["moments", "scenes", "plays_wide"],
    "with": {
      "template_id": "template:sports-reel",
      "include": ["moments", "scenes", "plays_wide"],
      "width": 1280,
      "height": 720,
      "duration_ms": 75000
    }
  }
}

vertical

Assembles the 30-second 9:16 reel from the tall clips.

json
{
  "vertical": {
    "type": "render",
    "needs": ["moments", "scenes", "plays_tall"],
    "with": {
      "template_id": "template:sports-reel",
      "include": ["moments", "scenes", "plays_tall"],
      "width": 1080,
      "height": 1920,
      "duration_ms": 30000
    }
  }
}

publish

Returns playback URLs for both reels.

json
{ "publish": { "type": "publish", "needs": ["reel", "vertical"] } }

How the templates use the step outputs

Two templates do the editing. Each render receives RENDER_DATA with the input file in source and the outputs of the steps in include; a for_each render also receives its play in item and its position in index.

The sports play template renders once for each item of moments.metadata.moments. It reads the scene.cut annotations of motion, the detector set to its lowest threshold, inside the play's span: in live play, consecutive frames change, while a slow-motion replay repeats frames. It plays the live shot that holds the action or, when the recording shows the action only as a replay, plays that replay muted at the rate that restores real speed. The 1080×1100 render also reads the detect boxes and moves a full-height window to follow the ball, or the players when no ball is found.

The sports reel template assembles a reel from the clips that a render step it includes already made. It finds them in that step's output and plays each one by its file ID:

js
var steps = data.steps || {};
var plan = (steps.moments && steps.moments.metadata) || {};
var clips = {};
Object.keys(steps).forEach(function (namespace) {
  var renders = ((steps[namespace] || {}).metadata || {}).renders;
  (Array.isArray(renders) ? renders : []).forEach(function (r) {
    if (r && r.status === "complete" && r.output_file_id && r.duration_ms > 0) {
      clips[r.index] = { file: r.output_file_id, length: Math.round(r.duration_ms) };
    }
  });
});

In 16:9 it opens on a title card that names the game, from the teams in moments and the upload's file name, gives each play a lower third with its team, kind and caption, and ends on a card with the footage credit its licence requires. In 9:16 it plays the tall clips between a header and the captions. Each reel lasts its render step's duration_ms, which the template's segments add up to.

The templates are templates/sports-play.html and templates/sports-reel.html, each with a .schema.json that describes the data it receives.

Run it

The example lives in elements/examples/sports-highlights/ in the Editframe repository: pipeline.json, the templates in templates/, sources.json with each source's download URL, licence and attribution, example.json with the pipeline's name and the items to run, and rubric.md, the criteria its output is judged by. A URL source must be MP4 or MOV and the game recordings are WebM, so this example has its own runner. From the repository root, with an API key of an organization that has pipelines and llm steps enabled, and Docker for FFmpeg:

bash
export EDITFRAME_TOKEN="$EDITFRAME_API_KEY"
node elements/examples/sports-highlights/run.mjs

For each item that is not MP4 or MOV, run.mjs converts the cached source to H.264/AAC MP4 with the linuxserver/ffmpeg image and uploads it once, remembering its file ID in ~/.cache/editframe/example-uploads; MP4 items run from their download URL. It then registers the templates the definition names as template:<name> and replaces each reference with the template's ID, finds or creates the pipeline example-sports-highlights and its version as elements/examples/scripts/run-example.mjs does, and starts a group with one run per item. --items selects other items of sources.json and --fresh starts a new group.

It then hands the group to run-example.mjs --group, which waits for the runs and saves their results under ~/.cache/editframe/example-runs/sports-highlights/<group-id>/: summary.json with the definition the runs used, and for each item run.json, outputs/<namespace>.json and media/<file>.mp4. Requests go to EDITFRAME_HOST, https://editframe.com by default.

To change a template without running the pipeline again, render it on a saved run's outputs with node elements/examples/scripts/render-template.mjs sports-highlights sports-reel --data <data.json>.

Licences