Split screen video refers to displaying multiple video clips at the same time, usually cut horizontally and presented side-by-side. In order to create the split screen effect using PHP, you will need a video editing API capable of processing video footage. Here's how to do that using PHP in just a few lines of 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,
'duration' => 6,
'elements' => [
[
'type' => 'video',
'source' => 'https://cdn.creatomate.com/demo/river.mp4',
'x' => '25%',
'width' => '50%'
],
[
'type' => 'video',
'source' => 'https://cdn.creatomate.com/demo/bridge.mp4',
'x' => '75%',
'width' => '50%'
]
]
])
]);
var_dump($output);
How it works: First, install the Creatomate package from Packagist using Composer. We can now set up a split screen video composition in our PHP code. First, decide on the resolution you want for the final video. In this case, we'll go with a 1080p landscape layout (1920 by 1080) and use two input videos.
To show both videos side-by-side, we'll use the "x" and "width" properties. Remember, these positions are based on the center of each video element. So, to make the videos appear on the left and right sides, we'll set their positions to "25%" and "75%". To make sure they take up half of the screen horizontally, we'll set the width to "50%".
Keep in mind that we're only providing the horizontal properties ("x" and "width") and leaving the vertical ones ("y" and "height") as they are. By default, the "y" position and height of an element are set to "50%" and "100%" respectively, so they fill up the whole vertical space. So there is no need to specify those values.
If you want to try different multi-screen layouts (for example, a vertical splitscreen layout rather than a horizontal one), you can use a video editor that lets you easily drag and drop videos into place. Once you're happy with the video setup, the editor will generate the necessary code for your PHP application automatically.