VideoEncoderConstraintsPresets


@ExperimentalApi
public final class VideoEncoderConstraintsPresets


Factories for VideoEncoderConstraints with presets for common encoding use cases.

Callers can override individual constraints of a preset via buildUpon.

Summary

Public methods

static VideoEncoderConstraints
forEditing(int width, int height, double frameRate)

Returns constraints with presets for video editing.

static VideoEncoderConstraints
forGalleryExport(int width, int height, double frameRate)

Returns constraints with presets for exporting a video to the device gallery.

static VideoEncoderConstraints
forHqCameraRecording(int width, int height, double frameRate)

Returns constraints with presets for high-quality camera recording.

static VideoEncoderConstraints
forLiveStreaming(
    int width,
    int height,
    double frameRate,
    int targetMaxBitrate
)

Returns constraints with presets for live streaming.

static VideoEncoderConstraints
forMessaging(
    int width,
    int height,
    double frameRate,
    int targetMaxBitrate
)

Returns constraints with presets for messaging, where fitting within a strict file-size or bitrate limit is the top priority.

static VideoEncoderConstraints
forRealTimeCommunication(
    int width,
    int height,
    double frameRate,
    int targetMaxBitrate
)

Returns constraints with presets for real-time communication (such as video calling) optimized for minimal latency.

static VideoEncoderConstraints
forSocialPosting(int width, int height, double frameRate)

Returns constraints with presets for social media posting.

Public methods

forEditing

public static VideoEncoderConstraints forEditing(int width, int height, double frameRate)

Returns constraints with presets for video editing.

The target quality is QUALITY_LEVEL_VERY_GOOD. Uses VBR rate control with B-frames allowed.

Parameters
int width

The video width, in pixels.

int height

The video height, in pixels.

double frameRate

The video frame rate, in frames per second.

Throws
java.lang.IllegalArgumentException

if width or height is not positive, or if frameRate is not positive and finite.

forGalleryExport

public static VideoEncoderConstraints forGalleryExport(int width, int height, double frameRate)

Returns constraints with presets for exporting a video to the device gallery.

The target quality is QUALITY_LEVEL_GOOD. Uses VBR rate control with B-frames allowed. Currently uses the same presets as forSocialPosting, which is a separate use case so that its presets can diverge in the future.

Parameters
int width

The video width, in pixels.

int height

The video height, in pixels.

double frameRate

The video frame rate, in frames per second.

Throws
java.lang.IllegalArgumentException

if width or height is not positive, or if frameRate is not positive and finite.

forHqCameraRecording

public static VideoEncoderConstraints forHqCameraRecording(int width, int height, double frameRate)

Returns constraints with presets for high-quality camera recording.

The target quality is QUALITY_LEVEL_NEAR_LOSSLESS. Uses VBR rate control with B-frames allowed.

Parameters
int width

The video width, in pixels.

int height

The video height, in pixels.

double frameRate

The video frame rate, in frames per second.

Throws
java.lang.IllegalArgumentException

if width or height is not positive, or if frameRate is not positive and finite.

forLiveStreaming

public static VideoEncoderConstraints forLiveStreaming(
    int width,
    int height,
    double frameRate,
    int targetMaxBitrate
)

Returns constraints with presets for live streaming.

Uses CBR rate control with B-frames allowed.

Parameters
int width

The video width, in pixels.

int height

The video height, in pixels.

double frameRate

The video frame rate, in frames per second.

int targetMaxBitrate

The target maximum bitrate, in bits per second (bps).

Throws
java.lang.IllegalArgumentException

if width, height, or targetMaxBitrate is not positive, or if frameRate is not positive and finite.

forMessaging

public static VideoEncoderConstraints forMessaging(
    int width,
    int height,
    double frameRate,
    int targetMaxBitrate
)

Returns constraints with presets for messaging, where fitting within a strict file-size or bitrate limit is the top priority.

Uses VBR rate control with B-frames allowed.

Parameters
int width

The video width, in pixels.

int height

The video height, in pixels.

double frameRate

The video frame rate, in frames per second.

int targetMaxBitrate

The target maximum bitrate, in bits per second (bps).

Throws
java.lang.IllegalArgumentException

if width, height, or targetMaxBitrate is not positive, or if frameRate is not positive and finite.

forRealTimeCommunication

public static VideoEncoderConstraints forRealTimeCommunication(
    int width,
    int height,
    double frameRate,
    int targetMaxBitrate
)

Returns constraints with presets for real-time communication (such as video calling) optimized for minimal latency.

Uses CBR rate control with B-frames disallowed.

Parameters
int width

The video width, in pixels.

int height

The video height, in pixels.

double frameRate

The video frame rate, in frames per second.

int targetMaxBitrate

The target maximum bitrate, in bits per second (bps).

Throws
java.lang.IllegalArgumentException

if width, height, or targetMaxBitrate is not positive, or if frameRate is not positive and finite.

forSocialPosting

public static VideoEncoderConstraints forSocialPosting(int width, int height, double frameRate)

Returns constraints with presets for social media posting.

The target quality is QUALITY_LEVEL_GOOD. Uses VBR rate control with B-frames allowed. Currently uses the same presets as forGalleryExport, which is a separate use case so that its presets can diverge in the future.

Parameters
int width

The video width, in pixels.

int height

The video height, in pixels.

double frameRate

The video frame rate, in frames per second.

Throws
java.lang.IllegalArgumentException

if width or height is not positive, or if frameRate is not positive and finite.