5

Since the vhook subsystem has been removed from the latest version of FFMPEG, how can I add a watermark to a video?

I need to be able to overlay a PNG with background transparency.

mpromonet
  • 11,326
  • 43
  • 62
  • 91
Felix Geisendörfer
  • 2,902
  • 5
  • 27
  • 36

4 Answers4

4

Using Xuggler we can do this in java. while encoding the video using IMediaTool, you will be getting sequence of images. Using these images place water mark on each of these images and generate a output video. Following is the code block

BufferedImage imageB = event.getImage();

/*....................... water mark .........................*/
Graphics2D g2d = (Graphics2D) imageB.getGraphics();
g2d.drawImage(imageB, 0, 0, null);

//Create an alpha composite of 50%
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
g2d.setComposite(alpha); 

g2d.setColor(Color.YELLOW);


g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

g2d.setFont(new Font("Arial", Font.BOLD, 30));

String watermark = "Sample water mark";

FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(watermark, g2d);
yScrolling = imageB.getHeight() - (int) rect.getHeight() / 2;

g2d.drawString(watermark, (imageB.getWidth() - (int) rect.getWidth()) / 2,
                         (imageB.getHeight() - (int) rect.getHeight()) / 2);
g2d.drawString(watermark, xScrolling,yScrolling);

//Free graphic resources
g2d.dispose(); 

 /*....................... water mark .........................*/
Stu Thompson
  • 38,370
  • 19
  • 110
  • 156
2

If you compile ffmpeg from official git repository, you probably need to pay attention to the syntax because it has changed a little bit in newer versions.

Old

ffmpeg -i input.mp4 -acodec copy -vf "movie=0:png:watermark.png [wm];[in][wm] overlay=5:5:1 [out]" -f mp4 -b 2500k -vcodec libx264 -vpre fast -ac 1 -y output.mp4

New

ffmpeg -i input.mp4 -acodec copy -vf "movie=watermark.png [wm];[in][wm] overlay=5:5 [out]" -f mp4 -b 2500k -vcodec libx264 -vpre fast -ac 1 -y output.mp4
whatUwant
  • 21
  • 4
1

The best I could reach was http://www.corbellconsulting.com/2010/07/using-ffmpeg-to-add-and-watermark-overlay-on-a-video-2/

However, I am unable to get it to work with ffmpeg 0.6.2.

Good luck.

Omar Ali
  • 8,467
  • 4
  • 33
  • 58
0

If you're familiar with Java, you can do this with Xuggler. In particular the tutorials for the MediaTool API of Xuggler show you how to decode and encode a video, and separately how to make a video from scratch using images you create. It's not hard to combine those too concepts to make a program that can decode a video, overlay a PNG on the video, and then re-encode.

Art Clarke
  • 2,495
  • 18
  • 15
  • 3
    I'd like to stay with ffmpeg, encoding various formats is already hard enough with one tool chain and I'd hate to throw another one into the mix. Thanks for the suggestion so! – Felix Geisendörfer Nov 11 '09 at 14:07