php - Encoding failed while adding watermark using ffmpeg in Laravel
Get the solution ↓↓↓I'm getting an error while adding a watermark on the video in Laravel. I'm using this protonemedia/laravel-ffmpeg package and I got reference code from here stackoverflow answer. I'm using the code from the first answer. If I do not add a watermark then it's working fine, but when I add a watermark I got an error.
FFMpeg\Exception\RuntimeException: Encoding failed in file E:\xampp\htdocs\Learn\video-demo\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\Media\AbstractVideo.php on line 106
I'm using PNG image and MP4 video and I'm using first time this type of package so I don't know how to fix that and I didn't find any right solution.
Please help me to fix that. Thanks and also sorry for bad English.
My watermark function:
public function postVideo(Request $request)
{
$video_file = $request->file('file');
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($video_file);
$watermark = public_path()."/app_logo.png";
$reqExtension = "mp4";
if (!empty($watermark))
{
$video->filters()
->watermark($watermark, array(
'position' => 'bottom',
'top' => 25,
'right' => 50,
));
}
$format = new FFMpeg\Format\Video\X264();
$format->setAudioCodec("libmp3lame");
$randomFileName = rand().".$reqExtension";
$saveLocation = public_path(). '/watermark/'.$randomFileName;
$video->save($format,$saveLocation);
if (file_exists($saveLocation))
return "http://localhost:8000/video/$randomFileName";
else
return "http://localhost:8000/test/thumb/404.png";
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: undefined array key php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.