Upload media with python
This tutorial will guide you through uploading media using tator-py. We assume you already have a project with a video type configured.
Get video type ID
Every media object in Tator is associated to a media type. Typically a project will have one or two media types, for example one for images and one for videos, but there is no hard limit. You can view all of the available media types for a project using tator-py:
import tator
api = tator.get_api(host='https://cloud.tator.io', token=MY_TOKEN)
media_types = api.get_media_type_list(PROJECT_ID)
print(media_types)
Media types can also be viewed in the UI. First click on the project settings button:
Then click on the media type in the left panel. The media type ID is displayed in the title.
Upload a video
We can use a utility in tator-py to easily upload local media to Tator called upload_media
. This function returns a generator that yields progress and, upon upload completion, a response from a POST
to the Transcode
or Media
endpoint, depending on if we upload a video or image.
for progress, response in tator.util.upload_media(api, VIDEO_TYPE_ID, MEDIA_PATH):
print(f"Upload progress for {MEDIA_PATH}: {progress}%")
print(response.message)
Once this code executes, the full original video has been uploaded and a transcode has been initiated on the backend. If desired, the transcode status can be monitored by polling:
while True:
job = api.get_job(response.uid)
if job.status == 'Succeeded':
print(f"Transcode finished!")
break
elif job.status == 'Failed':
print(f"Transcode failed!")
break
else:
print(f"Transcode still in progress...")
time.sleep(5)