How to Resize Video Dimensions in PHP

Cloudmersive
2 min readApr 12, 2023

--

Whether you’re looking to improve web page loading speeds or refine your website’s aesthetic cohesion, resizing your videos is a great way to get the job done.

Thankfully, with the help of our Video Resizing API, you can quickly customize the height and width of all your video uploads with simple request parameters. You can use this service to accomplish a lot more than just that, too; optional request parameters can be used to specify the frame rate, quality, and exact file extension of your video.

Simply follow steps below to quickly take advantage of this API with ready-to-run PHP code examples, or feel free to find additional code examples on our swagger documentation page.

First, let’s install the client SDK using Composer by executing the following command from the command line:

composer require cloudmersive/cloudmersive_video_api_client

After that, let’s copy in the below code examples and provide our API key (you can get one for free by registering a free account on our website). If our videos are consistently larger than 2 GB in size, we can use the $file_url request parameter instead of the $input_file parameter.

<?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.
$frame_rate = 56; // int | Optional; Specify the frame rate of the output video. Defaults to original video frame rate.
$quality = 56; // int | Optional; Specify the quality of the output video, where 100 is lossless and 1 is the lowest possible quality with highest compression. Default is 50.
$extension = "extension_example"; // string | Optional; Specify the file extension of the input video. This is recommended when inputting a file directly, without a file name. If no file name is available and no extension is provided, the extension will be inferred from the file data, which may cause a different extension to be used in the output.

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

Now you can easily structure each request however you’d like. Easy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet