Skip to content

bug: recipes: ffmpeg: hardware acc flags override --disable-everything flag #3382

Description

@f321x

The ffmpeg recipe declares flags = ['--disable-everything'] but then right below it
overrides the flags again (instead of appending):

flags = ['--disable-everything']
cflags = []
ldflags = []
# enable hardware acceleration codecs
flags = [
'--enable-jni',
'--enable-mediacodec'
]

The obvious fix is simple, but i have no means of testing the actual recipe, so I won't open a PR. Someone who is actually using this ffmpeg recipe should be testing the fix.

My LLM also recommends a patch like this to keep the hardware acceleration functional after this change:

Click to show patch:
diff --git a/pythonforandroid/recipes/ffmpeg/__init__.py b/pythonforandroid/recipes/ffmpeg/__init__.py
index 24004868..33724ee2 100644
--- a/pythonforandroid/recipes/ffmpeg/__init__.py
+++ b/pythonforandroid/recipes/ffmpeg/__init__.py
@@ -98,10 +98,18 @@ class FFMpegRecipe(Recipe):
             else:
                 # Enable codecs only for .mp4:
                 flags += [
-                    '--enable-parser=aac,ac3,h261,h264,mpegaudio,mpeg4video,mpegvideo,vc1',
-                    '--enable-decoder=aac,h264,mpeg4,mpegvideo',
+                    '--enable-parser=aac,ac3,h261,h264,hevc,mpegaudio,mpeg4video,mpegvideo,vc1',
+                    '--enable-decoder=aac,h264,hevc,mpeg4,mpegvideo',
+                    # --enable-mediacodec only builds the MediaCodec support layer;
+                    # the hardware decoders are separate components that
+                    # --disable-everything switches off, so enable them explicitly.
+                    # They are never picked automatically -- avcodec_find_decoder()
+                    # returns the first match in list order and every software
+                    # decoder is declared first -- so callers ask for them by name
+                    # and the software decoders above stay as the fallback.
+                    '--enable-decoder=h264_mediacodec,hevc_mediacodec,mpeg4_mediacodec,mpeg2_mediacodec',
                     '--enable-muxer=h264,mov,mp4,mpeg2video',
-                    '--enable-demuxer=aac,h264,m4v,mov,mpegvideo,vc1,rtsp',
+                    '--enable-demuxer=aac,h264,hevc,m4v,mov,mpegvideo,vc1,rtsp',
                 ]
 
             # needed to prevent _ffmpeg.so: version node not found for symbol av_init_packet@LIBAVFORMAT_52

It also mentions the following issues after reviewing this change:

  1. The shipped ffmpeg CLI loses all encoders. --enable-encoders appears only at line 94, inside the ffpyplayer_codecs/av_codecs branch. The minimal branch enables muxers and zero encoders. build_arch ends with cp ffmpeg ./lib/libffmpegbin.so (added 2026-01-19, ffmpeg, python3: include executable #3276 — after the Add hardware acceleration codecs to ffmpeg recipe #3092 bug), so that binary has only ever existed in "everything enabled" form. Post-fix it can remux but any -c:v/-c:a fails with "Unknown encoder".
  2. HLS breaks. --enable-protocol=...,hls builds hlsproto.c (deprecated, handles hls+http://). Real playback needs the hls demuxer — ff_hls_demuxer is a distinct component, it's not in the demuxer list, and hls_demuxer_select additionally requires mpegts_demuxer aac_demuxer ac3_demuxer eac3_demuxer, none enabled.
  3. RTSP breaks. rtsp_demuxer_select="http_protocol rtpdec" (configure:3682) — it does not pull rtp_protocol, and the protocol list is file,http,hls,udp,tcp with no rtp. Result: Protocol not found.

Also real but lower-stakes: mp4 audio is aac-only (mp3/ac3/alac tracks decode to nothing), and should_build() returns early on an existing libavcodec.so, so nobody sees any of this without a clean build.

According to the git blame this was introduced in #3092 by @DexerBR, maybe @DexerBR has some way of testing a fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions