A good way to convert a vertical video to landscape is by adding a background blur. This approach involves filling in the borders of the video by placing a blurred copy in the background. To do this using PHP, you'll need a video editing API. Here's how to blur a video's background in just a few lines of PHP 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' => 'mp4',
'width' => 1920,
'height' => 1080,
'elements' => [
[
'type' => 'video',
'clip' => true,
'color_overlay' => 'rgba(0,0,0,0.15)',
'blur_radius' => 57,
'source' => 'https://cdn.creatomate.com/demo/vertical.mp4',
'volume' => '0%'
],
[
'type' => 'video',
'source' => 'https://cdn.creatomate.com/demo/vertical.mp4',
'fit' => 'contain'
]
]
])
]);
var_dump($output);
How it works: You can use this technique with any video format, whether it's square, portrait, or vertical. It doesn't matter what resolution the video is, as it automatically adjusts to fit the desired output size.
Start by installing the Creatomate library from Packagist using Composer. Once you have the package installed, creating videos becomes as simple as defining a video scene in PHP code.
Firstly, choose the output resolution, such as 1080p (1920 x 1080). Then, specify two video elements. The initial element is the background video with a blur effect, which you can customize by adjusting the "blur_radius" property. You can also add a slight darkening effect using the "color_overlay" property. Remember to mute the video by setting the "volume" property to remove the audio track from the background.
The second element is the foreground video. Ensure that the "fit" property is set to "contain" so that it fits perfectly within the boundaries of the final video. Note that neither element requires a duration to be specified. The output video length is calculated automatically, eliminating the need to manually specify it.
If you prefer a visual editing experience, consider trying out the video editor tool. With this online app, you can design your own video templates interactively and then export them as JSON code for utilization in your PHP projects.