Video editing using PHP – Stack Overflow
![]()
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 AndchirVideoProcessing([ ‘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’ => ’50×0′, ‘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’ => ’50×0′, ‘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/
