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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With