gpt4 book ai didi

php - 使用 PHP 编辑视频

转载 作者:行者123 更新时间:2023-12-05 00:50:48 24 4
gpt4 key购买 nike

是否可以使用 PHP 在上传的视频上录制声音?

最佳答案

您可以使用 MLT 库和我的类(class)。你可以从这个链接下载它https://github.com/1fer/mlt

特点

  • 剪切和加入视频
  • 加入带有转场的视频
  • 10 个带有选项的现成过渡
  • 可自定义的删除过渡
  • 添加背景音频
  • 添加水印
  • 使用选项添加文本覆盖
  • 添加动画文字
  • 在后台运行渲染
  • 获取渲染进度百分比

要在服务器上安装这个融化库,请使用以下命令:sudo apt install melt

查看文档如何使用它,例如,加入剪辑使用此代码:

require __DIR__ . '/vendor/autoload.php';

$videoProcessing = new Andchir\VideoProcessing([
'melt_path' => '/usr/bin/melt',
'session_start' => true
]);

//加入剪辑

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['joinClips' => [
$rootPath . '/uploads/tmp/Social.mp4',
$rootPath . '/uploads/tmp/Dog.mp4',
$rootPath . '/uploads/tmp/Swans.mp4'
]])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out1.mp4');

//黑色和淡入淡出过渡

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
'colour:black', ['out' => 24],
$rootPath . '/uploads/tmp/Dog.mp4'
]])
->addOption(['mix' => 25])
->addOption(['mixer' => 'luma'])
->addOption(['inputSource' => [
'colour:black', ['out' => 24]
]])
->addOption(['mix' => 25])
->addOption(['mixer' => 'luma'])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out2.mp4');

//加入带有过渡的剪辑

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Swans.mp4',
$rootPath . '/uploads/tmp/Dog.mp4'
]])
->addOption(['mix' => 25])
->addOption(['mixer' => 'luma'])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out3.mp4');

//剪切剪辑并加入过渡

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Social.mp4', ['in' => 200, 'out' => 275]
]])
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Dog.mp4', ['in' => 50, 'out' => 125]
]])
->addReadyMadeTransition('fade', 25)
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Swans.mp4', ['in' => 50, 'out' => 125]
]])
->addReadyMadeTransition('shiftRightIn', 25, [
'width' => 1280,
'height' => 720
])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out4.mp4');

//延迟添加背景音频

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Swans.mp4', ['in' => 50, 'out' => 125]
]])
->disableAudio()
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Dog.mp4', ['in' => 50, 'out' => 200]
]])
->addReadyMadeTransition('shiftLeftIn', 25)
->addBackgroundAudio($rootPath . '/uploads/tmp/Reformat.mp3', ['in' => 0, 'out' => 150, 'delay' => 50])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out7.mp4');

//添加水印

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Swans.mp4', ['in' => 50, 'out' => 125]
]])
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Dog.mp4', ['in' => 50, 'out' => 200]
]])
->addWatermark($rootPath . '/uploads/tmp/SampleLogo.png', false, [
'distort' => 1
])
->addReadyMadeTransition('shiftLeftIn', 25)
->setOutputVideoOptions($rootPath . '/uploads/tmp/out8.mp4');

//添加文字叠加

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Swans.mp4', ['out' => 120]
]])
->addTextOverlay('This is my best video', true, [
'fgcolour' => '#004fed',
'olcolour' => '#fff200',
'outline' => 3,
'pad' => '50x0',
'size' => 80,
'weight' => 700,
'style' => 'italic',
'halign' => 'center',
'valign' => 'top',
'family' => 'Ubuntu'
])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out10.mp4');

//动画文字

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Swans.mp4', ['out' => 120]
]])
->addTextOverlay('This is my best video', true, [
'pad' => '50x0',
'size' => 80,
'halign' => 'center',
'valign' => 'top',
'family' => 'Ubuntu',
'slideFrom' => 'bottom',
'duration' => 50,
'inOpacity' => 0,
'outOpacity' => 100
])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out11.mp4');

//渲染

$videoProcessing
->setProfile('hdv_720_25p')
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Swans.mp4', ['out' => 120]
]])
->disableAudio()
->addOption(['inputSource' => [
$rootPath . '/uploads/tmp/Dog.mp4', ['out' => 120]
]])
->addReadyMadeTransition('shiftLeftIn', 25)
->addBackgroundAudio($rootPath . '/uploads/tmp/Reformat.mp3', ['out' => 215])
->setOutputVideoOptions($rootPath . '/uploads/tmp/out.mp4');

//在后台开始渲染

$progressLogPath = $videoProcessing->render();  

//渲染进度

$percent = $videoProcessing->getRenderingPercent();

您还可以制作一些滤镜效果,如 Instagram 等。在这里阅读更多: https://www.mltframework.org/plugins/PluginsFilters/

关于php - 使用 PHP 编辑视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1789881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com