Adding a Watermark to a Video in PHP

Today we’ll use the excellent ffmpeg tool to add a watermark to a video file in PHP.

.com software
2 min readJan 4, 2022
Photo by Glenn Carstens-Peters on Unsplash

According to its authors, ffmpeg is “a complete, cross-platform solution to record, convert and stream audio and video”. It’s easy to use in PHP and its possibilities are endless.

I’m assuming you have already installed the ffmpeg tool. In Linux it’s relatively easy by running apt-get install -y ffmpeg or brew install ffmpeg on MacOS. My current version of the ffmpeg at the time being is ffmpeg 4.1.8

We will also make use of the symfony/process package to control the conversion process. Installation with Composer is also a breeze
php composer.phar req symfony/process

The code is effortless, we just spawn a ffmpeg process that takes care of the conversion process.

After a brief run we get the input video with a watermark embedded in the top right part of the frame:

The entire code is available under an MIT license on GitHub and can be launched almost instantly, as long as you have Docker installed. Happy coding!

--

--

.com software

Father • PHP developer • entrepreneur • working for a €1bn unicorn startup as a backend engineer >>> https://bit.ly/dotcom-software