R
R
Roma Antonyuk2018-10-22 12:50:04
PHP
Roma Antonyuk, 2018-10-22 12:50:04

How to add watermark to video using PHP-FFMpeg?

If I use X264 format - FFMpeg\Exception\RuntimeException Encoding Failed
with others is fine

$ffmpeg = FFMpeg::create([
                'ffmpeg.binaries' => exec('which ffmpeg'),
                'ffprobe.binaries' => exec('which ffprobe'),
            ]);

            $format = new X264();
        $watermarkPath = Yii::getAlias('@frontend/web/default/watermark.jpg');

        foreach ($videos as $video) {
            if(!file_exists($video->serverPath) || !file_exists($video->serverPath)) {
                continue;
            }
            $ffVideo = $ffmpeg->open($video->serverPath);

            $ffVideo->filters()
                ->watermark($watermarkPath, array(
                    'position' => 'relative',
                    'bottom' => 50,
                    'right' => 50
                ));

            $ffVideo->save($format, $video->serverPath);
        }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question