Is it possible to use hwaccel h264_mediacodec encoder in Android?

Here is the error I get in Termux:

Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_mediacodec))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help                   [swscaler @ 0x7493629240] deprecated pixel format used, make sure you did set range correctly
    Last message repeated 3 times
[h264_mediacodec @ 0x73933efe40] Use 1 as the default MediaFormat i-frame-interval, please set gop_size properly (>= fps)                             [amediacodec_ndk @ 0x73633f47d0] Encoder configure failed, -10000                                   [h264_mediacodec @ 0x73933efe40] MediaCodec configure failed, Generic error in an external library
[vost#0:0/h264_mediacodec @ 0x73833f5b10] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.           Error while filtering: Generic error in an external library                                         [out#0/mp4 @ 0x73333f9070] Nothing was written into output file, because at least one of its streams received no packets.                             frame=    0 fps=0.0 q=0.0 Lsize=       0kB time=00:00:01.02 bitrate=   0.0kbits/s dup=1 drop=0 speed=2.94x
[aac @ 0x73933f20c0] Qavg: 5968.975
Conversion failed!
~ $

1 Answer 1


The default h264 codec shipped with ffmpeg in termux seems to be broken (also mentioned here: Hardware accelerated ffmpeg using MediaCodec on Android? )

Meanwhile, you can use the software libx264 encoder with -c:v libx264 as mentioned in this comment on the packages repo: https://github.com/termux/termux-packages/issues/18023#issuecomment-1741926145

You must log in to answer this question.