2017 © Pedro Peláez
 

library ffmpeg-transformer

FFmpeg transformation command builder

image

javer/ffmpeg-transformer

FFmpeg transformation command builder

  • Monday, June 18, 2018
  • by javer
  • Repository
  • 1 Watchers
  • 6 Stars
  • 273 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

FFmpeg transformer

This library simplifies usage of FFmpeg for complex transcoding of the media files in PHP applications., (*1)

Features: - FFmpeg command builder - Media profile builder - Profile transformer - Command transformer, (*2)

Requirements

Installation

Install the library using composer:, (*3)

composer require javer/ffmpeg-transformer

FFmpeg command builder

Enables you to build FFmpeg command line in OOP style., (*4)

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

$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:, (*6)

[
    '-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., (*7)

Media profile builder

Enables you to create MediaProfile for the given media file or from the given array., (*8)

From file:, (*9)

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

From array:, (*10)

$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)., (*11)

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

It returns a new MediaProfile which contains only necessary parameters which should be changed., (*12)

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., (*13)

$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., (*14)

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

The Versions

18/06 2018

dev-master

9999999-dev https://github.com/javer

FFmpeg transformation command builder

  Sources   Download

MIT

The Requires

 

The Development Requires

command adapter ffmpeg builder transformer

18/06 2018

v1.0.0

1.0.0.0 https://github.com/javer

FFmpeg transformation command builder

  Sources   Download

MIT

The Requires

 

The Development Requires

command adapter ffmpeg builder transformer