Video editing using PHP
Is it possible to record a voice onto the uploaded video using PHP?开发者_如何转开发
you can use the MLT library and my class. You can download it from this link https://github.com/1fer/mlt
Features
- Cut and join videos
- Join videos with transitions
- 10 ready-made transitions with options
- Customizable Wipe transitions
- Add background audio
- Add watermark
- Add text overlay with options
- Add animated text
- Run rendering on background
- Get rendering progress percent
To install this melt library on server use this command:
sudo apt install melt
take a look at documentation how to use it, for example, to join clips use this code:
require __DIR__ . '/vendor/autoload.php';
$videoProcessing = new Andchir\VideoProcessing([
'melt_path' => '/usr/bin/melt',
'session_start' => true
]);
// Join clips
$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');
// Black color and fade transition
$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');
// Join clips with transition
$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');
// Cut clips and join with transition
$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');
// Add background audio with delay
$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');
// Add watermark
$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');
// Add text overlay
$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');
// Animated text
$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');
// Rendering
$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');
// Start rendering in background
$progressLogPath = $videoProcessing->render();
// Rendering progress
$percent = $videoProcessing->getRenderingPercent();
You can also make some filter effects like in Instagram and so on. Read more here: https://www.mltframework.org/plugins/PluginsFilters/
No you can't, at least not by just using PHP, because PHP in itself doesn't provide the necessary libraries for recording sound and editing videos.
To actually record video and sound you'll need libraries like ffmpeg (there's a handy extension for PHP) for video editing and SoX for sound installed on your server. You can then access these programmes by using the the exec()
function in PHP, for example. The implementation wouldn't be that simple, though.
I'd say no, because I don't know of any Hardware-Layer (Client-Side) for PHP...it might be possible with AJAX, but I don't think so.
But PHP might be able to overlay a video with a provided sound file, that should work if you find a library for that.
Strange idea.
PHP is for server side scripting, but record vioce you can only on client side (need sound card/codec for it)
PHP have nothing for it.
It can be more relative if you'd ask about JavaScript as it client sided.
But still, most ready to use and featurefull thing for such task if Adobe Flash technology.
If you not notice it -- if you right click on some flash banner, you'd see a property page where above other features you can see vioce recording.
Technically you could write a PHP plugin that binds with C libraries for audio/video editing. However, that's probably not the best path. A better option would be to invoke a ffmpeg/mencoder/... process from PHP.
PHP is for server side scripting, but record vioce you can only on client side (need sound card/codec for it)
PHP have nothing for it.
You can use PHP to edit video using a 3rd party service like the Shotstack video editing API. They have a PHP library that lets you perform all sorts of video editing and manipulation.
The library is available as a Composer package so you can install it using:
composer require shotstack/shotstack-sdk-php
The code below is an example of trimming a video clip start and end point:
<?php
require 'vendor/autoload.php';
use Shotstack\Client\Api\EditApi;
use Shotstack\Client\Configuration;
use Shotstack\Client\Model\Edit;
use Shotstack\Client\Model\Output;
use Shotstack\Client\Model\Timeline;
use Shotstack\Client\Model\Track;
use Shotstack\Client\Model\Clip;
use Shotstack\Client\Model\VideoAsset;
$config = Configuration::getDefaultConfiguration()
->setHost('https://api.shotstack.io/stage')
->setApiKey('x-api-key', 'REGISTER FOR A KEY');
$client = new EditApi(null, $config);
$videoAsset = new VideoAsset();
$videoAsset
->setSrc('https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4')
->setTrim(3);
$videoClip = new Clip();
$videoClip
->setAsset($videoAsset)
->setLength(8)
->setStart(0);
$track = new Track();
$track->setClips([$videoClip]);
$timeline = new Timeline();
$timeline->setTracks([$track]);
$output = new Output();
$output
->setFormat('mp4')
->setResolution('hd');
$edit = new Edit();
$edit
->setTimeline($timeline)
->setOutput($output);
$render = $client->postRender($edit)->getResponse();
sleep(30);
$video = $client->getRender($render->getId())->getResponse();
if ($video->getStatus() === 'done') {
echo $video->getUrl();
}
The library is open source but the platform it self is a paid service, with free account options.
精彩评论