mirror of
https://github.com/androidx/media.git
synced 2025-05-04 22:20:47 +08:00
Preserve aspect ratio when scaling resolution is insufficient.
PiperOrigin-RevId: 509546771
This commit is contained in:
parent
b7d68fb62e
commit
ccc349abfd
@ -252,9 +252,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);
|
||||||
|
@ -163,6 +163,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)
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user