Cut a 10-minute recording into 3-minute Reels with video trim

A 600 s recording becomes four trims: 180, 180, 180 and 60 s, $0.08 in total. Python loop with a safe Idempotency-Key per segment; run it with an imported file.

5 min readSume
All posts

Reels run to 3 minutes, as NapoleonCat reports. A 10-minute recording therefore needs four cuts: three of 180 seconds and one of 60. Each video trim is $0.02, so the set is $0.08.

The loop

The source must already be on media.sume.com (import it first), every call needs an Idempotency-Key, and you send start plus only one of end or duration. A key built from the video name, start and duration makes a retry safe.

import os, requests

key = os.environ.get("SUME_API_KEY", "")
assert key, "set SUME_API_KEY"
SRC = "https://media.sume.com/artifacts/artf_demo/talk.mp4"

def plan(total, seg=180):
    return [(s, min(seg, total - s)) for s in range(0, total, seg)]

for start, dur in plan(600):
    r = requests.post(
        "https://api.sume.com/v1/video-trim",
        headers={"Authorization": f"Bearer {key}",
                 "Idempotency-Key": f"talk-{start}-{dur}"},
        json={"video_url": SRC, "start": start, "duration": dur},
        timeout=60,
    )
    r.raise_for_status()
    print(start, dur, r.json()["request_id"])

After the call

The default mode is async, so each call returns a job. Poll GET /v1/jobs/:id/status and read GET /v1/jobs/:id/result, which holds the new video_url. If a segment ends near a sentence, shift start by a second; also note a final piece shorter than 0.2 seconds is rejected.

Limits

Trim output is capped at 900 seconds and the source at 1800, so this loop covers a recording up to 30 minutes.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume