ffmpeg watermark without vhook?

Felix Geisendörfer picture Felix Geisendörfer · Oct 13, 2009 · Viewed 11.2k times · Source

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.

Answer

Prajwal A P picture Prajwal A P · Nov 23, 2009

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 .........................*/