The code
cut_clips.py
How it works
One job, file and transcript.includeTranscript: true with transcriptMode: "ai" runs speech-to-text on the same import, so the result has mediaUrl (the video) and transcript.data.segments, one segment per sentence with start and end in seconds. The download and the transcript are billed together; totalCostInDollars is what the job cost.
compatibleCodecs: true asks for H.264 video and AAC audio, which every editor, browser and phone plays. Without it you may get a smaller AV1 or VP9 file at the same resolution.
maxCostDollars caps the job. A long video at 720p plus speech-to-text costs more than a short clip, and a job that would go over fails with MAX_COST_EXCEEDED before anything is charged.
The cut re-encodes. Copying the stream (-c copy) is faster but starts on the nearest keyframe, which can be seconds before the sentence. Re-encoding a short clip takes a moment and starts where the sentence does. PAD adds half a second either side so words aren’t clipped.
The match is a plain substring search over each sentence. Swap matching_segments for whatever your app does: a list of keywords, a search index over segments, or an LLM that picks the best moments from the transcript text and returns their timestamps.
Errors to handle
Every error has a
documentationUrl with the fix. See Error handling.
In production
Don’t poll in a web request. Start the import from your API route, pass awebhookUrl, and cut the clips in a background worker when Importly calls back. See Webhooks.
Keep the source video. Add store: true and a storagePath so the file also lands in your own bucket, and cut from there whenever a user asks for a new clip, without importing again. See Save to your bucket.
Captions are cheaper when the video has them. Send transcriptMode: "captions" (or "auto", the default, for captions with speech-to-text when there are none) and transcriptLanguage to use the platform’s captions (line-by-line timing, sometimes auto-generated). See Transcripts.
A 10-minute 720p video (about 77 MB) costs about $0.15 to import, and $0.10 more for the speech-to-text transcript. Status checks are free. Try it free, no card required. See Pricing & credits.