API Sample: Create Highlight Reel for a Conference
In this sample, we'll demonstrate how to upload multiple video files from a conference and generate a highlight reel using the Timeline API, then export the result as an OTIO file.
Overview
- Objective: Create a highlight reel from multiple conference videos.
- APIs Used:
- Asset Management API
- Timeline API
Steps
- Authenticate and set up necessary variables.
- Upload the video files using the Asset Management API.
- Generate a highlight reel using the Timeline API.
- Export the generated timeline as an OTIO file.
Detailed Steps with Code
Step 1: Authenticate and Set Up
Use the same authentication headers as in Sample 1.
import requests
# Replace with your actual API key
API_KEY = 'YOUR_API_KEY'
# Base URLs
BASE_URL = 'https://api.play-video.dev'
# Headers
headers = {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}Step 2: Upload the Video Files
We'll upload 10 conference video files.
a) Create Assets and Upload Files
asset_uuids = []
for i in range(1, 11):
filename = f'conference_video_{i}.mp4'
file_path = f'/path/to/your/{filename}' # Replace with your actual file paths
# Create an asset
create_asset_url = f"{BASE_URL}/asset/create"
create_asset_payload = {
'filename': filename,
'indexer_profile_uuid': 'YOUR_INDEXER_PROFILE_UUID' # Replace with your indexer profile UUID
}
response = requests.post(create_asset_url, headers=headers, json=create_asset_payload)
response.raise_for_status()
asset_response = response.json()
asset_uuid = asset_response['uuid']
s3_presigned_url = asset_response['s3_presigned_url']
print(f"Asset {i} UUID: {asset_uuid}")
# Upload the file to S3
with open(file_path, 'rb') as file_data:
s3_response = requests.put(s3_presigned_url, data=file_data)
s3_response.raise_for_status()
print(f"File {i} uploaded successfully to S3.")
# Add the asset UUID to the list
asset_uuids.append(asset_uuid)Step 3: Generate a Highlight Reel
Use the Timeline API to generate a highlight reel from the uploaded videos.
# Step 3: Generate highlight reel
generate_timeline_url = f"{BASE_URL}/timelines/generate/highlight"
# Request payload
generate_timeline_payload = {
'prompt': 'Create a highlight reel showcasing the best moments of the conference.',
'files': asset_uuids,
'subjects': []
}
timeline_response = requests.post(generate_timeline_url, headers=headers, json=generate_timeline_payload)
timeline_response.raise_for_status()
timeline_data = timeline_response.json()
# Extract the timeline UUID
timeline_uuid = timeline_data['uuid']
print(f"Generated Timeline UUID: {timeline_uuid}")Step 4: Export the Timeline as OTIO
Once the timeline is ready, export it as an OTIO file.
import time
# Optionally, wait for the timeline to be ready
time.sleep(60) # Wait for processing (adjust as necessary)
# Step 4: Export timeline as OTIO
export_timeline_url = f"{BASE_URL}/timelines/{timeline_uuid}/export/otio"
export_response = requests.post(export_timeline_url, headers={'X-API-Key': API_KEY})
export_response.raise_for_status()
# Save the OTIO file
with open('highlight_reel.otio', 'wb') as f:
f.write(export_response.content)
print("Timeline exported as 'highlight_reel.otio'.")Note: Ensure that the timeline processing is complete before attempting to export. You may need to implement polling or wait mechanisms.