phpffmpegffmpeg-php

How to set pad with PHP-FFMpeg?


I use PHP-FFMpeg library (https://github.com/PHP-FFMpeg/PHP-FFMpeg) and try to do this:

ffmpeg -i input.mp4 -vf "crop=960:1080, scale=960:1080,pad=w=960+iw:h=ih:x=960:y=0" output.mp4

I have a video with dimensions 1920x1080. In php I do this:

$video = $ffmpeg->open('input.mp4');
$video->filters()->crop(new FFMpeg\Coordinate\Point(480, 0, true), new FFMpeg\Coordinate\Dimension(960, 1080));
$video->save(new FFMpeg\Format\Video\x264('aac'), 'output.mp4');

I get a cropped video in the center of the frame but not on the right side. How can I move output.mp4 or set the correct starting point?


Solution

  • This works:

    $advancedMedia = $ffmpeg->openAdvanced(array('input.mp4'));
    $advancedMedia->filters()
    ->custom('[0]', 'crop=960:1080, scale=-1:1080, pad=w=960+iw:h=ih:x=960:y=0', '[vmap]');
    $advancedMedia
    ->map(array('[vmap]'), new FFMpeg\Format\Video\x264('aac'), 'output.mp4')
    ->save();