1

Currently getting the following error whilst trying to add a watermark to videos

PHP Fatal error: Uncaught Alchemy\BinaryDriver\Exception\ExecutionFailureException: ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-i' 'test.mp4' '-vcodec' 'libx264' '-acodec' 'libmp3lame' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '256k' '-ac' '2' '-vf' 'movie=watermark.png [watermark];[in][watermark] overlay=main_w - 50 - overlay_w:25 [out]' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes5e4aa564641efqx15l/pass-5e4aa564642e3' '1276404247.mp4'

when doing the following:

if (file_exists('test.mp4')) {

    $videoSource = 'test.mp4';
    $reqExtension = 'mp4';
    $watermark = "watermark.png";

    $ffmpeg = FFMpeg\FFMpeg::create();

    $video = $ffmpeg->open($videoSource);

    $format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');

    if (!empty($watermark))
    {
        $video  ->filters()
                ->watermark($watermark, array(
                    'position' => 'relative',
                    'top' => 25,
                    'right' => 50,
                ));
    }

    $format
    -> setKiloBitrate(1000)
    -> setAudioChannels(2)
    -> setAudioKiloBitrate(256);

    $randomFileName = rand().".$reqExtension";
    $saveLocation = getcwd(). '/'.$randomFileName;
    $video->save($format, $saveLocation);

}

Have no idea why it's failing though, must be finding the video to even start the process?

EDIT:

Tried to make it simpler and just generate a capture of the video...

$ffmpeg = FFMpeg\FFMpeg::create();

$video = $ffmpeg->open($videoSource);


$frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(1));
$frame->save('image.jpg');

Throws this error:

PHP Fatal error: Uncaught Alchemy\BinaryDriver\Exception\ExecutionFailureException: ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-ss' '00:00:01.00' '-i' 'test.mp4' '-vframes' '1' '-f' 'image2' 'image.jpg'

In the console it works and generates the screenshot without error.

BN83
  • 902
  • 3
  • 9
  • 29
  • try running command that shows up in error message in your command line and see if you can get a more meaningful error message – Dimi Feb 17 '20 at 14:53
  • @Dimi `'-y' '-i' 'test.mp4' '-vcodec' 'libx264' '-acodec' 'libmp3lame' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '256k' '-ac' '2' '-vf' 'movie=watermark.png [watermark];[in][watermark] overlay=main_w - 50 - overlay_w:25 [out]' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes5e4aa564641efqx15l/pass-5e4aa564642e3' '1276404247.mp4'` This? – BN83 Feb 17 '20 at 14:59
  • @Dimi `[libx264 @ 0x2391ea0] ratecontrol_init: can't open stats file` and `Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height` show in red – BN83 Feb 17 '20 at 15:02
  • start working backwards in your code and see if you can make it process a single file without any watermarks (to make sure that your library works in general). Then start adding additional options one at a time until you can identify one that's causing primary issue. – Dimi Feb 17 '20 at 15:09
  • @Dimi I've made it as simple as I can and tried just grabbing a screenshot, but even that results in the error. – BN83 Feb 17 '20 at 15:20
  • Sounds like you might have an issue with either PHP driver for FFMpeg or ffmpeg binary, or apache user permissions. See if you can perform any operations with ffmpeg in command line. If you can, try doing `exec('ffmpeg ');` and see if it is happy. – Dimi Feb 17 '20 at 15:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/207990/discussion-between-bn83-and-dimi). – BN83 Feb 17 '20 at 15:42

0 Answers0