mikeambait/ffmpeglaravel

该包的最新版本(v1.1)没有可用的许可信息。

Laravel的php-ffmpeg包装器,用于简单的视频转换、编辑、调整大小等,利用FFMpeg强大的开源库/工具

v1.1 2021-11-24 10:09 UTC

This package is auto-updated.

Last update: 2024-09-14 09:38:02 UTC


README

example workflow

FFMpegLaravel

PHP-FFMpeg的简化Laravel包装器:用于简单的视频转换、缩略图生成、调整大小等,利用FFMpeg的开源库/工具,可以将任何视频格式解码和编码成其他格式。

要求

  • PHP 7.2
  • Apache 2.2+

配置

需要FFMpeg的一个有效安装

安装ffmpeg

sudo apt update
sudo apt install ffmpeg 
(mac) brew install ffmpeg

运行:composer require mikeambait/ffmpeglaravel

或者您可以添加特定版本(见标签)

发布供应商

php artisan vendor:publish

用法

将此添加到您的config/app.php中,以全局使用

'FFMpegLaravel' => FFMpegLaravel\FFMpegLaravel\FFmpegLaravel::class

转换视频(改变)质量,传递可选参数:'channel','bitrate'(视频质量)和'audio'。

use FFMpegLaravel;

$FFMpegLaravelInstance = FFMpegLaravel::open(public_path() . '/egg.mp4');

$FFMpegLaravelInstance->save(public_path() . '/NewEgg.mp4', [
    'bitrate' => 500,
    'audio' => 256
]);

将视频转换为音频

$mp3 = FFMpegLaravel::open(public_path() . '/egg.mp4');

$mp3->save(public_path() . '/egg.mp3');

调整视频大小

// params> width: integer(required) | height : integer(required) | $forceStandards : boolean(nullable)
// you can pass a boolean value in resize() to force the use of the nearest aspect ratio standard.
$resizedVideo = FFMpegLaravel::open(public_path() . '/egg.mp4')
            ->resize(640, 480)
            ->save(public_path() . '/resized_egg.mp4', [
                        'bitrate' => 500,
                        'audio' => 256
                    ]);

从视频中移除音频

$mutedVideo = FFMpegLaravel::open(public_path() . '/egg.mp4')
            ->mute()
            ->save(__DIR__ . '/output/muted_egg.mp4');

生成缩略图

// getThumbnail() , generates thumbnail at 10 secs mark, when no params passed
FFMpegLaravel::open('videos.mp4')
      ->getThumbnail(public_path() . '/filename.jpg');

获取视频持续时间的秒数

// returns a integer of duration in seconds
$duration = FFMpegLaravel::open(public_path() . '/egg.mp4')
      ->getDuration();

echo $duration;

从视频生成GIF

// parameters: new filepath.gif | duration of GIF file : int(nullable) | from seconds: int(nullable)
$gif = FFMpegLaravel::open(public_path() . '/egg.mp4')
            ->generateGif(public_path() . '/sample.gif', 2 );

return $gif;

获取视频分辨率

// returns an array of resolution of the video: 'width' & 'height'
$resolution = FFMpegLaravel::open(public_path() . '/egg.mp4')
      ->getResolution();

echo $resolution['width'] .' x '.$resolution['height'];

您可能想检查视频使用的编解码器

// returns a string of codec used by the video
$codec = FFMpegLaravel::open(public_path() . '/egg.mp4')
      ->getCodec();

echo $codec;

测试

$phpunit tests/FFMpegLaravelTest

鸣谢

鸣谢PHP-FFMpeg团队和Protone Media