I need to transcode a video file on Android from an arbitrary aspect ratio, such as 1920x1080 to 720p, while preserving the original aspect ratio, adding padding, if necessary.
I am using this CTS file as a reference.
I tried adding
outputVideoFormat.setInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_WIDTH, 720);
outputVideoFormat.setInteger(MediaFormat.KEY_PIXEL_ASPECT_RATIO_HEIGHT, 1280);
and also
codec.setVideoScalingMode(VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
to every callback method belonging to both encoder and decoder, i.e. onOutputFormatChanged(), onInputBufferAvailable(), onOutputBufferAvailable().
Also, I added the call to decoder.setVideoScalingMode() and encoder.setVideoScalingMode() right before creation of both encoder and decoder, as suggested here.
Unfortunately, none of the approaches above helped preserve the original aspect ratio.
Is there any other way to do it on Android I may be missing?
p.s.: yes, I know I am trying to use a cropping option to implement preserved padded aspect ratio, but this is the closest option I was able to find.