Create a simple video from text using the Pictory API with automatic visual selection
This guide shows you how to turn written text into an engaging video with automatically selected visuals. Perfect for creating social media content, educational videos, or marketing materials from your written content.
First, prepare your API credentials and the text you want to convert:
import axios from "axios";const API_BASE_URL = "https://api.pictory.ai/pictoryapis";const API_KEY = "YOUR_API_KEY"; // Replace with your actual API key// Your text content - this will be converted into videoconst SAMPLE_TEXT = "AI is transforming how we create content. By automating video production, " + "creators can focus on strategy while AI handles the technical work. " + "This means faster turnaround times and consistent quality across all videos.";
import requestsimport timeimport jsonAPI_BASE_URL = 'https://api.pictory.ai/pictoryapis'API_KEY = 'YOUR_API_KEY' # Replace with your actual API key# Your text content - this will be converted into videoSAMPLE_TEXT = ( "AI is transforming how we create content. By automating video production, " "creators can focus on strategy while AI handles the technical work. " "This means faster turnaround times and consistent quality across all videos.")
async function waitForVideo(jobId) { console.log("\nMonitoring video creation..."); while (true) { const statusResponse = await axios.get( `${API_BASE_URL}/v1/jobs/${jobId}`, { headers: { Authorization: API_KEY }, } ); const status = statusResponse.data.data.status; console.log("Status:", status); if (status === "completed") { console.log("\n✓ Video is ready!"); console.log("Video URL:", statusResponse.data.data.videoURL); return statusResponse.data; } else if (status === "failed") { throw new Error("Video creation failed: " + JSON.stringify(statusResponse.data)); } // Wait 5 seconds before checking again await new Promise(resolve => setTimeout(resolve, 5000)); }}// Run the complete workflowcreateTextToVideo() .then(jobId => waitForVideo(jobId)) .then(result => console.log("\nDone!")) .catch(error => console.error("Error:", error));
def wait_for_video(job_id): print("\nMonitoring video creation...") while True: response = requests.get( f'{API_BASE_URL}/v1/jobs/{job_id}', headers={'Authorization': API_KEY} ) response.raise_for_status() status = response.json()['data']['status'] print(f"Status: {status}") if status == 'completed': print("\n✓ Video is ready!") print(f"Video URL: {response.json()['data']['videoURL']}") return response.json() elif status == 'failed': raise Exception(f"Video creation failed: {response.json()}") # Wait 5 seconds before checking again time.sleep(5)# Run the complete workflowif __name__ == '__main__': job_id = create_text_to_video() result = wait_for_video(job_id) print("\nDone!")
Analyzes Your Text - Understands the context and key concepts
Breaks Into Scenes - Splits text based on your scene settings
Selects Visuals - Automatically chooses relevant stock images/videos for each scene
Generates Captions - Creates animated text overlays synchronized with the content
Renders Video - Compiles everything into a polished video file
Processing Time: Videos typically take 3-10 minutes to create, depending on length. The API processes asynchronously, so you receive a job ID immediately and can check status periodically.
const lessonText = "Today we'll learn about photosynthesis. " + "Plants convert sunlight into energy. " + "This process produces oxygen for us to breathe.";