Skip to main content

How to apply watermark on video in Android

How to apply watermark on video in Android

If you want to apply watermark on video, you should pass WatermarkInfo into the videoOutput.start method.

Drawable watermarkDrawable = ContextCompat.getDrawable(this, R.drawable.my_watermark_resource);
int watermarkWidth = 101;
int watermarkHeight = 24;
float aspectRatio = watermarkWidth / watermarkHeight;
SizeProvider sizeProvider = viewportSize -> {
int targetWidth = (int) (viewportSize.getWidth() * 0.5f);
int targetHeight = (int) (targetWidth / aspectRatio);
return new Size(targetWidth, targetHeight);
};
PositionProvider positionProvider = new GravityPositionProviderAdapter(sizeProvider, Gravity.BOTTOM | Gravity.RIGHT);
WatermarkInfo watermarkInfo = new WatermarkInfo(watermarkDrawable, sizeProvider, positionProvider, watermarkWidth, watermarkHeight, true);
videoOutput.start(..., watermarkInfo);