packet / ffmpeglib
FFMpeg 库
2.0.1
2020-09-15 08:00 UTC
Requires
- symfony/finder: ^5.1
- symfony/process: ^5.1
Requires (Dev)
- symfony/filesystem: ^5.1
- symfony/var-dumper: ^5.1
This package is auto-updated.
Last update: 2024-09-15 17:04:21 UTC
README
FFMPEG 库,对任何人开放。
这个库是为了个人使用而创建的,但如果你想使用它,请随意使用 :)。要使用它,你需要深入了解并查看函数的功能,因为它是个人使用,所以我不会记录所有内容。
如何使用
首先你需要所有这些库来使用它
use FFMpegLib\Initializer;
use FFMpegLib\Executor\Executor;
use FFMpegLib\Commands\VideoDurationCommand;
use FFMpegLib\Commands\CreateImagesCommand;
use FFMpegLib\Commands\GifCommand;
use FFMpegLib\FileFinder\FileFinder;
然后你需要初始化它
Initializer::initializeFFMpeg();
你可以用以下方法获取视频时长
$videoDurationCommand = new VideoDurationCommand('video.flv', APP_PATH);
Executor::executeCommand($videoDurationCommand);
$videoDurationCommand->getDuration(); // it returns an instance of Time
创建适合 GIF 的图像
$imagesPath = APP_PATH . '/assets/images/image.png';
$videoPath = APP_PATH . '/assets/videos/video.flv';
$createImagesCommand = new CreateImagesCommand(
$videoPath,
$imagesPath,
'00:30:40',
'00:0:03',
$videoDurationCommand->getDuration());
Executor::executeCommand($createImagesCommand);
请注意,你需要自己删除图像,因为该选项尚未实现
你可以用以下方法创建 GIF
$gifCommand = new GifCommand(APP_PATH . '/assets/images/image.png', APP_PATH . '/assets/images/t.gif');
Executor::executeCommand($gifCommand);
除了获取时长之外,每个命令都需要指定视频的完整路径,在那里我使用了一个查找器作为基本路径,但你也可以直接传递完整路径。
要获取由 createImagesCommand 创建的图像/帧,请使用
$createImagesCommand->framesCreated();
时间类
方法
getSeconds(); //returns seconds, you need a Time object to call all of theese methods
getMinutes();
getHours();
getFullTime();
getTimeInSeconds();
getTimeInMinutes();
create();// static method -- Time::create()
createFromString(); // static method -- Time::createFromString()