Add trying 1/3 resolution in fallback.

1/4 is probably unnecessary, as 1/3 of 4k is 720, which should be supported on
all practical encoders.

PiperOrigin-RevId: 440055144
This commit is contained in:
claincly 2022-04-07 10:57:10 +01:00 committed by Ian Baker
parent 8709b1ef02
commit 1f265a4fac

View File

@ -145,6 +145,13 @@ public final class EncoderUtil {
return new Size(newWidth, newHeight);
}
// Try one-third (e.g. 4k -> 720).
newWidth = alignResolution(width / 3, widthAlignment);
newHeight = alignResolution(height / 3, heightAlignment);
if (videoEncoderCapabilities.isSizeSupported(newWidth, newHeight)) {
return new Size(newWidth, newHeight);
}
// Fix frame being too wide or too tall.
width = videoEncoderCapabilities.getSupportedWidths().clamp(width);
int adjustedHeight = videoEncoderCapabilities.getSupportedHeightsFor(width).clamp(height);