PHP code example of javer / ffmpeg-transformer
1. Go to this page and download the library: Download javer/ffmpeg-transformer library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
javer / ffmpeg-transformer example snippets
$command = (new Command())
->overwriteOutputFiles();
$inputFile = $command->addInput('input.mov');
$command->addOutput('output.mp4')
->moveHeaderToStart()
->addVideoStream($inputFile->getVideoStream())
->codec('libx264')
->preset('veryfast')
->pixelFormat('yuv420p')
->end()
->addAudioStream($inputFile->getAudioStream())
->codec('aac')
->end();
$ffmpeg = new FFMpeg\FFMpeg(...);
$inputVideo = $ffmpeg->open($filename);
$inputMediaProfile = MediaProfile::fromMedia($inputVideo);
$referenceMediaProfile = MediaProfile::fromArray([
'name' => 'reference',
'format' => 'mp4',
'video' => [
'width' => 1920,
'height' => 1080,
'codec' => 'h264',
'profile' => 'main',
'preset' => 'veryfast',
'pixel_format' => 'yuv420p',
'bitrate' => '6000k',
'frame_rate' => 29.97,
'keyframe_interval' => 250,
],
'audio' => [
'codec' => 'aac',
'bitrate' => '128k',
'sample_rate' => '48k',
],
]);
$transformation = (new ProfileTransformer())
->transformMedia($sourceMediaProfile, $referenceMediaProfile);
$command = (new CommandTransformer())
->applyTransformation($transformation, $inputFilename, $outputFilename);
$ffmpeg->getFFMpegDriver()->command($command->build());