Opened 5 months ago

Closed 3 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:

Change History (3)

comment:1 by antonlyap, 5 months ago

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()

in reply to:  1 comment:2 by quinkblack, 3 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 quinkblack, 3 months ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.