How to Automate Video Generation with PHP

23 May 2025 | 8 min read
Laura van Sinderen

In this tutorial, you'll learn how to create videos programmatically using PHP and Creatomate's video generation API.

If you've worked with video in PHP before, you've probably used command-line tools like FFmpeg via exec() or libraries like "PHP-FFmpeg" for basic editing tasks. These solutions work well for trimming clips or stitching together simple videos, but they quickly become limiting when you're looking to automate more complex content – like generating social media videos, personalized video messages, or integrate AI tools such as ChatGPT, ElevenLabs, or DALL·E.

That's where Creatomate comes in: a powerful, cloud-based video generation API that simplifies dynamic video creation. Whether you're building backend tools, automating marketing content, or integrating generative AI into your video pipeline, Creatomate integrates seamlessly with PHP applications. It's especially useful for web developers using frameworks like Laravel, Symfony, or custom PHP setups who need to generate videos on demand.

In this tutorial, I'll walk you through the fundamentals of video automation using PHP and Creatomate. By the end, you'll have a solid starting point for building your own automated video workflows. I'll also point you to follow-up tutorials that explore more advanced techniques – including AI voiceovers, animated subtitles, generated visuals, and more.

The example video we'll create is just a glimpse of what's possible. From simple slideshows to highly dynamic, data-driven videos, Creatomate's online template editor and flexible REST API give you full control to customize and automate video content in whatever way you need.

Prerequisites

Before you begin, make sure you have the following:

  • PHP installed. If you don't have it yet, you can download it from the official PHP website or use a package manager like Homebrew (for macOS) or a pre-packaged solution like XAMPP or WAMP (for Windows). PHP 7.4 or higher is recommended.
  • a Creatomate account. Sign up for a free account if you don't already have one.
  • a terminal or code editor. Any environment where you can run PHP scripts will work.

How to create videos using PHP?

There are two main ways to generate videos with PHP and Creatomate.

The simplest and most common method is to use a template. You design the video layout once, then use your PHP script to insert dynamic content – like text, images, audio files, or video clips – creating a unique video each time. This approach is ideal for automating video creation at scale, and it's the one we'll focus on in this tutorial.

Alternatively, you can build videos entirely through code, without using a predefined template. This gives you full control over every detail of the video, including layout, animations, and timing. By writing a bit of JSON, you can define the entire video structure directly within your PHP app. This method is perfect for advanced, fully dynamic, data-driven video generation. If you're interested, explore the JSON to Video documentation to learn more.

1. Set up your PHP project

First, create a new directory for your project. Open your terminal or command prompt and run:

$ mkdir video_creation_project

Then, navigate into it:

$ cd video_creation_project

Next, create a new PHP file where you'll write your code. We'll name it generate_video.php for consistency.

On macOS or Linux:

$ touch generate_video.php

On Windows:

$ echo. > generate_video.php

Note: For this tutorial, we'll use PHP's built-in cURL functionality to communicate with the Creatomate API. This means you don't need to install any external libraries, but you do need to make sure that cURL is enabled in your PHP installation (it is enabled by default in most modern setups).

Your PHP project is now set up and ready to go. In the next step, we'll create a video template in Creatomate that we'll use to generate our video.

2. Create a video template in Creatomate

Log in to your Creatomate account, or sign up for free if you don't have one yet.

Next, navigate to the Templates page and click New to open the template gallery. You can either start from scratch if you have a specific design in mind, or choose a pre-made template for a faster setup. To keep things simple for this tutorial, select the Quick Promo template from the Featured category. Then, choose the 9:16 Vertical size and click Create Template to open it in the editor:

Let's take a closer look at the video template and how it will be used in your PHP script.

On the left side of the editor, you'll find all the elements that make up the template. Some elements, like Video, Text-1, and Text-2, are marked as dynamic. This means you can customize these parts for each video you generate by programmatically inserting different text or media through your script.

