# Subtask segmentation & semantic trimming

Canonical: https://interlatent.com/docs/ivy/subtask-segmentation

Prompt Ivy to divide a video into meaningful steps, steer the boundaries and labels, and export selected sections as video clips.

## Separate a video into meaningful sections

Section: https://interlatent.com/docs/ivy/subtask-segmentation#segment

Subtask segmentation divides a recording into timestamped sections based on what happens in the video. Ask your agent to use `segment_subtasks`, which saves a labeled timeline. For example, a packing video might contain opening a box, placing an item inside, and sealing the box. You can steer what counts as one section through your prompt.

### Prompt

```text
Use Ivy’s subtask segmentation tool to divide this packing video into meaningful steps. One subtask is one continuous action toward an immediate goal; start a new section when that goal changes. Use short action labels, retain repeated attempts, and save the timestamped timeline. Send me the section list and a dashboard link.
```

Note: Segmentation creates labels and time boundaries. Exporting those sections as separate videos is a follow-up trimming operation.

- [Import a video first](https://interlatent.com/docs/ivy/import-datasets)
- [Choose action timelines as your output](https://interlatent.com/docs/ivy/models#actions)

## Steer segmentation with a prompt

Section: https://interlatent.com/docs/ivy/subtask-segmentation#steer

Describe what one subtask means, which visible change starts a new one, and the labels you want. Your agent passes that guidance in the tool’s `convention` field. Choose broader sections for a process overview or smaller sections for individual actions. Define the rule for a section rather than prescribing a fixed number of sections for the whole video.

| What to steer | Example guidance |
| --- | --- |
| Section size | Keep opening, filling, and sealing as separate sections; keep small adjustments within the current step. |
| Start and end boundaries | Start “placing item” when the item begins moving into the box; end when it is released. |
| Label vocabulary | Use opening box, placing item, sealing box, and unclear when those labels apply. |
| Repeated or incomplete actions | Keep each new attempt separate and retain incomplete attempts. |
| Uncertain footage | Mark unclear intervals rather than inventing an action that is not visible. |

### Prompt

```text
Segment this video using this convention: one subtask is one completed or attempted packing action. Separate opening the box, placing each item, and sealing the box. Keep minor hand adjustments within the current action. Start a new section for a new attempt, even when the same action repeats. Use “unclear” where the action cannot be determined. Save the timeline as “Packing steps”.
```

Note: Use `convention` for segmentation guidance. The tool’s `instruction` field supplies a task description only when the recording has no task metadata.

## Review the sections and refine the convention

Section: https://interlatent.com/docs/ivy/subtask-segmentation#review

Open the saved timeline and inspect the section boundaries against the original video. Give feedback about a specific transition or a step that should stay together. To compare two conventions, keep the same recording and camera and use distinct track names. Reusing a track name replaces that named segmentation track.

### Prompt

```text
The “placing item” section includes closing the lid. Refine the convention so closing the lid starts a new section. Re-segment the same recording and camera into a new track named “Packing steps refined”. Show both timelines and the changed boundaries before we use the new sections for trimming.
```

- [Compare annotation variants](https://interlatent.com/docs/ivy/experiments#compare)
- [Review annotations in context](https://interlatent.com/docs/ivy/review-and-export#inspect)

## Trim by meaning instead of entering timestamps

Section: https://interlatent.com/docs/ivy/subtask-segmentation#semantic-trimming

Semantic trimming starts with a description of the sections you want, such as “each time an item is placed in the box”. Use reviewed segmentation labels to find the matching intervals, then export them as separate video clips. You can request context before and after each interval. The agent uses the saved start and end times for the cuts.

1. Segment the video with a convention that identifies the actions you care about.
2. Review the labels and boundaries, then choose the sections to keep.
3. Choose padding, the source camera, and whether each section should be a separate clip.
4. Export the selected intervals and inspect the beginning and end of each clip.

### Prompt

```text
From the reviewed “Packing steps refined” timeline, find every “placing item” section. List the matching source intervals, adding half a second before and after each and clamping them to the recording duration. Export each match as a separate MP4 in the same camera. Keep the original recording unchanged, and return a labeled list of clips with source timestamps and download links.
```

Note: If the recording already has suitable annotations, query those first. For recordings without them, segment and review before trimming. A new clip starts at time zero, so keep its source interval with the export.

- [Video trimming and output options](https://interlatent.com/docs/ivy/trimming)
- [Create an excerpt with ctx.trim](https://interlatent.com/docs/ivy/custom-code#trim-code)
- [Query saved action intervals](https://interlatent.com/docs/ivy/query-reference#intervals)

## Tool flow for your agent

Section: https://interlatent.com/docs/ivy/subtask-segmentation#tool-flow

Call `segment_subtasks` with the recording, camera, convention, and track name. Poll `get_job` with `kind="annotation"` at intervals of at least five seconds, then read `get_annotations` and inspect the timeline. After selecting the sections, use the saved intervals with a trimming recipe or a local video export. Segmentation uses credits; a custom script is not needed to create the timeline.

- [Segmentation and analysis tools](https://interlatent.com/docs/ivy/tool-reference#analysis)
- [Trimming recipe reference](https://interlatent.com/docs/ivy/custom-code#trim-code)
