Class DefaultEncoderFactory
- java.lang.Object
-
- com.google.android.exoplayer2.transformer.DefaultEncoderFactory
-
- All Implemented Interfaces:
Codec.EncoderFactory
public final class DefaultEncoderFactory extends Object implements Codec.EncoderFactory
A default implementation ofCodec.EncoderFactory
.
-
-
Field Summary
-
Fields inherited from interface com.google.android.exoplayer2.transformer.Codec.EncoderFactory
DEFAULT
-
-
Constructor Summary
Constructors Constructor Description DefaultEncoderFactory()
Creates a new instance using thedefault encoder selector
, a defaultVideoEncoderSettings
, and with format fallback enabled.DefaultEncoderFactory(EncoderSelector videoEncoderSelector, boolean enableFallback)
Creates a new instance using a defaultVideoEncoderSettings
.DefaultEncoderFactory(EncoderSelector videoEncoderSelector, VideoEncoderSettings requestedVideoEncoderSettings, boolean enableFallback)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Codec
createForAudioEncoding(Format format, List<String> allowedMimeTypes)
Returns aCodec
for audio encoding.Codec
createForVideoEncoding(Format format, List<String> allowedMimeTypes)
Returns aCodec
for video encoding.boolean
videoNeedsEncoding()
Returns whether the video needs to be encoded because of encoder specific configuration.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.transformer.Codec.EncoderFactory
audioNeedsEncoding
-
-
-
-
Constructor Detail
-
DefaultEncoderFactory
public DefaultEncoderFactory()
Creates a new instance using thedefault encoder selector
, a defaultVideoEncoderSettings
, and with format fallback enabled.
-
DefaultEncoderFactory
public DefaultEncoderFactory(EncoderSelector videoEncoderSelector, boolean enableFallback)
Creates a new instance using a defaultVideoEncoderSettings
.
-
DefaultEncoderFactory
public DefaultEncoderFactory(EncoderSelector videoEncoderSelector, VideoEncoderSettings requestedVideoEncoderSettings, boolean enableFallback)
Creates a new instance.With format fallback enabled, when the requested
Format
is not supported,DefaultEncoderFactory
finds a format that is supported by the device and configures theCodec
with it. The fallback process may change the requestedMIME type
, resolution,bitrate
,profile/level
etc.Values in
requestedVideoEncoderSettings
could be adjusted to improve encoding quality and/or reduce failures. Specifically,VideoEncoderSettings.profile
andVideoEncoderSettings.level
are ignored forMimeTypes.VIDEO_H264
. Consider implementingCodec.EncoderFactory
if such adjustments are unwanted.requestedVideoEncoderSettings
should be handled with care because there is no fallback support for it. For example, using incompatibleVideoEncoderSettings.profile
andVideoEncoderSettings.level
can cause codec configuration failure. Setting an unsupportedVideoEncoderSettings.bitrateMode
may cause encoder instantiation failure.- Parameters:
videoEncoderSelector
- TheEncoderSelector
.requestedVideoEncoderSettings
- TheVideoEncoderSettings
.enableFallback
- Whether to enable fallback.
-
-
Method Detail
-
createForAudioEncoding
public Codec createForAudioEncoding(Format format, List<String> allowedMimeTypes) throws TransformationException
Description copied from interface:Codec.EncoderFactory
Returns aCodec
for audio encoding.This method must validate that the
Codec
is configured to produce one of theallowedMimeTypes
. The sample MIME type given informat
is not necessarily allowed.- Specified by:
createForAudioEncoding
in interfaceCodec.EncoderFactory
- Parameters:
format
- TheFormat
(of the output data) used to determine the underlying encoder and its configuration values.allowedMimeTypes
- The non-empty list of allowed output sample MIME types.- Returns:
- A
Codec
for audio encoding. - Throws:
TransformationException
- If no suitableCodec
can be created.
-
createForVideoEncoding
public Codec createForVideoEncoding(Format format, List<String> allowedMimeTypes) throws TransformationException
Description copied from interface:Codec.EncoderFactory
Returns aCodec
for video encoding.This method must validate that the
Codec
is configured to produce one of theallowedMimeTypes
. The sample MIME type given informat
is not necessarily allowed.- Specified by:
createForVideoEncoding
in interfaceCodec.EncoderFactory
- Parameters:
format
- TheFormat
(of the output data) used to determine the underlying encoder and its configuration values.Format.sampleMimeType
,Format.width
andFormat.height
are set to those of the desired output video format.Format.rotationDegrees
is 0 andFormat.width
>=
Format.height
, therefore the video is always in landscape orientation.Format.frameRate
is set to the output video's frame rate, if available.allowedMimeTypes
- The non-empty list of allowed output sample MIME types.- Returns:
- A
Codec
for video encoding. - Throws:
TransformationException
- If no suitableCodec
can be created.
-
videoNeedsEncoding
public boolean videoNeedsEncoding()
Description copied from interface:Codec.EncoderFactory
Returns whether the video needs to be encoded because of encoder specific configuration.- Specified by:
videoNeedsEncoding
in interfaceCodec.EncoderFactory
-
-