I want to merge multiple videos side by side in one video with PHP-FFmpeg, is there anyone help me about that?
public function GENERATE_VIDEO()
{
require_once APPPATH . '/third_party/vendor/autoload.php';
$ffmpeg = FFMpeg\FFMpeg::create([
'ffmpeg.binaries' => APPPATH . '/third_party/ffmpeg',
'ffprobe.binaries' => APPPATH . '/third_party/ffprobe',
]);;
$inputs = array(
'../output/01.webm',
'../output/02.webm',
);
$advancedMedia = $ffmpeg->openAdvanced($inputs);
$ffmpeg->getFFMpegDriver()->listen(new \Alchemy\BinaryDriver\Listeners\DebugListener());
$ffmpeg->getFFMpegDriver()->on('debug', function ($message) {
echo $message . "\n";
});
$advancedMedia = $ffmpeg->openAdvanced($inputs);
$advancedMedia->filters()
->custom('[0]', 'overlay=:x=000:y=000', '[output0]')
->custom('[output0][1]', 'overlay=:x=058:y=000', '[output1]');
$advancedMedia
->map(array('[output1]'), new FFMpeg\Format\Video\WebM(), '../output/output.webm')
->save();
}
Above code is working actually, but there is something wrong with custom filters, it's saving only one input.
Use hstack filter instead of overlay filter if you want side-by-side.
Change:
->custom('[0]', 'overlay=:x=000:y=000', '[output0]')
->custom('[output0][1]', 'overlay=:x=058:y=000', '[output1]');
To:
->custom('[0][1]', 'hstack', '[output1]');
Both inputs must be the same height. If heights are different then add the scale, scale2ref, crop, or pad filters.
If you wanted to use overlay instead you need to pad the first video with the pad filter to provide space for the second video. But this method is slower and more complicated than just using hstack.