SAM 3.1 video selection
Choose an object on one frame and keep its selection through the video. SAM 3.1 takes an original clip plus text, points or boxes and returns one lossless black-and-white mask MP4. White marks the selected object. The mask keeps the source dimensions, frame count and frame rate, so it can be used directly for compositing, occlusion and moving selections.
The selection can start on any frame. Tracking runs forward and backward from that frame, following the chosen instance rather than adding other objects that match its name.
| Task | Model ID | Input | Output |
|---|---|---|---|
| Video object selection | sam3_video_segment_fp16 |
referenceVideo and sam3VideoPrompt |
One lossless binary mask MP4 |
Use the JavaScript or Python SDK, or the Creative Agent CLI. For an original still, use the separate SAM 3 image workflow.
#Source requirements
- Up to 30 seconds and 900 frames, with neither edge exceeding 2560 pixels.
- A constant frame rate from 1 to 60 fps, including fractional rates.
- 100 MB or less, SDR, square pixels, with rotation already applied.
- Upload the original clip. The server reads its actual geometry and timestamps before charging. If you supply
width,height,framesorfps, they must match the upload.
The output is a hard selection mask. It has no audio or transparency channel. Feathered alpha mattes and transparent cutout videos are separate compositing steps.
#Selection prompt
Use normalized coordinates from 0 to 1 in the original video's frame. The origin is its top-left corner. The existing image selection rules for signed points, boxes and text also apply.
| Field | Meaning |
|---|---|
text |
A short name for the visible object, such as unicorn horn. |
points |
Positive and negative { x, y, label } clicks on the selected frame. |
boxes |
Positive and negative { x0, y0, x1, y1, label } boxes. Negative boxes require text. |
frameIndex |
Zero-based selection frame; default 0. |
objectIndex |
Zero-based index among matches sorted by score; default 0, the strongest match. |
threshold |
Confidence threshold from 0 to 1; default 0.5. |
output |
mask. |
edges |
hard. |
One job tracks one selected instance. Text and points cannot be combined. applyMask and maxInstances belong to the image workflow; use objectIndex to choose a video instance.
To select a drawn region, track several things in one mask, or prompt more than one frame, use the optional selection options.
#JavaScript SDK
import { readFileSync } from 'node:fs';
import { SogniClient, SAM3_VIDEO_SEGMENT_MODEL_ID } from '@sogni-ai/sogni-client';
const client = await SogniClient.createInstance({
appId: crypto.randomUUID(),
apiKey: process.env.SOGNI_API_KEY,
network: 'fast'
});
const project = await client.projects.create({
type: 'video',
modelId: SAM3_VIDEO_SEGMENT_MODEL_ID,
positivePrompt: '',
numberOfMedia: 1,
referenceVideo: new Blob([readFileSync('clip.mp4')], { type: 'video/mp4' }),
sam3VideoPrompt: { text: 'unicorn horn', frameIndex: 127 }
});
const [maskUrl] = await project.waitForCompletion();
console.log(maskUrl);
client.disconnect();
The upload is preserved at its original size and timing. Omit generation controls such as steps, resizing, interpolation or trimming.
#Python SDK
import asyncio
import os
from sogni_client import SogniClient
async def main():
async with await SogniClient.create(
api_key=os.environ['SOGNI_API_KEY'], app_id='video-selection'
) as client:
project = await client.projects.create(
type='video',
model_id='sam3_video_segment_fp16',
positive_prompt='',
number_of_media=1,
reference_video='clip.mp4',
sam3_video_prompt={'text': 'unicorn horn', 'frameIndex': 127},
)
print(await project.wait_for_completion())
asyncio.run(main())
#CLI
sogni-agent --segment-video clip.mp4 --segment-text "unicorn horn" \
--segment-frame 127 -o mask.mp4
Use --segment-point, --segment-exclude and --segment-box for spatial prompts. Signed boxes are available through the SDK. --segment-object chooses another ranked instance. --segment-frame is a frame index, not a timestamp in seconds.
#Selection options
Four more fields can go in sam3VideoPrompt. They are all optional and off by default. A prompt without them runs and is priced exactly as before.
| Field | What it does |
|---|---|
mask |
Selects a region you draw, instead of text, points or boxes. |
objects |
Tracks 2 to 16 separate things together and merges them into one mask. |
frames |
Selects the same thing on 2 to 8 different frames. |
memory |
Chooses how tracking carries from one 32-frame chunk to the next. |
Send them with the JavaScript or Python SDK, version 5.80.0 or later. The CLI does not send them yet.
#Draw a region with mask
Give the outline as one or more polygons. Each point is [x, y], from 0 to 1 across the source frame, with the origin at its top-left corner. A ring inside another ring is a hole.
{
"frameIndex": 0,
"mask": {
"polygons": [
[[0.42, 0.18], [0.58, 0.18], [0.61, 0.55], [0.39, 0.55]]
]
}
}
The region starts the tracker on its prompt frame, just as a click does. The mask on that frame is the tracker's own shape for the region, not your exact drawing. That keeps the prompt frame consistent with the frames around it, so a looping clip does not jump between its last and first frames.
Draw the region tight. If it covers background, or something standing in front of the object, the mask keeps that extra area for several frames before the tracker corrects it.
- 1 to 64 rings, each with 3 to 2048 points, and at most 4096 points in one region.
maskcannot be combined withtext,points,boxes,thresholdormultimaskin the same selection.objectIndexmust be0or left out.- A region too small to cover any pixel of the source frame is refused, and the job is not charged.
#Track several things with objects
Put one selection for each thing in objects, and set combine to "union". Every output frame is the union of their masks. All the selections refer to the top-level frameIndex, which defaults to 0.
{
"frameIndex": 0,
"combine": "union",
"objects": [
{ "points": [{ "x": 0.21, "y": 0.48, "label": "positive" }] },
{ "points": [{ "x": 0.52, "y": 0.45, "label": "positive" }] },
{ "points": [{ "x": 0.80, "y": 0.50, "label": "positive" }] }
]
}
Use objects for a crowd or for several separate things, with one selection each. A single selection that covers several similar things tends to settle on just one of them.
- 2 to 16 objects. Each entry takes
text,points,boxesormask, plusthresholdandobjectIndexwhere they apply. - Put every selection inside
objects. A top-leveltext,points,boxes,mask,threshold,multimaskorobjectIndexis refused alongside it. objectscannot be combined withframes.
#Select on several frames with frames
Give 2 to 8 entries. Each has its own frameIndex and selection. Each output frame follows the track from the nearest prompted frame; when two are equally near, the earlier one wins. The clip is still tracked about once.
For a looping video whose first and last frames are the same still, select the same thing on frame 0 and on the last frame. In this 121-frame clip, the last frame is 120:
{
"frames": [
{ "frameIndex": 0, "points": [{ "x": 0.47, "y": 0.62, "label": "positive" }] },
{ "frameIndex": 120, "points": [{ "x": 0.47, "y": 0.62, "label": "positive" }] }
]
}
You can also add a frame in the middle of a clip to correct a selection that has drifted.
- Every
frameIndexmust be different and must be a frame of the source. - Each entry takes
text,points,boxesormask, like anobjectsentry. - Do not send a top-level
frameIndexor selection withframes, and do not combine it withobjects.
#Choose tracking memory with memory
The tracker works through a clip in chunks of 32 frames.
"chunk", the default, starts each chunk from the mask at the end of the previous one. This is how video selection has always worked. An object lost at the end of a chunk is not found again."anchor"starts each chunk again from the prompt frame and its selection. Tracking errors do not carry from one chunk to the next, and a lost object can be found again. The mask can shift where a chunk starts.
{ "text": "unicorn horn", "frameIndex": 127, "memory": "anchor" }
memory works on its own or with any of the other options.
#Prompt size and workers
- At most 4096 region points in one prompt, across all its objects and frames. Simplify long outlines if you reach it.
objectsandframescannot be used together.
These options run on Comfy Worker 1.0.253 or newer. If none is online, the request is refused straight away with error 4044, No workers available for this model, and nothing is charged. A prompt without the options runs on every SAM video worker.
#Pricing and timing
Video selection is priced from the source's verified frame count and pixel area, with a per-frame cost for the tracker. Request a live estimateVideoCost() using the source's width, height, frames, fps and steps: 1; the submitted job is charged from the uploaded bytes.
The selection options change the price only a little:
- Each object after the first adds 8% of one selection's work. Three objects cost 1.16 times one selection.
memory: "anchor"adds 1/31, about 3%.framesandmaskadd nothing.
Pass the job's own sam3VideoPrompt to estimateVideoCost() in JavaScript, or sam3_video_prompt to estimate_video_cost() in Python, and the SDK prices these for you. If you call the video estimate endpoint directly, add the query values sam3ObjectCount (2 to 16) and sam3Memory (chunk or anchor). A quote without them is the same as before.
A 1920 × 1080 clip with 255 frames at 24 fps took 38.27 seconds end to end on an RTX 4090 in qualification. A 720-frame, 30-second clip at the same dimensions took 106.12 seconds. These single-run measurements include local delivery; Supernet upload, queuing and download time depend on the job and connection.
#Result provenance
Each completed job carries the mask SHA-256, source-video SHA-256, normalized selection-prompt SHA-256, mask width, height, frame count and frame rate, plus the SAM version. Keep that receipt with the source and mask when a later edit depends on exact alignment.
Workers need Comfy Worker 1.0.252 or newer and the independent SAM3 video optional pack on a local NVIDIA CUDA 13 runtime. The selection options need 1.0.253 or newer. The existing image SAM pack remains separate.