Opened 6 months ago
Closed 4 months ago
#11010 closed enhancement (fixed)
Android MediaCodec: encoding videos with resolution not divisible by 16 to codec other than H.264 and H.265
Reported by: | antonlyap | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avcodec |
Version: | git-master | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Current behavior:
When trying to encode a video with a resolution not divisible by 16 (e.g. 1080p) with Android MediaCodec, the resolution is aligned to 16 pixels (1920x1088). If the output is H.264 or H.265, this gets mitigated by cropping the stream with h264_metadata
or hevc_metadata
BSF.
How to reproduce:
% ffmpeg -i input.mkv -c:v vp9_mediacodec -b:v 4000k -c:a copy out.mkv # input.mkv is a 1080p video % ffprobe out.mkv # displays 1920x1088
Proposed enhancement:
There are other methods to make sure that the output is 1920x1080 instead of 1920x1088:
- setting
crop-bottom
(andcrop-right
) onMediaFormat
(https://developer.android.com/reference/android/media/MediaFormat#KEY_CROP_BOTTOM). Unfortunately, it's only supported on API level 33+ - allowing the user to opt out of the alignment, as a lot of hardware can produce 1080p (or possibly other arbitrary resolution) output.
Change History (3)
follow-up: 2 comment:1 by , 6 months ago
comment:2 by , 4 months ago
Replying to antonlyap:
Also, it appears that we can get accurate info on alignment requirements on API 21+: https://developer.android.com/reference/android/media/MediaCodecInfo.VideoCapabilities.html#getWidthAlignment()
Firstly, it's only available with the terrible designed Java API. Seconly, the information provided by this API on a lot of devides are incorrect, so it's not helpful if it's not reliable.
comment:3 by , 4 months ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Also, it appears that we can get accurate info on alignment requirements on API 21+: https://developer.android.com/reference/android/media/MediaCodecInfo.VideoCapabilities.html#getWidthAlignment()