Reputation: 891
I wanna overlay a picture on a video, as a watermark. How do I insert an animated watermark that randomly moves from side to side.
For example, A watermark, placed on top/ upper-left corner, moves randomly to the top/upper-right corner and freezes there for five seconds before moving down to the lower- right corner.
I don't want the watermark to have a cross movement and move from the upper-right corner to the lower-left corner.
Here is an example of my code, using which the watermark randomly jumps to a corner each 200 frames without animate:
ffmpeg -i "source.mp4" -i "watermark.png" -filter_complex "[1:v]scale=50:-1[a]; [0:v][a]overlay=x='st(0,floor(random(n)*2)+1);if(eq(mod(n-1,200),0), if(eq(ld(0),1),0, main_w-overlay_w ) ,x)':y='st(0,floor(random(n)*2)+1);if(eq(mod(n-1,200),0),if(eq(ld(0),1),0, main_h-overlay_h ),y)'" -codec:a copy "out.mp4"
Upvotes: 1
Views: 490
Reputation: 1
This adds a moving watermark in Laravel using ProtoneMedia\LaravelFFMpeg\Support\FFMpeg.
public function addWatermark($video_path, $url, $dist)
{
$custom_filter = "overlay=x='if(lt(mod(t\,120)\,60)\,W-w-W*10/100\,W*10/100)':y='if(lt(mod(t+30\,120)\,60)\,H-h-H*5/100\,H*5/100)'";
$logo = public_path('images/logo5.png');
$name = 'mjrb_watermark_'.time().'[email protected]';
info("edited file name: $name");
$path = 'videos/'.$url.'/'.$name;
$video = FFMpeg::fromDisk('public')->open($video_path)->resize(640, 480)->addFilter(function ($filters) use ($logo) {
$filters->watermark($logo, [
'position' => 'absolute',
'x' => 'if(lt(mod(t\,30)\,15)\,W-w-W*10/100\,W*10/100)',
'y' => 'if(lt(mod(t+7\,30)\,15)\,H-h-H*5/100\,H*5/100)',
]);
})
->export()
->toDisk('public')
->inFormat(new \FFMpeg\Format\Video\X264)
->save('videos/place_video/'.$name);
return $name;
}
Upvotes: 0