php - 使用 PHP-FFmpeg 将多个输入合并为一个
问题描述
我想用 PHP-FFmpeg 将多个视频并排合并到一个视频中,有人帮我吗?
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();
}
上面的代码实际上可以工作,但是自定义过滤器有问题,它只保存了一个输入。
解决方案
如果您想并排使用,请使用hstack过滤器而不是覆盖过滤器。
改变:
->custom('[0]', 'overlay=:x=000:y=000', '[output0]')
->custom('[output0][1]', 'overlay=:x=058:y=000', '[output1]');
到:
->custom('[0][1]', 'hstack', '[output1]');
两个输入的高度必须相同。如果高度不同,则添加 scale、scale2ref、crop 或 pad 过滤器。
如果您想使用覆盖,则需要使用填充过滤器填充第一个视频,以便为第二个视频提供空间。但是这种方法比只使用 hstack 更慢更复杂。
推荐阅读
- 3d - 3d 形状填充连接到 P5.js webGL 上的第一个顶点
- angular - 使用 Angular 7 http 拦截器加载微调器在页面重新加载时不起作用
- ag-grid - AG-GRID 值格式化程序不适用于动态生成的货币
- reactjs - 实现 onSnapshot 函数以获取 reactjs 代码中的实时更新
- javascript - 使用 const 关键字 Javascript 声明数组
- python - OSError:SavedModel 文件不存在于:../dnn/mpg_model.h5/{saved_model.pbtxt|saved_model.pb}
- php - Algolia:使用 CURL (PHP) 获取数据返回的结果与使用 places.js 的示例结果不同
- dart - 在 Dart 中创建一组独特的地图
- java - 如何在 Android 中生成图像的二维码?
- python - 我可以在 fillna() 中使用 for 循环吗?