ypresto/android-transcoder

Why not transcoding videos other than 16:9

Shanki070 opened this issue · 2 comments

I was looking at your code, I found that in Android720pFormatStrategy.java

if (longer * 9 != shorter * 16) { throw new OutputFormatUnavailableException("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")"); }

So, why are you not transcoding videos other than 16:9?

CTS contains encoding test for 1280x720 and it is listed in Supported Media Formats. But other resolution like 960x540 (iOS can encode in this res) causes broken video at least Nexus 4. It perhaps limitation or bug of hardware codec. So we cannot use something like 1280x600 for output resolution to adapt to aspect ratio of input video.

So if input file is other than 16:9, we should crop it and fit into 16:9, but currently cropping is not supported by this library.

Perhaps it can be done by manipulating vertex shader and etc. in TextureRender.java.

In my tests, you can use this library to encode videos of arbitrary aspect ratio, as long as you maintain that aspect ratio in your strategy. >= API23
I've successfully tested downsizing video bitrate and dimensions with input ratios of: 16x9, 4x3, 1x1, 18.5x9 with no issues.
https://en.wikipedia.org/wiki/Aspect_ratio_(image)#Current_video_standards

Just provide a single, target minimum dimension (width or height), and calculate the other dimension to maintain the aspect ratio.

Update:
But as ypresto mentioned above, these output resolutions may not be playable on older devices and api versions.