Text to Video with Scene Transitions

This example demonstrates how to add transition effects between scenes in your video. Transitions provide smooth visual changes when moving from one scene to another.

Overview

This example covers:

  • Getting an access token
  • Adding scene transition effects
  • Understanding available transition types
  • Applying different transitions to different scenes
  • Creating professional-looking video transitions
  • 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_1 = "AI is poised to significantly impact educators and course creators on social media.";
const STORY_TEXT_2 =
  "By automating tasks like content generation, visual design, and video editing, AI will save time and enhance consistency.";
const STORY_TEXT_3 = "This allows creators to focus on higher-level strategies and ensures a cohesive brand presence.";

async function createTextToVideoWithSceneTransitions() {
  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 Scene Transitions
    console.log("Step 2: Creating video with scene transitions...");
    const storyboardResponse = await axios.post(
      `${API_BASE_URL}/v2/video/storyboard/render`,
      {
        videoName: "text_to_video_transitions",
        scenes: [
          {
            story: STORY_TEXT_1,
            createSceneOnNewLine: false,
            createSceneOnEndOfSentence: false,
            sceneTransition: "fade", // Fade transition to next scene
          },
          {
            story: STORY_TEXT_2,
            createSceneOnNewLine: false,
            createSceneOnEndOfSentence: false,
            sceneTransition: "wiperight", // Wipe right transition to next scene
          },
          {
            story: STORY_TEXT_3,
            createSceneOnNewLine: false,
            createSceneOnEndOfSentence: false,
            sceneTransition: "none", // No transition (hard cut)
          },
        ],
      },
      {
        headers: {
          "Content-Type": "application/json",
          Authorization: accessToken,
        },
      }
    );

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

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_1 = "AI is poised to significantly impact educators and course creators on social media."
STORY_TEXT_2 = "By automating tasks like content generation, visual design, and video editing, AI will save time and enhance consistency."
STORY_TEXT_3 = "This allows creators to focus on higher-level strategies and ensures a cohesive brand presence."

def create_text_to_video_with_scene_transitions():
    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 Scene Transitions
        print('Step 2: Creating video with scene transitions...')
        storyboard_response = requests.post(
            f'{API_BASE_URL}/v2/video/storyboard/render',
            json={
                'videoName': 'text_to_video_transitions',
                'scenes': [
                    {
                        'story': STORY_TEXT_1,
                        'createSceneOnNewLine': False,
                        'createSceneOnEndOfSentence': False,
                        'sceneTransition': 'fade'  # Fade transition to next scene
                    },
                    {
                        'story': STORY_TEXT_2,
                        'createSceneOnNewLine': False,
                        'createSceneOnEndOfSentence': False,
                        'sceneTransition': 'wiperight'  # Wipe right transition to next scene
                    },
                    {
                        'story': STORY_TEXT_3,
                        'createSceneOnNewLine': False,
                        'createSceneOnEndOfSentence': False,
                        'sceneTransition': 'none'  # No transition (hard cut)
                    }
                ]
            },
            headers={
                'Content-Type': 'application/json',
                'Authorization': access_token
            }
        )
        storyboard_response.raise_for_status()

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

Available Scene Transitions

Basic Transitions

  • none: No transition, hard cut between scenes
  • fade: Classic fade in/out transition

Wipe Transitions

  • wipeup: Wipe transition moving upward
  • wipedown: Wipe transition moving downward
  • wipeleft: Wipe transition moving left
  • wiperight: Wipe transition moving right

Smooth Transitions

  • smoothleft: Smooth slide transition to the left
  • smoothright: Smooth slide transition to the right

Special Transitions

  • radial: Radial/circular wipe transition
  • circlecrop: Circle crop transition
  • hblur: Horizontal blur transition

Transition Descriptions

none

  • No transition effect
  • Immediate cut from one scene to another
  • Most commonly used for fast-paced content
  • Good for news-style or energetic videos

fade

  • Classic crossfade effect
  • Smooth and professional
  • Works well for all content types
  • Most versatile transition

wipe (up/down/left/right)

  • One scene "wipes away" the previous
  • Directional movement
  • Good for showing progression or change
  • More dramatic than fade

smooth (left/right)

  • Sliding transition between scenes
  • Creates sense of continuity
  • Good for sequential content
  • Modern and clean look

radial

  • Circular wipe from center outward
  • Attention-grabbing
  • Good for reveals or emphasis
  • Works well for promotional content

circlecrop

  • Circle expands to reveal next scene
  • Unique and creative
  • Good for highlighting specific content
  • Best used sparingly

hblur

  • Horizontal blur effect during transition
  • Modern and stylish
  • Good for tech or contemporary content
  • Adds motion feel

Use Cases

Professional/Corporate

sceneTransition: "fade"; // Smooth, professional

Dynamic/Energetic

sceneTransition: "wiperight"; // Fast, directional

Modern/Stylish

sceneTransition: "hblur"; // Contemporary feel

Sequential Content

sceneTransition: "smoothright"; // Shows progression

Best Practices

  1. Consistency: Use the same transition type throughout for cohesive feel
  2. Purpose: Match transition to content mood and pacing
  3. Moderation: Don't overuse dramatic transitions
  4. Context: Consider your audience and content type

Common Transition Patterns

Educational Content

Most scenes: "fade" Chapter breaks: "wipedown"

Marketing/Promo

All scenes: "smoothright" or "wiperight"

News/Information

Most scenes: "none" (quick cuts) Section breaks: "fade"

Creative/Artistic

Mix different transitions for variety

Response

The API returns a job ID for monitoring the video creation progress. Once completed, you'll receive a video URL with smooth transitions between scenes.

Notes

  • Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your actual API credentials
  • Each scene's sceneTransition defines the transition TO THE NEXT scene
  • The last scene's transition is typically ignored (no scene after it)
  • Transition duration is automatically optimized
  • Transitions are applied after the current scene ends