Add TextureOverlay.configure() to configure overlay before frame processing

This change allows an overlay to be sized with respect to the video dimensions.

PiperOrigin-RevId: 497337734
This commit is contained in:
tofunmi 2022-12-23 10:44:17 +00:00 committed by Marc Baechinger
parent 88fd9e18f5
commit 18f58d1790
4 changed files with 37 additions and 4 deletions

View File

@ -150,14 +150,33 @@ public class OverlayTextureProcessorPixelTest {
}
@Test
public void drawFrame_scaledBitmapOverlay_blendsBitmapIntoFrame() throws Exception {
public void drawFrame_scaledBitmapOverlay_letterboxStretchesOverlay() throws Exception {
String testId = "drawFrame_scaledBitmapOverlay";
Bitmap overlayBitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
float[] scaleMatrix = GlUtil.create4x4IdentityMatrix();
Matrix.scaleM(scaleMatrix, /* mOffset= */ 0, /* x= */ 3, /* y= */ 3, /* z= */ 1);
OverlaySettings overlaySettings = new OverlaySettings.Builder().setMatrix(scaleMatrix).build();
BitmapOverlay staticBitmapOverlay =
BitmapOverlay.createStaticBitmapOverlay(overlayBitmap, overlaySettings);
new BitmapOverlay() {
@Override
public Bitmap getBitmap(long presentationTimeUs) {
return overlayBitmap;
}
@Override
public void configure(Size videoSize) {
Matrix.scaleM(
scaleMatrix,
/* mOffset= */ 0,
/* x= */ videoSize.getWidth() / (float) overlayBitmap.getWidth(),
/* y= */ 1,
/* z= */ 1);
}
@Override
public OverlaySettings getOverlaySettings(long presentationTimeUs) {
return overlaySettings;
}
};
overlayTextureProcessor =
new OverlayEffect(ImmutableList.of(staticBitmapOverlay))
.toGlTextureProcessor(context, /* useHdr= */ false);

View File

@ -83,7 +83,11 @@ import com.google.common.collect.ImmutableList;
public Size configure(int inputWidth, int inputHeight) {
videoWidth = inputWidth;
videoHeight = inputHeight;
return new Size(inputWidth, inputHeight);
Size videoSize = new Size(inputWidth, inputHeight);
for (TextureOverlay overlay : overlays) {
overlay.configure(videoSize);
}
return videoSize;
}
@Override

View File

@ -41,6 +41,16 @@ public abstract class TextureOverlay {
*/
public abstract Size getTextureSize(long presentationTimeUs);
/**
* Set up resources for the overlay given the input videos dimensions.
*
* <p>This method will be called before drawing the first frame and before drawing subsequent
* frames with different input dimensions.
*
* @param videoSize The width and height of the input video, in pixels.
*/
public void configure(Size videoSize) {}
/**
* Returns the {@link OverlaySettings} controlling how the overlay is displayed at the specified
* timestamp.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 540 KiB

After

Width:  |  Height:  |  Size: 539 KiB