PHP code example of tbritz / ffmphp
1. Go to this page and download the library: Download tbritz/ffmphp 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/ */
tbritz / ffmphp example snippets
FFmphp::configure([
'ffmpeg' => 'C:\ffmpeg\ffmpeg.exe',
'ffprobe' => 'C:\ffmpeg\ffprobe.exe',
'timeout' => 0, // default, no timeout (in seconds)
]);
FFmphp::load($infile)
->save('outfile.mp4')
->run();
FFmphp::load($infile)
->save('outfile.mp4', 'FFmphp\Formats\Video\MP4')
->run();
use FFmphp\Formats\Video\MP4;
FFmphp::load($infile)
->save('outfile.mp4', MP4::class)
->run();
FFmphp::load($infile)
->save('outfile.mp3', MP3::class)
->run();
FFmphp::load($file)
->save('thumbnail.jpg')
->run();
FFmphp::load($file)
->save('poster.jpg', Poster::class)
->run();
FFmphp::load($file)
->save('preview-4x3.jpg', TileFourByThree::class)
->run();
FFmphp::load($input)
->save('output.mp4', MP4::class)
->save('output.webm', Webm::class)
->save('output-audio.mp3', MP3::class)
->save('poster.jpg', Poster::class)
->save('preview-5x5.jpg', TileFiveByFive::class)
->run();
use FFmphp\Formats\Video\MP4;
class MP4Anime extends MP4
{
public function build()
{
return parent::build()->withOption('-tune', 'animation');
}
}
use FFmphp\Formats\InteractsWithOutput;
use FFmphp\Formats\OutputFormat;
class MyMP4 implements OutputFormat
{
use InteractsWithOutput;
public function build()
{
return $this->withOptions([
'-vcodec' => 'libx264',
'-acodec' => 'aac',
'-b:a' => '128k',
'-preset' => 'slower',
'-crf' => '26',
'-max_muxing_queue_size' => '9999',
'-movflags' => '+faststart',
'-threads' => '4',
]);
}
}
->save('output.mp4', MyMP4::class)
FFmphp::load($input)
->save('output.mp4', MP4::class)
->toCommand();
$is_hd = true;
FFmphp::load($input)
->save('output.webm', Webm::class)
->when($is_hd, function ($command) {
$command->save('output-1080p.webm', Webm1080p::class);
})
->save('thumbnail.jpg', Thumbnail::class)
->run();
FFmphp::load($input)
->save('output.mp4', MP4::class, ['-preset' => 'veryslow', '-crf' => '28',])
->run();
FFmphp::load($input)
->save('output.mp4', MP4::class, function (StreamBuilder $output) {
return $output->withOption('-preset', 'veryslow')
->withOption('-crf', '28');
})
->run();
FFmphp::load($input)
->save('output.mp4')
->run(function ($time) {
// Logic for notifying users of progress updates
});
FFmphp::raw([
'-y',
'-i',
'input.mp4',
'output.mp4',
])
->run();