Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7497b1e0
authored
Feb 15, 2023
by
samrobinson
Committed by
christosts
Feb 15, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use MediaFormatUtil for creating MediaFormat from Format.
PiperOrigin-RevId: 509785247
parent
3b7cf8f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
25 deletions
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultDecoderFactory.java
View file @
7497b1e0
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
com
.
google
.
android
.
exoplayer2
.
transformer
;
package
com
.
google
.
android
.
exoplayer2
.
transformer
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
MediaFormatUtil
.
createMediaFormatFromFormat
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
SDK_INT
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
SDK_INT
;
import
android.annotation.SuppressLint
;
import
android.annotation.SuppressLint
;
...
@@ -51,12 +52,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
...
@@ -51,12 +52,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@Override
@Override
public
Codec
createForAudioDecoding
(
Format
format
)
throws
TransformationException
{
public
Codec
createForAudioDecoding
(
Format
format
)
throws
TransformationException
{
MediaFormat
mediaFormat
=
checkNotNull
(
format
.
sampleMimeType
);
MediaFormat
.
createAudioFormat
(
MediaFormat
mediaFormat
=
createMediaFormatFromFormat
(
format
);
checkNotNull
(
format
.
sampleMimeType
),
format
.
sampleRate
,
format
.
channelCount
);
MediaFormatUtil
.
maybeSetInteger
(
mediaFormat
,
MediaFormat
.
KEY_MAX_INPUT_SIZE
,
format
.
maxInputSize
);
MediaFormatUtil
.
setCsdBuffers
(
mediaFormat
,
format
.
initializationData
);
@Nullable
@Nullable
String
mediaCodecName
=
EncoderUtil
.
findCodecForFormat
(
mediaFormat
,
/* isDecoder= */
true
);
String
mediaCodecName
=
EncoderUtil
.
findCodecForFormat
(
mediaFormat
,
/* isDecoder= */
true
);
...
@@ -79,6 +76,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
...
@@ -79,6 +76,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
Format
format
,
Surface
outputSurface
,
boolean
requestSdrToneMapping
)
Format
format
,
Surface
outputSurface
,
boolean
requestSdrToneMapping
)
throws
TransformationException
{
throws
TransformationException
{
checkNotNull
(
format
.
sampleMimeType
);
checkNotNull
(
format
.
sampleMimeType
);
if
(
ColorInfo
.
isTransferHdr
(
format
.
colorInfo
))
{
if
(
ColorInfo
.
isTransferHdr
(
format
.
colorInfo
))
{
if
(
requestSdrToneMapping
&&
(
SDK_INT
<
31
||
deviceNeedsNoToneMappingWorkaround
()))
{
if
(
requestSdrToneMapping
&&
(
SDK_INT
<
31
||
deviceNeedsNoToneMappingWorkaround
()))
{
throw
createTransformationException
(
throw
createTransformationException
(
...
@@ -91,13 +89,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
...
@@ -91,13 +89,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
}
}
}
MediaFormat
mediaFormat
=
MediaFormat
mediaFormat
=
createMediaFormatFromFormat
(
format
);
MediaFormat
.
createVideoFormat
(
format
.
sampleMimeType
,
format
.
width
,
format
.
height
);
MediaFormatUtil
.
maybeSetInteger
(
mediaFormat
,
MediaFormat
.
KEY_ROTATION
,
format
.
rotationDegrees
);
MediaFormatUtil
.
maybeSetInteger
(
mediaFormat
,
MediaFormat
.
KEY_MAX_INPUT_SIZE
,
format
.
maxInputSize
);
MediaFormatUtil
.
setCsdBuffers
(
mediaFormat
,
format
.
initializationData
);
MediaFormatUtil
.
maybeSetColorInfo
(
mediaFormat
,
format
.
colorInfo
);
if
(
decoderSupportsKeyAllowFrameDrop
)
{
if
(
decoderSupportsKeyAllowFrameDrop
)
{
// This key ensures no frame dropping when the decoder's output surface is full. This allows
// This key ensures no frame dropping when the decoder's output surface is full. This allows
// transformer to decode as many frames as possible in one render cycle.
// transformer to decode as many frames as possible in one render cycle.
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java
View file @
7497b1e0
...
@@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
...
@@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkState
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkState
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkStateNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkStateNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
MediaFormatUtil
.
createMediaFormatFromFormat
;
import
static
java
.
lang
.
Math
.
abs
;
import
static
java
.
lang
.
Math
.
abs
;
import
static
java
.
lang
.
Math
.
floor
;
import
static
java
.
lang
.
Math
.
floor
;
import
static
java
.
lang
.
Math
.
round
;
import
static
java
.
lang
.
Math
.
round
;
...
@@ -32,7 +33,6 @@ import android.util.Size;
...
@@ -32,7 +33,6 @@ import android.util.Size;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.Format
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.MediaFormatUtil
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.video.ColorInfo
;
import
com.google.android.exoplayer2.video.ColorInfo
;
...
@@ -173,10 +173,7 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
...
@@ -173,10 +173,7 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
@Override
@Override
public
DefaultCodec
createForAudioEncoding
(
Format
format
)
throws
TransformationException
{
public
DefaultCodec
createForAudioEncoding
(
Format
format
)
throws
TransformationException
{
checkNotNull
(
format
.
sampleMimeType
);
checkNotNull
(
format
.
sampleMimeType
);
MediaFormat
mediaFormat
=
MediaFormat
mediaFormat
=
createMediaFormatFromFormat
(
format
);
MediaFormat
.
createAudioFormat
(
format
.
sampleMimeType
,
format
.
sampleRate
,
format
.
channelCount
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_BIT_RATE
,
format
.
bitrate
);
@Nullable
@Nullable
String
mediaCodecName
=
EncoderUtil
.
findCodecForFormat
(
mediaFormat
,
/* isDecoder= */
false
);
String
mediaCodecName
=
EncoderUtil
.
findCodecForFormat
(
mediaFormat
,
/* isDecoder= */
false
);
...
@@ -231,10 +228,6 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
...
@@ -231,10 +228,6 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
encoderAndClosestFormatSupport
.
supportedEncoderSettings
;
encoderAndClosestFormatSupport
.
supportedEncoderSettings
;
String
mimeType
=
checkNotNull
(
encoderSupportedFormat
.
sampleMimeType
);
String
mimeType
=
checkNotNull
(
encoderSupportedFormat
.
sampleMimeType
);
MediaFormat
mediaFormat
=
MediaFormat
.
createVideoFormat
(
mimeType
,
encoderSupportedFormat
.
width
,
encoderSupportedFormat
.
height
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_FRAME_RATE
,
round
(
encoderSupportedFormat
.
frameRate
));
int
finalBitrate
;
int
finalBitrate
;
if
(
enableFallback
)
{
if
(
enableFallback
)
{
...
@@ -265,8 +258,10 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
...
@@ -265,8 +258,10 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
encoderSupportedFormat
=
encoderSupportedFormat
=
encoderSupportedFormat
.
buildUpon
().
setAverageBitrate
(
finalBitrate
).
build
();
encoderSupportedFormat
.
buildUpon
().
setAverageBitrate
(
finalBitrate
).
build
();
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_BIT_RATE
,
encoderSupportedFormat
.
averageBitrate
);
MediaFormat
mediaFormat
=
createMediaFormatFromFormat
(
encoderSupportedFormat
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_BITRATE_MODE
,
supportedVideoEncoderSettings
.
bitrateMode
);
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_BITRATE_MODE
,
supportedVideoEncoderSettings
.
bitrateMode
);
// Some older devices (API 21) fail to initialize the encoder if frame rate is not an integer.
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_FRAME_RATE
,
round
(
encoderSupportedFormat
.
frameRate
));
if
(
supportedVideoEncoderSettings
.
profile
!=
VideoEncoderSettings
.
NO_VALUE
if
(
supportedVideoEncoderSettings
.
profile
!=
VideoEncoderSettings
.
NO_VALUE
&&
supportedVideoEncoderSettings
.
level
!=
VideoEncoderSettings
.
NO_VALUE
&&
supportedVideoEncoderSettings
.
level
!=
VideoEncoderSettings
.
NO_VALUE
...
@@ -281,7 +276,6 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
...
@@ -281,7 +276,6 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
adjustMediaFormatForH264EncoderSettings
(
format
.
colorInfo
,
encoderInfo
,
mediaFormat
);
adjustMediaFormatForH264EncoderSettings
(
format
.
colorInfo
,
encoderInfo
,
mediaFormat
);
}
}
MediaFormatUtil
.
maybeSetColorInfo
(
mediaFormat
,
encoderSupportedFormat
.
colorInfo
);
if
(
Util
.
SDK_INT
>=
31
&&
ColorInfo
.
isTransferHdr
(
format
.
colorInfo
))
{
if
(
Util
.
SDK_INT
>=
31
&&
ColorInfo
.
isTransferHdr
(
format
.
colorInfo
))
{
// TODO(b/260389841): Validate the picked encoder supports HDR editing.
// TODO(b/260389841): Validate the picked encoder supports HDR editing.
if
(
EncoderUtil
.
getSupportedColorFormats
(
encoderInfo
,
mimeType
)
if
(
EncoderUtil
.
getSupportedColorFormats
(
encoderInfo
,
mimeType
)
...
@@ -298,12 +292,12 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
...
@@ -298,12 +292,12 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
MediaFormat
.
KEY_COLOR_FORMAT
,
MediaCodecInfo
.
CodecCapabilities
.
COLOR_FormatSurface
);
MediaFormat
.
KEY_COLOR_FORMAT
,
MediaCodecInfo
.
CodecCapabilities
.
COLOR_FormatSurface
);
}
}
// Float I-frame intervals are only supported from API 25.
if
(
Util
.
SDK_INT
>=
25
)
{
if
(
Util
.
SDK_INT
>=
25
)
{
mediaFormat
.
setFloat
(
mediaFormat
.
setFloat
(
MediaFormat
.
KEY_I_FRAME_INTERVAL
,
supportedVideoEncoderSettings
.
iFrameIntervalSeconds
);
MediaFormat
.
KEY_I_FRAME_INTERVAL
,
supportedVideoEncoderSettings
.
iFrameIntervalSeconds
);
}
else
{
}
else
{
float
iFrameIntervalSeconds
=
supportedVideoEncoderSettings
.
iFrameIntervalSeconds
;
float
iFrameIntervalSeconds
=
supportedVideoEncoderSettings
.
iFrameIntervalSeconds
;
// Only integer I-frame intervals are supported before API 25.
// Round up values in (0, 1] to avoid the special 'all keyframes' behavior when passing 0.
// Round up values in (0, 1] to avoid the special 'all keyframes' behavior when passing 0.
mediaFormat
.
setInteger
(
mediaFormat
.
setInteger
(
MediaFormat
.
KEY_I_FRAME_INTERVAL
,
MediaFormat
.
KEY_I_FRAME_INTERVAL
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment