PHP Video water mark?

I came across this article on water marking images with PHP, can this be done with videos as well with PHP, or an alternative language.

I did a simple test a while ago with a gif:


<?php
$animation = "morph.gif";

$watermark = "output.png";

$watermarked_animation = "morph.gif";

$cmd = " $animation -coalesce -resize 100x200 -gravity South ".
" -geometry +0+0 null: $watermark -layers composite -layers optimize ";

exec("convert $cmd $watermarked_animation ");
?> 

What about other video formats ?

With PHP itself? No. You’ll need something like ffmpeg to encode the video.
This might help: http://www.linuxjournal.com/video/add-watermark-video-ffmpeg

I would think this might need to be something the server does in scheduled batches. My familiarity with video codecs is limited, but I’ve not seen one that’s quick or not memory intensive. I can’t imagine this being feasible on a large scale without a lot more silicon than I’m familiar with managing.

What about other video formats ?

I am afraid I have no idea but I would think as Michael says it would take quite a bit of processing.

How does it work with images ? You upload the image and it’s automatically placed in any custom location on the image ? If it works that beautiful, I may consider.

Images are relatively simple. They are static. And the libraries needed to manipulate images are built into PHP.

Videos are much, much different.

Either you need to encode the video yourself with an encoding/conversion tool to add a watermark, or utilize ffmpeg with an exec command like Ruble posted.

ffmpeg is usually a special request to add to a server. For shared hosting, hosts won’t usually add it because it sucks up CPU time when in use and can slow down the other sites on the server. You’ll typically need to be using dedicated server or VPS.

I don’t completely understand what you mean by a FFmpeg server ?

What are you trying to achieve? Probably the simplest and least time intensive approach in regards to work involved and processing time would be to have the user upload variable file formats themselves. That would completely alleviate the pain of needing to do it server side. However, the trade-off would be user error. So it depends on what needs to be a done and scale.

How does it work with images ? You upload the image and it’s automatically placed in any custom location on the image ? If it works that beautiful, I may consider.

My watermark examples are here:Watermark

From what I understand FFmpeg is an external program that can be installed on a server and used using exec(). Imagemagick also uses it for some of its processes.

I understand now. Making the server add a water mark to a video would be processor intensive. Adding a watermark to a image I’m going to think about :slight_smile: