Upload single videos
This guide shows how you can upload a video file to the platform. The platform offers the following options for uploading single videos:
- Upload from the local file system: Use this option to upload a single video file from the local file system.
- Upload from a direct URL: Use this option to upload a video file from a publicly accessible URL. The platform will retrieve the file directly from the specified URL, so your application doesn’t have to store the video locally and upload it.
Notes
- The platform supports uploading video files that can play without additional user interaction or custom video players. Ensure your URL points to the raw video file, not a web page containing the video. Links to third-party hosting sites, cloud storage services, or videos requiring extra steps to play are not supported.
- The ability to upload videos from YouTube is no longer supported.
Prerequisites
- You’re familiar with the concepts described on the Platform overview page.
- You have an API key. To retrieve your API key, navigate to the API Key page and log in with your credentials. Then, select the Copy icon to the right of your API key to copy it to your clipboard.
- You’ve already created an index.
- The video you wish to upload must meet the following requirements:
- Video resolution: Must be at least 360x360 and must not exceed 3840x2160.
- Aspect ratio: Must be between 1:1 and 16:9.
- Video and audio formats: The video files you wish to upload must be encoded in the video and audio formats listed on the FFmpeg Formats Documentation page. Note: HLS(live streaming) videos can only be uploaded using the API. For videos in other formats, contact us at support@twelvelabs.io.
- Duration: For Marengo, it must be between 4 seconds and 2 hours (7,200s). For Pegasus, it must be between 4 seconds and 60 minutes (3600s). In a future release, the maximum duration for Pegasus will be 2 hours (7,200 seconds).
- File size: Must not exceed 2 GB. If you require different options, contact us at support@twelvelabs.io.
- Audio track: If the
audio
model option is selected, the video you’re uploading must contain an audio track.
Procedure
Depending on your use case:
Upload from the local file system
Upload from a direct URL
Invoke the create
method of the task
object with the following parameters:
index_id
: A string representing the unique identifier of the index to which you want to upload your video.file
: A string representing the path to your video file (example:"/videos/01.mp4"
).- (Optional)
transcription_file
: A string representing the path to your transcription file (example:"/videos/01.srt"
)
The TwelveLabs Video Understanding Platform requires some time to index videos. You can search or summarize your videos only after the indexing process is complete. To monitor the indexing process, call the wait_for_done
method of the task
object with the following parameters:
sleep_interval
: A number specifying the time interval, in seconds, between successive status checks. In this example, the method checks the status every five seconds. Adjust this value to control how frequently the method checks the status.callback
: A callback function that the SDK executes each time it checks the status. In this example,on_task_update
is the callback function. Note that the callback function takes a parameter of typeTask
. Use this parameter to display the status of your video indexing task.
Notes
- The
task
object contains, among other information, a field namedvideo_id
, representing the unique identifier of your video. For a description of each field in the request and response, see the Create a video indexing task page. - For details about the possible statuses, see the Task object page.
- You can also use webhooks to monitor the status of the indexing process. For details, see the Webhooks section.
Provide custom metadata
Metadata includes technical and contextual information about each video uploaded to the platform. By default, all the videos have the following metadata associated with them:
duration
: The duration of the video, expressed in secondsfilename
: The filenamefps
: The number of frames per secondheight
: The height of the videosize
: The size of the video file, expressed in KBvideo_title
: The title of the video (defaults to the file name)width
: The width of the video
Custom metadata allows you to add more data to your videos, providing more detailed, specialized, or context-specific information. You can use custom metadata to filter search results or videos.
The values you provide must be of the following types: string
, integer
, float
or boolean
. If you want to store other types of data such as objects or arrays, you must convert your data into string values.
Once the platform has finished indexing your videos, you can provide custom metadata by invoking the update
method of the index.video
object with the following parameters:
index_id
: A string representing the unique identifier of the index containing the video for which you want to provide custom metadata.id
: A string representing the unique identifier of the videouser_metadata
: A dictionary containing your custom metadata. In this example, themetadata
dictionary has four keys:views
,downloads
,language
andcountry
. Theviews
anddownloads
keys are integers, and thecreation_date
andcountry
keys are strings.