Search code examples
phplaravelffmpegvideo-watermarking

how to add watermark in multiple areas using ffmpeg?


i am using laravel framework and also using ffmpeg php library. Actually i have done almost 70% of work. But the problem i faced is to show watermark at multiple areas on video. I have done the watermark on top-left corner that is running very fine on that video. But i want to add watermark in top-left, bottom-left, bottom-right. I have used this code for top-left watermark (for video):-

$inputVideo = public_path('input/airplane_flight_airport_panorama_1080.mp4');
$outputVideo = public_path('uploads/output.mp4');
$watermark = public_path('input/watermark.jpg');

$wmarkvideo = "ffmpeg -i ".$inputVideo." -i ".$watermark." -filter_complex ". '"overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".$outputVideo;
exec($wmarkvideo );

Please help me how can i add watermark on top-left, bottom-left, bottom-right in these areas. Thanks in advance :)


Solution

  • This is the ffmpeg command you would use for multiple watermarks

    ffmpeg -i inputVideo -i watermark-tr -i watermark-tl -i watermark-br -i watermark-bl 
           -filter_complex "[0][1]overlay=x=W-w:y=0[tr];
                            [tr][2]overlay=x=0:y=0[tl];
                            [tl][3]overlay=x=W-w:y=H-h[br];
                            [br][4]overlay=x=0:y=H-h"  outputfile
    

    tr = top-right; tl = top-left; br = bottom-right; bl = bottomleft


    With center as well,

    ffmpeg -i inputVideo -i watermark-tr -i watermark-tl -i watermark-br -i watermark-bl -i watermark-c
           -filter_complex "[0][1]overlay=x=W-w:y=0[tr];
                            [tr][2]overlay=x=0:y=0[tl];
                            [tl][3]overlay=x=W-w:y=H-h[br];
                            [br][4]overlay=x=0:y=H-h[bl];
                            [bl][5]overlay=x=(W-w)/2:y=(H-h)/2"  outputfile