Commit ccd8856d by samrobinson Committed by Andrew Lewis

Preserve aspect ratio when scaling resolution is insufficient.

PiperOrigin-RevId: 509546771
parent ccdb3b70
...@@ -250,9 +250,8 @@ public final class EncoderUtil { ...@@ -250,9 +250,8 @@ public final class EncoderUtil {
} }
} }
// Fix frame being too wide or too tall. int supportedWidth = videoCapabilities.getSupportedWidths().clamp(width);
width = videoCapabilities.getSupportedWidths().clamp(width); int adjustedHeight = videoCapabilities.getSupportedHeightsFor(supportedWidth).clamp(height);
int adjustedHeight = videoCapabilities.getSupportedHeightsFor(width).clamp(height);
if (adjustedHeight != height) { if (adjustedHeight != height) {
width = width =
alignResolution((int) round((double) width * adjustedHeight / height), widthAlignment); alignResolution((int) round((double) width * adjustedHeight / height), widthAlignment);
......
...@@ -164,6 +164,23 @@ public class EncoderUtilTest { ...@@ -164,6 +164,23 @@ public class EncoderUtilTest {
assertThat(closestSupportedResolution.getHeight()).isEqualTo(1080); assertThat(closestSupportedResolution.getHeight()).isEqualTo(1080);
} }
@Test
public void getSupportedResolution_requestedReallyLarge_matchesAspectRatio() {
ImmutableList<MediaCodecInfo> supportedEncoders = EncoderUtil.getSupportedEncoders(MIME_TYPE);
MediaCodecInfo encoderInfo = supportedEncoders.get(0);
double aspectRatio = 1.5;
@Nullable
Size closestSupportedResolution =
EncoderUtil.getSupportedResolution(
encoderInfo, MIME_TYPE, (int) (aspectRatio * 5000), 5000);
assertThat(closestSupportedResolution).isNotNull();
assertThat(
(double) closestSupportedResolution.getWidth() / closestSupportedResolution.getHeight())
.isEqualTo(aspectRatio);
}
/** /**
* @see EncoderUtil#getSupportedEncodersForHdrEditing(String, ColorInfo) * @see EncoderUtil#getSupportedEncodersForHdrEditing(String, ColorInfo)
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment