Text to Video with Brand Settings

This example demonstrates how to create a video using your saved brand settings. Brand settings include predefined styles, logos, colors, fonts, and other visual elements that maintain consistency across all your videos.

Overview

This example covers:

  • Getting an access token
  • Creating a video using brand settings
  • Using brandId or brandName to apply brand styles
  • Maintaining brand consistency across videos
  • Monitoring job status and retrieving the final video

Node.js Example

Prerequisites

npm install axios

Complete 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";

const STORY_TEXT =
  "AI is poised to significantly impact educators and course creators on social media. By automating tasks like content generation, visual design, and video editing, AI will save time and enhance consistency.";

async function createTextToVideoWithBrand() {
  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 Video with Brand Settings
    console.log("Step 2: Creating video with brand settings...");
    const storyboardResponse = await axios.post(
      `${API_BASE_URL}/v2/video/storyboard/render`,
      {
        videoName: "text_to_video_with_brand",
        brandId: "{YOUR_BRAND_ID}", // Use either brandId or brandName, not both
        // brandName: "{YOUR_BRAND_NAME}",  // Alternative: use brandName instead of brandId
        scenes: [
          {
            story: STORY_TEXT,
            createSceneOnNewLine: false,
            createSceneOnEndOfSentence: false,
          },
        ],
      },
      {
        headers: {
          "Content-Type": "application/json",
          Authorization: accessToken,
        },
      }
    );

    const renderJobId = storyboardResponse.data.data.jobId;
    console.log("Video with brand settings 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 with brand settings 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
createTextToVideoWithBrand();

Python Example

Prerequisites

pip install requests

Complete 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'

STORY_TEXT = "AI is poised to significantly impact educators and course creators on social media. By automating tasks like content generation, visual design, and video editing, AI will save time and enhance consistency."

def create_text_to_video_with_brand():
    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 with Brand Settings
        print('Step 2: Creating video with brand settings...')
        storyboard_response = requests.post(
            f'{API_BASE_URL}/v2/video/storyboard/render',
            json={
                'videoName': 'text_to_video_with_brand',
                'brandId': '{YOUR_BRAND_ID}',  # Use either brandId or brandName, not both
                # 'brandName': '{YOUR_BRAND_NAME}',  # Alternative: use brandName instead of brandId
                'scenes': [
                    {
                        'story': STORY_TEXT,
                        'createSceneOnNewLine': False,
                        'createSceneOnEndOfSentence': False
                    }
                ]
            },
            headers={
                'Content-Type': 'application/json',
                'Authorization': access_token
            }
        )
        storyboard_response.raise_for_status()

        render_job_id = storyboard_response.json()['data']['jobId']
        print('Video with brand settings 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 with brand settings 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_brand()

Key Parameters

  • brandId: The unique identifier of your saved brand (use this OR brandName, not both)
  • brandName: The name of your saved brand (use this OR brandId, not both)

What Brand Settings Include

When you apply a brand to your video, it automatically includes:

  • Logo: Your brand logo with predefined position and size
  • Colors: Brand color palette for text and backgrounds
  • Fonts: Specific font families and sizes
  • Subtitle Styles: Consistent subtitle styling
  • Voice Over: Default voice settings
  • Background Music: Preferred background music
  • Aspect Ratio: Standard aspect ratio for your videos
  • Visual Preferences: Preferred types of stock visuals

Use Cases

  • Maintain consistent branding across all marketing videos
  • Ensure corporate identity in training materials
  • Create multiple videos with the same look and feel
  • Save time by not configuring styles for each video
  • Enforce brand guidelines automatically

Creating a Brand

Before using this API, you need to create a brand in your Pictory account:

  1. Log in to your Pictory account
  2. Navigate to Brand settings
  3. Create a new brand with your preferred settings
  4. Note the Brand ID or Brand Name for API use

Important Notes

  1. Mutual Exclusivity: You cannot provide both brandId and brandName in the same request. Use one or the other.
  2. Brand Override: Brand settings can be overridden by explicitly specifying parameters in the request. For example, if you specify a logo in the request, it will override the brand's logo.
  3. Account Ownership: The brand must belong to your account or be shared with you.

Response

The API returns a job ID for monitoring the video creation progress. Once completed, you'll receive a video URL with all your brand settings applied.

Notes

  • Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your actual API credentials
  • Replace {YOUR_BRAND_ID} with your actual brand ID (e.g., "abc123xyz")
  • Replace {YOUR_BRAND_NAME} with your actual brand name if using brandName instead
  • Using placeholders with curly braces {} indicates user-specific data that must be replaced