Skip to main content

Extract frames and video clips

Because Tator transcodes videos into a format that facilitates fast random access, individual video frames and video clips can be retrieved using normal REST API calls. This tutorial will walk through how to retrieve individual frames from a video, then how to retrieve video clips using tator-py. To get started you will need the media ID of the videos you want to extract frames from.

Retrieve video frames

Individual video frames can be downloaded using the API method get_frame. A temporary file path is automatically created where the file is stored in PNG format. This function is capable of retrieving multiple frames at once and tiling them, but since this can cause much longer (non-linearly scaling) response times it is generally recommended to retrieve one frame at a time.

import tator
api = tator.get_api(host='', token=MY_TOKEN)
img_paths = []
for frame in [0, 100, 200]:
img_path = api.get_frame(VIDEO_ID, frames=[frame])

Retrieve video clip

Parts of a video can be extracted into a clip using the API method get_clip. The clip is stored server side in a TemporaryFile object, which can be downloaded with the utility download_temporary_file.

clip = api.get_clip(VIDEO_ID, frame_ranges=['0:200'])
for progress in tator.util.download_temporary_file(api, clip.file, '/tmp/my_clip.mp4'):
print(f"Video clip download progress: {progress}%")