1. Go to this page and download the library: Download buggedcom/phpvideotoolkit 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/ */
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$output_format = new VideoFormat_Mp4();
// attempt to auto rotate the video to the correct orientation (ie mobile phone users - hurgygur)
$output_format->setVideoRotation(true)
->setVideoFrameRate(10)
->setVideoPixelFormat('rgb24')
->setAudioSampleFrequency(44100);
$video->save('output.mp4', $output_format);
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$video->save('output.my_silly_custom_file_extension', new ImageFormat_Jpeg());
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$process = $video->extractFrames(new Timecode(40), new Timecode(50))
->save('./output/big_buck_bunny_frame_%timecode.jpg');
$output = $process->getOutput();
namespace PHPVideoToolkit;
$output_format = new ImageFormat_Jpeg();
/*
OR
$output_format = new VideoFormat();
$output_format->setFrameRate(1);
// optionally also set the video and output format, however if you use the ImageFormat_Jpeg
// output format object this is automatically done for you. If you do not add below, FFmpeg
// automatically guesses from your output file extension which format and codecs you wish to use.
$output_format->setVideoCodec('mjpeg')
->setFormat('image2');
*/
$video = new Video('BigBuckBunny_320x180.mp4');
$process = $video->extractFrames(null, new Timecode(50)) // if null then the extracted segment starts from the begining of the video
->save('./output/big_buck_bunny_frame_%timecode.jpg', $output_format);
$output = $process->getOutput();
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$process = $video->extractFrames(new Timecode(50), null, 1) // if null then the extracted segment goes from the start timecode to the end of the video
->save('./output/big_buck_bunny_frame_%timecode.jpg');
$output = $process->getOutput();
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$process = $video->extractFrames(new Timecode(40), new Timecode(50), '1/60')
->save('./output/big_buck_bunny_frame_%timecode.jpg');
$output = $process->getOutput();
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$process = $video->saveNonBlocking('./output/big_buck_bunny.mov');
// do something else important, db queries etc
while($process->isCompleted() === false)
{
// do something more stuff in a loop.
// doesn't have to be a loop, just an example.
sleep(0.5);
}
if($process->hasError() === true)
{
// an error was encountered, do something with it.
}
else
{
// encoding has completed and no error was detected so
// we can get the output from the process.
$output = $process->getOutput();
}
namespace PHPVideoToolkit;
session_start();
$handler = new ProgressHandlerPortable($_SESSION['phpvideotoolkit_portable_process_id']);
$probe = $handler->probe();
echo json_encode(array(
'finished' => $probe['finished'], // true when the process has ended by interruption, error or success
'completed' => $probe['completed'], // true when the process has ended with a successful encoding that encountered no errors.
'percentage' => $probe['percentage']
));
exit;
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$process = $video->getProcess();
// ... continued from above
$process->addPreInputCommand('-custom-command');
$process->addCommand('-custom-command-with-arg', 'arg value');
$process->addPostOutputCommand('-output-command', 'another value');
// ... now save the output video
$video->save('./your/output/file.mp4');
namespace PHPVideoToolkit;
$video = new Video('BigBuckBunny_320x180.mp4');
$process = $video->getProcess();
$process->setProcessTimelimit(10); // in seconds
try
{
$video->save('output.mp4');
}
catch(FfmpegProcessOutputException $e)
{
echo $e->getMessage(); // Imposed time limit (10 seconds) exceeded.
}