Text to Video with Logo

This example demonstrates how to create a video with your logo overlay. You can customize the logo's position and size to match your branding requirements.

Overview

This example covers:

  • Getting an access token
  • Adding a logo to your video
  • Positioning the logo (9 position options)
  • Controlling logo size
  • Understanding logo overlay behavior
  • 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.";
const LOGO_URL = "https://pictory-static.pictorycontent.com/logo-octopus-with-pictory.png";

async function createTextToVideoWithLogo() {
  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 Logo
    console.log("Step 2: Creating video with logo...");
    const storyboardResponse = await axios.post(
      `${API_BASE_URL}/v2/video/storyboard/render`,
      {
        videoName: "text_to_video_with_logo",
        logo: {
          url: LOGO_URL,
          position: "bottom-right", // Position of the logo
          width: "15%", // Logo width as percentage of video width
        },
        scenes: [
          {
            story: STORY_TEXT,
            createSceneOnNewLine: true,
            createSceneOnEndOfSentence: true,
          },
        ],
      },
      {
        headers: {
          "Content-Type": "application/json",
          Authorization: accessToken,
        },
      }
    );

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

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."
LOGO_URL = "https://pictory-static.pictorycontent.com/logo-octopus-with-pictory.png"

def create_text_to_video_with_logo():
    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 Logo
        print('Step 2: Creating video with logo...')
        storyboard_response = requests.post(
            f'{API_BASE_URL}/v2/video/storyboard/render',
            json={
                'videoName': 'text_to_video_with_logo',
                'logo': {
                    'url': LOGO_URL,
                    'position': 'bottom-right',  # Position of the logo
                    'width': '15%'               # Logo width as percentage of video width
                },
                'scenes': [
                    {
                        'story': STORY_TEXT,
                        'createSceneOnNewLine': True,
                        'createSceneOnEndOfSentence': True
                    }
                ]
            },
            headers={
                'Content-Type': 'application/json',
                'Authorization': access_token
            }
        )
        storyboard_response.raise_for_status()

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

Key Parameters

Logo Object

  • url (required): The URL of the logo image file
  • position (optional): Position of the logo on the video
    • "top-left"
    • "top-center"
    • "top-right"
    • "center-left"
    • "center-center"
    • "center-right"
    • "bottom-left"
    • "bottom-center"
    • "bottom-right"
  • width (optional): Logo width as a percentage string (e.g., "15%", "20%")
    • Must be a string between "0%" and "100%"
    • Default varies based on logo dimensions

Logo Position Visual Guide

┌─────────────────────────────────┐
│ top-left    top-center  top-right│
│                                  │
│ center-left center     center-right│
│                                  │
│ bottom-left bottom-center bottom-right│
└─────────────────────────────────┘

Supported Image Formats

  • PNG (recommended for logos with transparency)
  • JPG/JPEG
  • SVG
  • GIF
  • WebP

Best Practices

  1. Use PNG with Transparency: For best results, use PNG format with a transparent background
  2. Appropriate Size: Keep logo width between 10-20% for subtle branding
  3. High Resolution: Use high-resolution logos for better quality
  4. Corner Placement: Bottom-right or bottom-left are most common for watermarks
  5. Contrast: Ensure logo is visible against your video content

Logo Size Guidelines

  • Small/Subtle: 5-10% width
  • Standard: 10-15% width
  • Prominent: 15-25% width
  • Large: 25%+ width

Use Cases

  • Brand watermarking for copyright protection
  • Company logo on marketing videos
  • Channel branding for social media content
  • Product logo placement
  • Event or campaign branding

Logo Persistence

  • The logo appears on all scenes throughout the video
  • Logo maintains the same position and size across scenes
  • Logo is overlaid on top of all other content

Response

The API returns a job ID for monitoring the video creation progress. Once completed, you'll receive a video URL with your logo positioned as specified.

Notes

  • Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your actual API credentials
  • The logo image must be accessible via a public URL
  • Logo aspect ratio is preserved (no stretching or distortion)
  • Logo is rendered as an overlay, not burned into the background
  • For percentage values, always include the "%" symbol as a string (e.g., "15%")