mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Fix error in frame rate handling.
The old getString() will throw because FRAME_RATE can only be float or int.
PiperOrigin-RevId: 458481251
(cherry picked from commit deea5c927a)
This commit is contained in:
parent
e0752a3a7a
commit
379ecd198f
1 changed files with 8 additions and 3 deletions
|
|
@ -239,9 +239,14 @@ public final class EncoderUtil {
|
|||
MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
|
||||
// Format must not include KEY_FRAME_RATE on API21.
|
||||
// https://developer.android.com/reference/android/media/MediaCodecList#findDecoderForFormat(android.media.MediaFormat)
|
||||
@Nullable String frameRate = null;
|
||||
float frameRate = Format.NO_VALUE;
|
||||
if (Util.SDK_INT == 21 && format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
|
||||
frameRate = format.getString(MediaFormat.KEY_FRAME_RATE);
|
||||
try {
|
||||
frameRate = format.getFloat(MediaFormat.KEY_FRAME_RATE);
|
||||
} catch (ClassCastException e) {
|
||||
frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
|
||||
}
|
||||
// Clears the frame rate field.
|
||||
format.setString(MediaFormat.KEY_FRAME_RATE, null);
|
||||
}
|
||||
|
||||
|
|
@ -251,7 +256,7 @@ public final class EncoderUtil {
|
|||
: mediaCodecList.findEncoderForFormat(format);
|
||||
|
||||
if (Util.SDK_INT == 21) {
|
||||
MediaFormatUtil.maybeSetString(format, MediaFormat.KEY_FRAME_RATE, frameRate);
|
||||
MediaFormatUtil.maybeSetInteger(format, MediaFormat.KEY_FRAME_RATE, round(frameRate));
|
||||
}
|
||||
return mediaCodecName;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue