From 821ab267026beee4f37e71220d930776b6ac266f Mon Sep 17 00:00:00 2001 From: claincly Date: Fri, 1 Jul 2022 11:06:12 +0000 Subject: [PATCH] Round the frame rate in MediaFormat Although MediaCodec claims supporting float frame rate, encoder init failed on API21 Nexus 5. Since it's just a performance hint to the codec, it's OK to generalize it to other API versions. PiperOrigin-RevId: 458434650 --- .../android/exoplayer2/transformer/DefaultEncoderFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java index b7dca2343e..407f50ae96 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/DefaultEncoderFactory.java @@ -23,6 +23,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; import static com.google.android.exoplayer2.util.Util.SDK_INT; import static java.lang.Math.abs; import static java.lang.Math.floor; +import static java.lang.Math.round; import android.content.Context; import android.media.MediaCodecInfo; @@ -229,7 +230,7 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory { String mimeType = checkNotNull(format.sampleMimeType); MediaFormat mediaFormat = MediaFormat.createVideoFormat(mimeType, format.width, format.height); - mediaFormat.setFloat(MediaFormat.KEY_FRAME_RATE, format.frameRate); + mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, round(format.frameRate)); mediaFormat.setInteger( MediaFormat.KEY_BIT_RATE, supportedVideoEncoderSettings.bitrate != VideoEncoderSettings.NO_VALUE