Video to Video - Create Short Clips from Long Videos
This example demonstrates how to create a short video clip (highlight) from a longer video URL. This is perfect for creating social media clips, highlights, or teasers from existing video content.
Overview
This example covers:
- Getting an access token
- Creating a 30-second highlight from a longer video
- Using media repurpose settings to control the output
- Specifying the audio language for transcription
- Monitoring job status and retrieving the final video
Node.js Example
Prerequisites
npm install axiosComplete Code
import axios from "axios";
const API_BASE_URL = "https://api.pictory.ai/pictoryapis";
const CLIENT_ID = "YOUR_CLIENT_ID";
const CLIENT_SECRET = "YOUR_CLIENT_SECRET";
// Video URL to repurpose
const VIDEO_URL = "https://pictory-static.pictorycontent.com/samples/videos/video-editing/VideoEditDemoInput.mp4";
async function createVideoToVideoHighlight() {
try {
// Step 1: Get Access Token
console.log("Step 1: Getting access token...");
const tokenResponse = await axios.post(
`${API_BASE_URL}/v1/oauth2/token`,
{
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
},
{
headers: {
"Content-Type": "application/json",
},
}
);
const accessToken = tokenResponse.data.access_token;
console.log("Access token obtained successfully");
console.log("Token expires in:", tokenResponse.data.expires_in, "seconds\n");
// Step 2: Create Short Video Highlight from Long Video
console.log("Step 2: Creating 30-second video highlight...");
const storyboardResponse = await axios.post(
`${API_BASE_URL}/v2/video/storyboard/render`,
{
videoName: "video_to_video_highlight",
scenes: [
{
videoUrl: VIDEO_URL,
mediaRepurposeSettings: {
highlightLength: 30,
},
audioLanguage: "en-US",
hideSubtitles: false,
},
],
},
{
headers: {
"Content-Type": "application/json",
Authorization: accessToken,
},
}
);
const renderJobId = storyboardResponse.data.data.jobId;
console.log("Video highlight render job created");
console.log("Job ID:", renderJobId, "\n");
// Step 3: Monitor Job Status
console.log("Step 3: Monitoring job status...");
let jobCompleted = false;
let jobResult = null;
while (!jobCompleted) {
const jobStatusResponse = await axios.get(`${API_BASE_URL}/v1/jobs/${renderJobId}`, {
headers: {
Authorization: accessToken,
},
});
const status = jobStatusResponse.data.data.status;
console.log("Current status:", status);
if (status === "completed") {
jobCompleted = true;
jobResult = jobStatusResponse.data;
console.log("\nVideo highlight created successfully!");
console.log("Video URL:", jobResult.data.videoUrl);
} else if (status === "failed") {
throw new Error("Job failed: " + JSON.stringify(jobStatusResponse.data));
} else {
// Wait 5 seconds before checking again
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
return jobResult;
} catch (error) {
console.error("Error:", error.response?.data || error.message);
throw error;
}
}
// Run the function
createVideoToVideoHighlight();Python Example
Prerequisites
pip install requestsComplete Code
import requests
import time
import json
API_BASE_URL = 'https://api.pictory.ai/pictoryapis'
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
# Video URL to repurpose
VIDEO_URL = "https://pictory-static.pictorycontent.com/samples/videos/video-editing/VideoEditDemoInput.mp4"
def create_video_to_video_highlight():
try:
# Step 1: Get Access Token
print('Step 1: Getting access token...')
token_response = requests.post(
f'{API_BASE_URL}/v1/oauth2/token',
json={
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET
},
headers={
'Content-Type': 'application/json'
}
)
token_response.raise_for_status()
access_token = token_response.json()['access_token']
print('Access token obtained successfully')
print(f"Token expires in: {token_response.json()['expires_in']} seconds\n")
# Step 2: Create Short Video Highlight from Long Video
print('Step 2: Creating 30-second video highlight...')
storyboard_response = requests.post(
f'{API_BASE_URL}/v2/video/storyboard/render',
json={
'videoName': 'video_to_video_highlight',
'scenes': [
{
'videoUrl': VIDEO_URL,
'mediaRepurposeSettings': {
'highlightLength': 30
},
'audioLanguage': 'en-US',
'hideSubtitles': False
}
]
},
headers={
'Content-Type': 'application/json',
'Authorization': access_token
}
)
storyboard_response.raise_for_status()
render_job_id = storyboard_response.json()['data']['jobId']
print('Video highlight render job created')
print(f'Job ID: {render_job_id}\n')
# Step 3: Monitor Job Status
print('Step 3: Monitoring job status...')
job_completed = False
job_result = None
while not job_completed:
job_status_response = requests.get(
f'{API_BASE_URL}/v1/jobs/{render_job_id}',
headers={
'Authorization': access_token
}
)
job_status_response.raise_for_status()
status = job_status_response.json()['data']['status']
print(f'Current status: {status}')
if status == 'completed':
job_completed = True
job_result = job_status_response.json()
print('\nVideo highlight created successfully!')
print(f"Video URL: {job_result['data']['videoUrl']}")
elif status == 'failed':
raise Exception(f"Job failed: {json.dumps(job_status_response.json())}")
else:
# Wait 5 seconds before checking again
time.sleep(5)
return job_result
except requests.exceptions.RequestException as error:
print(f'Error: {error}')
if hasattr(error, 'response') and error.response is not None:
print(f'Response: {error.response.text}')
raise
# Run the function
if __name__ == '__main__':
create_video_to_video_highlight()Key Parameters
- videoUrl: The full URL of the video file to repurpose (max 3000 characters, must be a valid URI)
- mediaRepurposeSettings: Configuration for video repurposing
- highlightLength: Length of the highlight in seconds (5-180 seconds)
- removeFillerWords (optional): Remove filler words like "um", "uh", etc.
- removeSilences (optional): Remove silent portions from the video
- silenceThresholdSeconds (optional): Minimum silence duration to remove (0-10 seconds)
- audioLanguage: The language of the video's audio (required for transcription)
- hideSubtitles: Whether to hide subtitles in the output video (default: false)
How It Works
- The API fetches the video file from the provided URL
- The audio is transcribed and analyzed
- The most engaging or important segments are identified
- A highlight clip of the specified length is created
- Optionally, filler words and silences are removed for better pacing
- The final short video is generated with subtitles (if enabled)
Use Cases
- Create social media clips from long-form content
- Generate video highlights for YouTube Shorts, Instagram Reels, TikTok
- Extract key moments from webinars or presentations
- Create teasers from full videos
- Repurpose long videos into bite-sized content
- Automatically edit videos for better engagement
Advanced Features
Remove Filler Words
mediaRepurposeSettings: {
highlightLength: 30,
removeFillerWords: true
}Remove Silences
mediaRepurposeSettings: {
highlightLength: 30,
removeSilences: true,
silenceThresholdSeconds: 2 // Remove silences longer than 2 seconds
}Combine Multiple Features
mediaRepurposeSettings: {
highlightLength: 30,
removeFillerWords: true,
removeSilences: true,
silenceThresholdSeconds: 1.5
}Response
The API returns a job ID for monitoring the video creation progress. Once completed, you'll receive a video URL containing the repurposed short video clip.
Notes
- Replace
YOUR_CLIENT_IDandYOUR_CLIENT_SECRETwith your actual API credentials - The video file must be accessible via a public URL
- Supported video formats include MP4, MOV, AVI, and other common formats
- The
audioLanguageparameter is required for accurate transcription and highlight detection - The
highlightLengthmust be between 5 and 180 seconds - The API uses AI to identify the most engaging segments automatically
Updated about 15 hours ago
