Text to Video with Custom Visual Search Filters per Scene
This example demonstrates how to create a video where each scene has custom visual search filters. By providing a category and media search query for each scene, you can precisely control which visuals are selected, ensuring the best match for your content.
Overview
This example covers:
- Getting an access token
- Creating multiple scenes with individual story sentences
- Applying custom visual search filters per scene with category and query
- Understanding how search filters influence visual selection
- 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";
async function createTextToVideoWithSearchFilters() {
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");
// Step 2: Create Video Storyboard with Custom Visual Search Filters
console.log("Step 2: Creating video storyboard with custom visual search filters...");
const storyboardResponse = await axios.post(
`${API_BASE_URL}/v2/video/storyboard/render`,
{
videoName: "text_to_video_custom_visual_search_filters",
scenes: [
{
story: "The mountain ranges provide breathtaking views and challenging hiking trails.",
background: {
searchFilter: {
category: "Nature/Landscapes",
query: "majestic mountain peaks with hiking trails and scenic overlooks",
},
},
},
{
story: "Marine life thrives in the vibrant coral reefs of tropical waters.",
background: {
searchFilter: {
category: "Animals/Marine_Life",
query: "colorful coral reef with diverse fish and marine animals swimming",
},
},
},
{
story: "Modern technology is transforming the way we work and communicate.",
background: {
searchFilter: {
category: "Technology/Innovation",
query: "advanced technology devices and innovative digital interfaces",
},
},
},
{
story: "Urban landscapes showcase impressive architectural designs and city life.",
background: {
searchFilter: {
category: "Places_and_Landmarks/Urban_Areas",
query: "modern city skyline with skyscrapers and urban architecture",
},
},
},
{
story: "Professional athletes demonstrate exceptional skills in competitive sports.",
background: {
searchFilter: {
category: "Sports_and_Recreation/Team_Sports",
query: "professional athletes competing in team sports action shots",
},
},
},
],
},
{
headers: {
"Content-Type": "application/json",
Authorization: accessToken,
},
}
);
const renderJobId = storyboardResponse.data.data.jobId;
console.log("Storyboard render job created with custom visual search filters");
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 with custom visual search filters 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
createTextToVideoWithSearchFilters();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'
def create_text_to_video_with_search_filters():
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 Video Storyboard with Custom Visual Search Filters
print('Step 2: Creating video storyboard with custom visual search filters...')
storyboard_response = requests.post(
f'{API_BASE_URL}/v2/video/storyboard/render',
json={
'videoName': 'text_to_video_custom_visual_search_filters',
'scenes': [
{
'story': 'The mountain ranges provide breathtaking views and challenging hiking trails.',
'background': {
'searchFilter': {
'category': 'Nature/Landscapes',
'query': 'majestic mountain peaks with hiking trails and scenic overlooks'
}
}
},
{
'story': 'Marine life thrives in the vibrant coral reefs of tropical waters.',
'background': {
'searchFilter': {
'category': 'Animals/Marine_Life',
'query': 'colorful coral reef with diverse fish and marine animals swimming'
}
}
},
{
'story': 'Modern technology is transforming the way we work and communicate.',
'background': {
'searchFilter': {
'category': 'Technology/Innovation',
'query': 'advanced technology devices and innovative digital interfaces'
}
}
},
{
'story': 'Urban landscapes showcase impressive architectural designs and city life.',
'background': {
'searchFilter': {
'category': 'Places_and_Landmarks/Urban_Areas',
'query': 'modern city skyline with skyscrapers and urban architecture'
}
}
},
{
'story': 'Professional athletes demonstrate exceptional skills in competitive sports.',
'background': {
'searchFilter': {
'category': 'Sports_and_Recreation/Team_Sports',
'query': 'professional athletes competing in team sports action shots'
}
}
}
]
},
headers={
'Content-Type': 'application/json',
'Authorization': access_token
}
)
storyboard_response.raise_for_status()
render_job_id = storyboard_response.json()['data']['jobId']
print('Storyboard render job created with custom visual search filters')
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 with custom visual search filters 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_text_to_video_with_search_filters()Key Parameters
Scene Object
- story: The text content for the scene that will also be used for AI understanding and subtitle generation
- background: Configuration for the scene's background visual
Background Search Filter
- searchFilter: Configuration to control which visuals are selected
- category (optional): Specific visual category to search within (see categories below)
- query (optional): Media search query that influences visual selection to find the best match
Supported Visual Categories
The API supports a wide range of visual categories to help you find the perfect match:
Aerial
Aerial/Coastal_and_MarineAerial/InfrastructureAerial/Natural_LandscapesAerial/Urban_Landscapes
Animals
Animals/Farm_AnimalsAnimals/Marine_LifeAnimals/PetsAnimals/Wildlife
Business and Professions
Business_and_Professions/Business_ConceptsBusiness_and_Professions/Office_WorkBusiness_and_Professions/Professions
Effects
Effects/Chemical_ReactionsEffects/ExplosionsEffects/Fire_and_SmokeEffects/GlitchesEffects/Lighting_EffectsEffects/Particles
Food and Beverage
Food_and_Beverage/BeveragesFood_and_Beverage/Food_PreparationFood_and_Beverage/Meals
Graphics
Graphics/BackgroundsGraphics/EffectsGraphics/Patterns
Nature
Nature/LandscapesNature/Plants_and_TreesNature/Sunrises_and_SunsetsNature/WaterfallsNature/Weather
People
People/ActivitiesPeople/GroupsPeople/Portraits
Places and Landmarks
Places_and_Landmarks/Rural_AreasPlaces_and_Landmarks/Tourist_AttractionsPlaces_and_Landmarks/Urban_Areas
Sports and Recreation
Sports_and_Recreation/Individual_SportsSports_and_Recreation/Outdoor_ActivitiesSports_and_Recreation/Team_Sports
Technology
Technology/DevicesTechnology/Innovation
And many more categories...
How Search Filters Work
-
Category Filtering: When you specify a category, the visual search is restricted to that specific category, ensuring you get visuals that match the theme.
-
Query Enhancement: The query parameter acts as a media search query that helps identify the best visual for the scene. It provides specific details about what you're looking for, making the visual selection more accurate.
-
Combined Effect: When both category and query are used together, you get highly targeted visual results:
- Category narrows down the type of content
- Query refines the specific visual characteristics
Best Practices
-
Be Specific with Queries:
- Use descriptive language in your queries
- Include details about mood, action, or specific elements you want
- Example: Instead of "mountain", use "majestic mountain peaks with hiking trails"
-
Choose Appropriate Categories:
- Select categories that align closely with your content
- Use subcategories for more precise results
- Example: Use
Animals/Marine_Lifeinstead of justAnimalsfor ocean content
-
Consistency:
- Maintain consistent visual themes across related scenes
- Use similar categories for scenes that should have cohesive visuals
Response
The API returns a job ID for monitoring the video creation progress. Once completed, you'll receive a video URL with visuals precisely matched to your search filters.
Notes
- Replace
YOUR_CLIENT_IDandYOUR_CLIENT_SECRETwith your actual API credentials - Both category and query are optional, but using them together provides the best results
- The query parameter is particularly powerful for getting specific visual characteristics
- Categories help narrow down the visual pool, while queries refine the exact match
- You can use different categories and queries for each scene to create diverse, targeted visuals
Updated about 3 hours ago
