定制 javer/ffmpeg-transformer 二次开发

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

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

javer/ffmpeg-transformer

Composer 安装命令:

composer require javer/ffmpeg-transformer

包简介

FFmpeg transformation command builder

README 文档

README

This library simplifies usage of FFmpeg for complex transcoding of the media files in PHP applications.

Features:

  • FFmpeg command builder
  • Media profile builder
  • Profile transformer
  • Command transformer

Requirements

Installation

Install the library using composer:

composer require javer/ffmpeg-transformer

FFmpeg command builder

Enables you to build FFmpeg command line in OOP style.

For example, for retranscoding of the source media file in any format/codecs to mp4/h264/aac you need just write:

$command = (new Command())
    ->overwriteOutputFiles();

$inputFile = $command->addInput('input.mov');

$command->addOutput('output.mp4')
    ->moveHeaderToStart()
    ->addVideoStream($inputFile->getVideoStream())
        ->codec('libx264')
        ->preset('veryfast')
        ->pixelFormat('yuv420p')
    ->end()
    ->addAudioStream($inputFile->getAudioStream())
        ->codec('aac')
    ->end();

To build command line which performs this transformation just call $command->build() which will return array of all command line arguments to achieve the goal:

[
    '-y',
    '-i', 'input.mov',
    '-movflags', 'faststart',
    '-map', '0:v:0', '-c:v:0', 'libx264', '-preset', 'veryfast', '-pix_fmt:v:0', 'yuv420p',
    '-map', '0:a:0', '-c:a:0', 'aac',
    'output.mp4',
]

More examples can be found in CommandTest.

Media profile builder

Enables you to create MediaProfile for the given media file or from the given array.

From file:

$ffmpeg = new FFMpeg\FFMpeg(...);
$inputVideo = $ffmpeg->open($filename);
$inputMediaProfile = MediaProfile::fromMedia($inputVideo);

From array:

$referenceMediaProfile = MediaProfile::fromArray([
    'name' => 'reference',
    'format' => 'mp4',
    'video' => [
        'width' => 1920,
        'height' => 1080,
        'codec' => 'h264',
        'profile' => 'main',
        'preset' => 'veryfast',
        'pixel_format' => 'yuv420p',
        'bitrate' => '6000k',
        'frame_rate' => 29.97,
        'keyframe_interval' => 250,
    ],
    'audio' => [
        'codec' => 'aac',
        'bitrate' => '128k',
        'sample_rate' => '48k',
    ],
]);

Profile transformer

Performs calculation of the transformation which should be applied to the input MediaProfile to get output MediaProfile (usually reference).

$transformation = (new ProfileTransformer())
    ->transformMedia($sourceMediaProfile, $referenceMediaProfile);

It returns a new MediaProfile which contains only necessary parameters which should be changed.

Command transformer

Builds a command for FFmpeg to perform necessary transformation (from the previous step) to transform input media file to the output media file.

$command = (new CommandTransformer())
    ->applyTransformation($transformation, $inputFilename, $outputFilename);

It returns a Command (see the first section) which should be run by ffmpeg to convert input media file to the reference.

$ffmpeg->getFFMpegDriver()->command($command->build());

javer/ffmpeg-transformer 适用场景与选型建议

javer/ffmpeg-transformer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47.83k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2018 年 06 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 47.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-18