[FFmpeg-devel] about mediacodec encoder on android platform

Martin Storsjö martin at martin.st
Tue Mar 31 11:46:11 EEST 2020


On Tue, 31 Mar 2020, Matthieu Bouron wrote:

> On Fri, Mar 27, 2020 at 04:21:59PM +0800, aistoy wrote:
>> Hi, I want to know why ffmpeg do not include mediacodec encoder, just include mediacodec decoder. 
>> And why the decoder implemention don’t use mediacodec native api, but use jni call mediacodec java methods. 
>> If i plan to add the mediacodec encoder, what do you think i should pay attention to ?
>
> Hi,
>
> Sorry for the late replay.
>
> The MediaCodec decoder wrapper in FFmpeg does not use the native API
> because at the time it was implemented, more than 40% of the devices were
> running Android 4.4 (which does not support the native API).
>
> The MediaCodec native API has also some limitation regarding codec
> probing, ie: it does not provide a wrapper around
> MediaCodecList/MediaCodecInfo. We use this capability to blacklist
> software codecs for example.
>
> I made our MediaCodec java wrapper implement the same API as the native
> one provided by the NDK so it shouldn't be too hard to switch.
> Moreover, Aman Gupta already already did this work in one of his branches.
>
> The "tricky" part about implementing MediaCodec encoding support in FFmpeg
> will be to fit the encoder input surface API into the libavcodec API.

FWIW, one doesn't need to use the surface API for input to encoders. Since 
Android 4.3 they all support either YUV420 or NV12 as input via plain 
buffers (enforced via a CTS test), fairly quirk free actually.

On Android 4.1 and 4.2 though, there were no tests that enforced encoders 
to behave, and they did pretty much whatever they wanted (having their own 
definitions of pixel formats, meaning something totally different to their 
standard names etc, with nonstandard padding).

// Martin


More information about the ffmpeg-devel mailing list