How to Blur the Background of a Video using PHP?

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:

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' => 'mp4',
  'width' => 1920,
  'height' => 1080,
  'elements' => [
    'type' => 'video',
    'clip' => true,
    'color_overlay' => 'rgba(0,0,0,0.15)',
    'blur_radius' => 57,
    'source' => '',
    'volume' => '0%'
    'type' => 'video',
    'source' => '',
    'fit' => 'contain'

Output Video

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.

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