Sign in Get started

Video

Upload a video, read its duration and frame rate, and extract frames at the rate you choose into a dataset, as images ready to annotate and train on.

View as Markdown
On this page

Extract a video’s frames into a dataset, each an ordinary image: upload, optionally probe, then extract_frames. upload returns the handle (info.video) the others take; the video is deleted once extracted. To run models over a video without extracting it, use a workflow.

upload

Upload a local video.

Source: Video.upload

Arg Type Default Notes
file_path str | Path required Local video file
content_type str "video/mp4" MIME type; set it for other containers, e.g. video/quicktime or video/webm
info = client.video.upload(
    file_path="./recording.mp4",
    content_type="video/mp4",
)
print(info.video)
pictograph video upload ./recording.mp4 --content-type video/mp4
# Step 1: ask for an upload URL; the answer's `video` is the handle.
curl -s -X POST "https://api.pictograph.io/api/v1/developer/video/upload-url" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"filename": "recording.mp4", "content_type": "video/mp4"}'

# Step 2: PUT the bytes to the returned upload_url. No API key - the signed URL
# carries its own signature.
curl -s -X PUT "<upload_url>" \
  -H "Content-Type: video/mp4" \
  --data-binary @./recording.mp4

Returns VideoUploadInfo

VideoUploadInfo · 2 fields
class VideoUploadInfo(BaseModel):
    """An uploaded video: `video` is the handle pictograph.resources.video.Video.probe and pictograph.resources.video.Video.extract_frames take."""
    upload_url: str
    video: str

H.264, H.265, VP9 and AV1 all work.

probe

A video’s duration, frame rate, size and frame count. It reads the whole file, so call it once.

Source: Video.probe

Arg Type Default Notes
video str required Video handle from upload
meta = client.video.probe(video=info.video)
print(meta.duration_seconds, meta.native_fps, meta.width, meta.height, meta.frame_count)
pictograph video probe "<video-from-upload>"
curl -s -X POST "https://api.pictograph.io/api/v1/developer/video/probe" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"video": "<video-from-upload>"}'

Returns VideoMetadata

VideoMetadata · 5 fields
class VideoMetadata(BaseModel):
    """Probe result for an uploaded video."""
    duration_seconds: float
    # The video's frame rate.
    native_fps: float
    width: int
    height: int
    # Frames at its own rate.
    frame_count: int

extract_frames

Extract frames at sample_fps into a dataset directory (created if missing); each frame becomes an image.

Source: Video.extract_frames

Arg Type Default Notes
dataset str required Dataset name or id
video str required Video handle from upload
directory str required Destination directory, e.g. /clips/run-1; created if missing
sample_fps float 1.0 Frames per second of video (max 60)
wait bool True Wait until the job finishes
poll_interval float 3.0 Seconds between checks
timeout float 1800.0 Max seconds to wait
job = client.video.extract_frames(
    dataset="my-dataset",
    video=info.video,
    directory="/raw-footage/frames",
    sample_fps=2.0,
    timeout=1800.0,
)
print(job.status, job.frames_extracted, job.directory_path)
pictograph video extract-frames my-dataset "<video-from-upload>" \
  --directory /raw-footage/frames \
  --sample-fps 2.0
curl -s -X POST "https://api.pictograph.io/api/v1/developer/video/extract-frames" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "my-dataset", "video": "<video-from-upload>",
       "directory": "/raw-footage/frames", "sample_fps": 2.0}'

Returns VideoExtractionJob

VideoExtractionJob · 9 fields
class VideoExtractionJob(BaseModel):
    """Snapshot of a frame-extraction job."""
    job_id: str
    status: Literal['processing', 'complete', 'failed']
    progress: int = 0
    frames_extracted: int = 0
    total_frames: int = 0
    error: str | None = None
    # The directory the frames went into, once it succeeds.
    directory_path: str | None = None
    # Set when the image quota cut the frames short; the job still completes.
    warning: str | None = None
    # The frames' image ids, once the job is complete.
    image_ids: list[str] | None = None

Extracting is free; the frames count as images.

get_extraction

An extraction’s state, for one started with wait=False.

Source: Video.get_extraction

Arg Type Default Notes
job str required Job id
job = client.video.get_extraction(job="7c1f4a90-2b3d-4e56-8f70-9a1b2c3d4e5f")
pictograph video status 7c1f4a90-2b3d-4e56-8f70-9a1b2c3d4e5f
curl -s "https://api.pictograph.io/api/v1/developer/video/extract-frames/7c1f4a90-2b3d-4e56-8f70-9a1b2c3d4e5f" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY"

Returns VideoExtractionJob

VideoExtractionJob · 9 fields
class VideoExtractionJob(BaseModel):
    """Snapshot of a frame-extraction job."""
    job_id: str
    status: Literal['processing', 'complete', 'failed']
    progress: int = 0
    frames_extracted: int = 0
    total_frames: int = 0
    error: str | None = None
    # The directory the frames went into, once it succeeds.
    directory_path: str | None = None
    # Set when the image quota cut the frames short; the job still completes.
    warning: str | None = None
    # The frames' image ids, once the job is complete.
    image_ids: list[str] | None = None

Once status is complete, image_ids lists the frames, ready for auto_annotate.batch.

wait_for_extraction

Wait for an extraction to be complete or failed.

Source: Video.wait_for_extraction

Arg Type Default Notes
job str required Job id
poll_interval float 3.0 Seconds between checks
timeout float 1800.0 Max seconds to wait
job = client.video.wait_for_extraction(
    job="7c1f4a90-2b3d-4e56-8f70-9a1b2c3d4e5f",
    timeout=600.0,
)
# extract-frames already waits; poll status for a detached job.
pictograph video status <job-id>
curl -s "https://api.pictograph.io/api/v1/developer/video/extract-frames/<job-id>" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY"

Returns VideoExtractionJob

VideoExtractionJob · 9 fields
class VideoExtractionJob(BaseModel):
    """Snapshot of a frame-extraction job."""
    job_id: str
    status: Literal['processing', 'complete', 'failed']
    progress: int = 0
    frames_extracted: int = 0
    total_frames: int = 0
    error: str | None = None
    # The directory the frames went into, once it succeeds.
    directory_path: str | None = None
    # Set when the image quota cut the frames short; the job still completes.
    warning: str | None = None
    # The frames' image ids, once the job is complete.
    image_ids: list[str] | None = None

Common errors

Status Exception Cause
400 ValidationError The file isn’t a readable video
404 NotFoundError The video handle or dataset doesn’t exist
- PollTimeoutError The wait passed timeout; the extraction keeps going
Copied to clipboard