FrameDropEffect


@UnstableApi
public final class FrameDropEffect implements GlEffect


Drops frames to lower average frame rate to around targetFrameRate.

Summary

Public methods

static FrameDropEffect
createDefaultFrameDropEffect(float targetFrameRate)

Creates a FrameDropEffect with the default frame dropping strategy.

static FrameDropEffect
createSimpleFrameDropEffect(
    float expectedFrameRate,
    float targetFrameRate
)

Creates a FrameDropEffect that keeps every nth frame, where n is the inputFrameRate divided by the targetFrameRate.

GlShaderProgram
toGlShaderProgram(Context context, boolean useHdr)

Returns a GlShaderProgram that applies the effect.

Inherited methods

From androidx.media3.common.Effect
long

Returns the expected duration of the output stream when the effect is applied given a input durationUs.

From androidx.media3.effect.GlEffect
boolean
isNoOp(int inputWidth, int inputHeight)

Returns whether a GlEffect applies no change at every timestamp.

Public methods

createDefaultFrameDropEffect

public static FrameDropEffect createDefaultFrameDropEffect(float targetFrameRate)

Creates a FrameDropEffect with the default frame dropping strategy.

The strategy used is to queue the current frame, x, with timestamp T_x if and only if one of the following is true:

  • x is the first frame,
  • (T_x - T_lastQueued) is closer to the target frame interval than (T_(x+1) - T_lastQueued)

Where T_lastQueued is the timestamp of the last queued frame and T_(x+1) is the timestamp of the next frame. The target frame interval is determined from targetFrameRate.

Parameters
float targetFrameRate

The number of frames per second the output video should roughly have.

createSimpleFrameDropEffect

public static FrameDropEffect createSimpleFrameDropEffect(
    float expectedFrameRate,
    float targetFrameRate
)

Creates a FrameDropEffect that keeps every nth frame, where n is the inputFrameRate divided by the targetFrameRate.

For example, if the input stream came in at 60fps and the targeted frame rate was 20fps, every 3rd frame would be kept. If n is not an integer, then we round to the nearest one.

Parameters
float expectedFrameRate

The number of frames per second in the input stream.

float targetFrameRate

The number of frames per second the output video should roughly have.

toGlShaderProgram

public GlShaderProgram toGlShaderProgram(Context context, boolean useHdr)

Returns a GlShaderProgram that applies the effect.

Parameters
Context context

A Context.

boolean useHdr

Whether input textures come from an HDR source. If true, colors will be in linear RGB BT.2020. If false, colors will be in linear RGB BT.709.

Throws
androidx.media3.common.VideoFrameProcessingException

If an error occurs while creating the .