You can fully customize your template to fit your exact needs. The editor offers a wide range of options and is intuitive for anyone familiar with video editing tools. If you want to explore the editor further, check out this quick guide.

Once you're happy with your video design, let's move on.

3. Generate the PHP script

In this step, we'll turn our template into an API request.

Click the Use Template button in the top-right corner of the template editor, then select API Integration:

Creatomate offers ready-to-use code snippets in multiple programming languages. Select PHP from the options, then copy the provided code:

Next, paste it into the empty file generate_video.php that you created earlier. In the next step, you'll learn how to pass dynamic data into your video through the PHP code.

4. Insert video content

Now you can customize the content (text, media, etc.) of each video render using the “modifications” parameter.

You can modify this data in any way you like – including using dynamic inputs from your own scripts. To keep things simple for this tutorial, we'll use some predefined test data.

Copy and paste this into your PHP script:

$data = [
  'template_id' => 'your_template_id',
  'modifications' => [
    'Video.source' => 'https://cdn.creatomate.com/demo/video5.mp4',
    'Text-1.text' => 'Hello PHP users 👋',
    'Text-2.text' => 'It\'s easy to create videos from your own scripts!'
  ]
];

Note: Make sure to replace 'your_template_id' with your actual template ID from step 2. This tells the API which template to use when generating the video.

5. Run the script to create a video

With your script ready, run it using the following command:

$ php generate_video.php

After you send the API request, Creatomate will return a JSON response confirming that your request was received. The video will begin processing shortly. The response will look something like this:

1[
2  {
3    "id": "5cfb5ddb-3405-437c-99c6-9998b3983ca6",
4    "status": "planned",
5    "url": "https://f002.backblazeb2.com/file/creatomate-c8xg3hsxdu/5cfb5ddb-3405-437c-99c6-9998b3983ca6.mp4",
6    "snapshot_url": "https://f002.backblazeb2.com/file/creatomate-c8xg3hsxdu/5cfb5ddb-3405-437c-99c6-9998b3983ca6-snapshot.jpg",
7    ...
8  }
9]

There are two ways to wait for your video to finish rendering:

1. Polling the status
You can write a small PHP script that makes periodic GET requests to the API, checking if the "status" has changed to "succeeded".

2. Using a webhook (recommended)
With webhooks, Creatomate will automatically notify your application as soon as the video is ready, so you don't have to keep checking manually.

For now, after running your script, wait about a minute, then visit the URL returned in the API response. If you see a “Not Found” message, the video is still processing – just wait a bit longer and refresh the page. Once it's done, the URL will show your finished video:

Now that you have the video link, you can download it, embed it, or integrate it directly into your automation workflow – whichever works best for you.

Tip: You can track all your API requests on the API Log page in your Creatomate dashboard. If a video fails to render, the log will display error messages and suggested solutions to help you troubleshoot.

What's next for video creation with PHP

And that's how to create videos using PHP and Creatomate. Now that you've learned the basics, you can customize this workflow to suit your own projects and use cases.

As mentioned at the beginning, you can take things further by integrating generative AI into your video creation process. Think of the faceless, short-form videos you often see on platforms like YouTube, TikTok, and Instagram – these can be fully automated using AI tools.

Start by asking ChatGPT to generate a script based on a topic or keyword. Then, use a text-to-speech tool like ElevenLabs to turn that script into an AI voiceover. With Creatomate's auto-transcription feature, you can automatically add animated captions in trending social media styles. For background visuals, generate images using tools like DALL·E or Stable Diffusion. And for easier publishing, let ChatGPT generate the video's title, description, and hashtags as well.

Here are some helpful tutorials and examples to dive deeper. While they aren't PHP-specific, the concepts are easy to adapt to your PHP setup.

👉 How to Create AI Voice Over Videos using an API
👉 Using ChatGPT's API to Auto-Create Social Media Videos by Code
👉 How to Automate AI-Generated Shorts, Stories, and Reels

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free