Skip to main content
A clipping tool, highlight reel or repurposing app needs two things from a link: the full video file and a transcript with timestamps, so it can find the moment and cut it. Getting the file yourself means a download tool that gets blocked on servers, and getting the timestamps means a separate speech-to-text step. One Importly import returns both. This script takes a link and a phrase, finds every sentence where it’s said, and cuts each one into its own MP4 with ffmpeg on your machine or server. Importly delivers the file and the transcript; your app does the cutting, so you control the edit.

The code

cut_clips.py
Create your key on the API key page (it’s shown once) and keep it on the server. Output for that link:

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 a webhookUrl, 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.