public interface

GlMatrixTransformation

implements GlEffect

 androidx.media3.effect.GlMatrixTransformation

Subclasses:

MatrixTransformation, Crop, Presentation, ScaleAndRotateTransformation

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-effect', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-effect
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-effect:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Specifies a 4x4 transformation to apply in the vertex shader for each input frame.

The matrix is applied to points given in normalized device coordinates (-1 to 1 on x, y, and z axes). Transformed pixels that are moved outside of the normal device coordinate range are clipped.

Output frame pixels outside of the transformed input frame will be black, with alpha = 0 if applicable.

Summary

Methods
public Sizeconfigure(int inputWidth, int inputHeight)

Configures the input and output dimensions.

public float[]getGlMatrixArray(long presentationTimeUs)

Returns the 4x4 transformation to apply to the frame with the given timestamp.

public BaseGlShaderProgramtoGlShaderProgram(Context context, boolean useHdr)

Methods

public Size configure(int inputWidth, int inputHeight)

Configures the input and output dimensions.

Must be called before GlMatrixTransformation.getGlMatrixArray(long).

Parameters:

inputWidth: The input frame width, in pixels.
inputHeight: The input frame height, in pixels.

Returns:

The output frame width and height, in pixels.

public float[] getGlMatrixArray(long presentationTimeUs)

Returns the 4x4 transformation to apply to the frame with the given timestamp.

public BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)

Source

/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.effect;

import android.content.Context;
import android.opengl.Matrix;
import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.Size;
import androidx.media3.common.util.UnstableApi;
import com.google.common.collect.ImmutableList;

/**
 * Specifies a 4x4 transformation {@link Matrix} to apply in the vertex shader for each input frame.
 *
 * <p>The matrix is applied to points given in normalized device coordinates (-1 to 1 on x, y, and z
 * axes). Transformed pixels that are moved outside of the normal device coordinate range are
 * clipped.
 *
 * <p>Output frame pixels outside of the transformed input frame will be black, with alpha = 0 if
 * applicable.
 */
@UnstableApi
public interface GlMatrixTransformation extends GlEffect {
  /**
   * Configures the input and output dimensions.
   *
   * <p>Must be called before {@link #getGlMatrixArray(long)}.
   *
   * @param inputWidth The input frame width, in pixels.
   * @param inputHeight The input frame height, in pixels.
   * @return The output frame width and height, in pixels.
   */
  default Size configure(int inputWidth, int inputHeight) {
    return new Size(inputWidth, inputHeight);
  }

  /**
   * Returns the 4x4 transformation {@link Matrix} to apply to the frame with the given timestamp.
   */
  float[] getGlMatrixArray(long presentationTimeUs);

  @Override
  default BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
      throws VideoFrameProcessingException {
    return DefaultShaderProgram.create(
        context,
        /* matrixTransformations= */ ImmutableList.of(this),
        /* rgbMatrices= */ ImmutableList.of(),
        useHdr);
  }
}