mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Prevent using high profile on problematic devices
[Android best
practices](https://developer.android.com/media/optimize/sharing#android_8_81_and_9)
recommend disabling B-frames on API 27, but some devices output B-frames anyway
when H.264/AVC High profile is selected. Add a workaround to force these
devices not to use high profile, to prevent B-frames being output.
`MediaMuxer` likely handles B-frames on these specific devices, but this change
allows the migration to default to in-app muxing to take place without
introducing errors, and it's a temporary workaround until B-frames are properly
supported in the in-app muxer.
PiperOrigin-RevId: 600422238
(cherry picked from commit 6029521898)
This commit is contained in:
parent
3e005e62dc
commit
18617b8a60
1 changed files with 10 additions and 3 deletions
|
|
@ -570,7 +570,7 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||
mediaFormat.setInteger(MediaFormat.KEY_PROFILE, expectedEncodingProfile);
|
||||
mediaFormat.setInteger(MediaFormat.KEY_LEVEL, supportedEncodingLevel);
|
||||
}
|
||||
} else if (Util.SDK_INT >= 26) {
|
||||
} else if (Util.SDK_INT >= 26 && !deviceNeedsNoH264HighProfileWorkaround()) {
|
||||
int expectedEncodingProfile = MediaCodecInfo.CodecProfileLevel.AVCProfileHigh;
|
||||
int supportedEncodingLevel =
|
||||
EncoderUtil.findHighestSupportedEncodingLevel(
|
||||
|
|
@ -581,8 +581,8 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||
// system versions.
|
||||
mediaFormat.setInteger(MediaFormat.KEY_PROFILE, expectedEncodingProfile);
|
||||
mediaFormat.setInteger(MediaFormat.KEY_LEVEL, supportedEncodingLevel);
|
||||
// TODO(b/210593256): Set KEY_LATENCY to 2 to enable B-frame production after switching to
|
||||
// in-app muxing.
|
||||
// TODO(b/210593256): Set KEY_LATENCY to 2 to enable B-frame production after in-app muxing
|
||||
// is the default and it supports B-frames.
|
||||
mediaFormat.setInteger(MediaFormat.KEY_LATENCY, 1);
|
||||
}
|
||||
} else if (Util.SDK_INT >= 24) {
|
||||
|
|
@ -678,4 +678,11 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||
// Redmi Note 9 Pro fails if KEY_FRAME_RATE is set too high (see b/278076311).
|
||||
return SDK_INT < 30 && Util.DEVICE.equals("joyeuse");
|
||||
}
|
||||
|
||||
private static boolean deviceNeedsNoH264HighProfileWorkaround() {
|
||||
// The H.264/AVC encoder produces B-frames when high profile is chosen despite configuration to
|
||||
// turn them off, so force not using high profile on these devices (see b/306617392).
|
||||
// TODO(b/229420356): Remove once the in-app muxer is the default and B-frames are supported.
|
||||
return Util.SDK_INT == 27 && (Util.DEVICE.equals("ASUS_X00T_3") || Util.DEVICE.equals("TC77"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue