How to Create PNG Still Frames from a Video File in PHP

Cloudmersive
2 min readApr 14, 2023

--

If you’re creating slides or thumbnails for video uploads, converting your files to PNG still frames will provide a variety of great options to choose from. With the API solution provided below, you can easily convert video uploads to PNG still frames in one simple step & use minimal code in the process.

To install the client SDK, we can run the following command:

composer require cloudmersive/cloudmersive_video_api_client

With that out of the way, we can now copy from the following ready-to-run PHP Code examples to structure our API call:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\VideoApi(


new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.
$file_url = "file_url_example"; // string | Optional; URL of a video file being used for conversion. Use this option for files larger than 2GB.
$max_width = 56; // int | Optional; Maximum width of the output video, up to the original video width. Defaults to original video width.
$max_height = 56; // int | Optional; Maximum height of the output video, up to the original video width. Defaults to original video height.
$frames_per_second = 8.14; // float | Optional; How many video frames per second to be returned as PNG images. Minimum value is 0.1, maximum is 60. Default is 1 frame per second. Maximum of 2000 total frames.

try {
$result = $apiInstance->videoConvertToStillFrames($input_file, $file_url, $max_width, $max_height, $frames_per_second);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling VideoApi->videoConvertToStillFrames: ', $e->getMessage(), PHP_EOL;
}
?>

To authenticate our request for free (with a limit of 800 API calls per month), we can provide our free-tier API key in the $config line. To get one, simply register a free account on our website.

That’s all there is to it!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet