定制 linkthrow/ffmpeg 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

linkthrow/ffmpeg

Composer 安装命令:

composer require linkthrow/ffmpeg

包简介

A laravel audio and video conversion, thumbnail generator and metadata editor package powered by ffmpeg

README 文档

README

Latest Stable Version

**** NOTE **** This is a duplicate of https://github.com/closca/FFMPEG. I have duplicated because the original package was not working with the latest Laravel psr-4 loaders and hasn't been updated for a while!

FFMPEG is a tool designed to leverage the power of Laravel 5 and (C library FFMPEG) to perform tasks such as:

  • Audio/Video conversion
  • Video thumbnail generation
  • Metadata manipulation

Quick Start

Setup

Update your composer.json file and add the following under the require key

"linkthrow/ffmpeg": "dev-master"

Run the composer update command:

$ composer update

In your config/app.php add 'LinkThrow\Ffmpeg\Provider\FfmpegServiceProvider' to the end of the $providers array

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'LinkThrow\Ffmpeg\Provider\FfmpegServiceProvider',

),

Still under config/app.php add 'FFMPEG' => 'LinkThrow\Ffmpeg\Facade\FfmpegFacade' to the $aliases array

'aliases' => array(

    'App'             => 'Illuminate\Support\Facades\App',
    'Artisan'         => 'Illuminate\Support\Facades\Artisan',
    ...
    'FFMPEG'           => 'LinkThrow\Ffmpeg\Facade\FfmpegFacade',

),

Run the artisan command below to publish the configuration file

$ php artisan vendor:publish

Navigate to app/config/ffmpeg.php and update all four parameters

Examples

Here is a simple example of a file being converted from FLAC to AAC:

FFMPEG::convert()->input('foo.flac')->bitrate(128)->output('bar.aac')->go();

FFMPEG can also convert video files:

FFMPEG::convert()->input('foo.avi')->bitrate(300, 'video')->output('bar.flv')->go();

FFMPEG can also return media information as an array or json

FFMPEG::getMediaInfo('foo.mov');

FFMPEG can also easily generate smart movie thumbnails like this

FFMPEG::getThumbnails('foo.mp4', 'foo-thumb', 5); // Yields 5 thumbnails

FFMPEG can also thumbnify your movie (create thumbs for a short preview)

FFMPEG::thumbnify('foo.mp4', 'foo-thumb', 40, '400'); // Yields 40 thumbnails (every 10 seconds) and video has 400 secs

Although FFMPEG contains several preset parameters, you can also pass your own

FFMPEG::convert()->input('foo.flac')->output('bar.mp3')->go('-b:a 64k -ac 1');

Tracking progress

Make sure the progress and tmp_dir options are set correctly in the config.php file

'progress'      => true,
...
'tmp_dir'      => '/Applications/ffmpeg/tmp/'

Pass the progress method when initiating a conversion

FFMPEG::convert()->input('foo.avi')->output('bar.mp3')->progress('uniqueid')->go();

Now you can write a controller action to return the progress for the job id you passed and call it using any flavor of JavaScript you like

public function getJobProgress($id)
{
    return FFMPEG::getProgress('uniqueid');
}

Security and Compatibility

FFMPEG uses PHP's shell_exec function to perform ffmpeg and ffprobe commands. This command is disabled if you are running PHP 5.3 or below and safe mode is enabled.

Please make sure that ffmpeg and ffprobe are at least the following versions:

  • ffmpeg: 2.1.*
  • ffprobe: 2.0.*

Also, remember that filepaths must be relative to the location of FFMPEG on your system. To ensure compatibility, it is good practice to pass the full path of the input and output files. Here's an example working in Laravel:

$file_in  = Input::file('audio')->getRealPath();
$file_out = '\path\to\my\file.mp3'; 
FFMPEG::convert()->input($file_in)->output($file_out)->go();

Lastly, FFMPEG will only convert to formats which ffmpeg supports. To check if your version of ffmpeg is configured to encode or decode a specific format you can run the following commands using php artisan tinker

var_dump(FFMPEG::canEncode('mp3'));
var_dump(FFMPEG::canDecode('mp3'));

To get a list of all supported formats you can run

var_dump(FFMPEG::getSupportedFormats());

Troubleshooting

Please make sure the following statements are true before opening an issue:

  1. I am able to access FFMPEG on terminal using the same path I defined in the FFMPEG configuration file

  2. I have checked the error logs for the webserver and found no FFMPEG output messages

Usually all concerns are taken care of by following these two steps. If you still find yourself having issues you can always open a trouble ticket.

License

FFMPEG is free software distributed under the terms of the MIT license.

Aditional information

Any questions, feel free to contact me.

Any issues, please report here

linkthrow/ffmpeg 适用场景与选型建议

linkthrow/ffmpeg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.65k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2016 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ffmpeg」 「ffprobe」 「converter」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 linkthrow/ffmpeg 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 linkthrow/ffmpeg 我们能提供哪些服务?
定制开发 / 二次开发

基于 linkthrow/ffmpeg 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 40.65k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 33
  • 点击次数: 20
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 29
  • Watchers: 3
  • Forks: 34
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-12