How to Extract an Image from a Video using PHP?

When working with video files in your PHP application, it is likely you will want to take a screenshot at a particular point, essentially grabbing a single frame from a video. This is especially true when creating video thumbnails and still previews. If you're using PHP, this is pretty straightforward, requiring only a few lines of code:

Input Code
// Don't forget to install the required library using Composer:
// composer require creatomate/creatomate
$client = new Creatomate\Client('Your API Key');

$output = $client->render([
 'source' => new Creatomate\Source([
  'output_format' => 'jpg',
  'snapshot_time' => 1.94,
  'elements' => [
    'type' => 'video',
    'source' => ''

Output Image

How it works: First, install the Creatomate package from Packagist using Composer. Once installed, you can create a composition that contains a single video element and specify the video URL using the "source" property. By default, the resulting image will have the same resolution as the video, but you can change the image size by adjusting the "width" and "height" properties. You can find an example in the related articles section below.

To capture a JPEG image from the video, set the "output_format" property to "jpg". This will take a snapshot at the time specified by the "snapshot_time" property, which is set to 1.94 seconds from the beginning of the video. If you prefer a PNG image instead, you can use the "png" output format.

If you want, you can also add a logo or text to the output image. Below are some PHP examples of how to do that. Additionally, you can use the online video editor to make your own overlays. Check it out below.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your PHP application to create any kind of video – completely through code.

Related PHP Video Editing Questions

Start automating today

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