Set pixel aspect ratio from output media format if set

This commit is contained in:
Daniele Sparano 2024-05-13 14:54:56 +01:00 committed by microkatz
parent 9c5ea4f1ba
commit f0463bff8a

View File

@ -1342,7 +1342,12 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
? mediaFormat.getInteger(KEY_CROP_BOTTOM) - mediaFormat.getInteger(KEY_CROP_TOP) + 1
: mediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
}
pixelWidthHeightRatio = format.pixelWidthHeightRatio;
boolean hasPixelAspectRatio = mediaFormat.containsKey(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH)
&& mediaFormat.containsKey(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT);
pixelWidthHeightRatio = hasPixelAspectRatio ?
mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH) /
mediaFormat.getInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT)
: format.pixelWidthHeightRatio;
// The decoder applies the rotation when rendering to the surface. For 90 and 270 degree
// rotations, we need to flip the width, height and pixel aspect ratio to reflect the rotation
// that was applied.