• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kivy / python-for-android / 12321796541

13 Dec 2024 07:25PM UTC coverage: 59.19% (-0.005%) from 59.195%
12321796541

push

github

web-flow
Add hardware acceleration codecs to ffmpeg recipe (#3092)

* enable hardware acceleration codecs
* Reorder "enable-mediacodec" to fix libx264 issues

---------

Co-authored-by: Dexer <73297572+DexerBR@users.noreply.github.com>

1050 of 2363 branches covered (44.44%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

4895 of 7681 relevant lines covered (63.73%)

2.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/pythonforandroid/recipes/ffmpeg/__init__.py
1
from pythonforandroid.toolchain import Recipe, current_directory, shprint
4✔
2
from os.path import exists, join, realpath
4✔
3
import sh
4✔
4

5

6
class FFMpegRecipe(Recipe):
4✔
7
    version = 'n6.1.2'
4✔
8
    # Moved to github.com instead of ffmpeg.org to improve download speed
9
    url = 'https://github.com/FFmpeg/FFmpeg/archive/{version}.zip'
4✔
10
    depends = ['sdl2']  # Need this to build correct recipe order
4✔
11
    opts_depends = ['openssl', 'ffpyplayer_codecs', 'av_codecs']
4✔
12
    patches = ['patches/configure.patch']
4✔
13

14
    def should_build(self, arch):
4✔
15
        build_dir = self.get_build_dir(arch.arch)
×
16
        return not exists(join(build_dir, 'lib', 'libavcodec.so'))
×
17

18
    def get_recipe_env(self, arch):
4✔
19
        env = super().get_recipe_env(arch)
×
20
        env['NDK'] = self.ctx.ndk_dir
×
21
        return env
×
22

23
    def build_arch(self, arch):
4✔
24
        with current_directory(self.get_build_dir(arch.arch)):
×
25
            env = arch.get_env()
×
26

27
            flags = ['--disable-everything']
×
28
            cflags = []
×
29
            ldflags = []
×
30

31
            # enable hardware acceleration codecs
NEW
32
            flags = [
×
33
                '--enable-jni',
34
                '--enable-mediacodec'
35
            ]
36

37
            if 'openssl' in self.ctx.recipe_build_order:
×
38
                flags += [
×
39
                    '--enable-openssl',
40
                    '--enable-nonfree',
41
                    '--enable-protocol=https,tls_openssl',
42
                ]
43
                build_dir = Recipe.get_recipe(
×
44
                    'openssl', self.ctx).get_build_dir(arch.arch)
45
                cflags += ['-I' + build_dir + '/include/',
×
46
                           '-DOPENSSL_API_COMPAT=0x10002000L']
47
                ldflags += ['-L' + build_dir]
×
48

49
            codecs_opts = {"ffpyplayer_codecs", "av_codecs"}
×
50
            if codecs_opts.intersection(self.ctx.recipe_build_order):
×
51

52
                # Enable GPL
53
                flags += ['--enable-gpl']
×
54

55
                # libx264
56
                flags += ['--enable-libx264']
×
57
                build_dir = Recipe.get_recipe(
×
58
                    'libx264', self.ctx).get_build_dir(arch.arch)
59
                cflags += ['-I' + build_dir + '/include/']
×
60
                # Newer versions of FFmpeg prioritize the dynamic library and ignore
61
                # the static one, unless the static library path is explicitly set.
62
                ldflags += [build_dir + '/lib/' + 'libx264.a']
×
63

64
                # libshine
65
                flags += ['--enable-libshine']
×
66
                build_dir = Recipe.get_recipe('libshine', self.ctx).get_build_dir(arch.arch)
×
67
                cflags += ['-I' + build_dir + '/include/']
×
68
                ldflags += ['-lshine', '-L' + build_dir + '/lib/']
×
69
                ldflags += ['-lm']
×
70

71
                # libvpx
72
                flags += ['--enable-libvpx']
×
73
                build_dir = Recipe.get_recipe(
×
74
                    'libvpx', self.ctx).get_build_dir(arch.arch)
75
                cflags += ['-I' + build_dir + '/include/']
×
76
                ldflags += ['-lvpx', '-L' + build_dir + '/lib/']
×
77

78
                # Enable all codecs:
79
                flags += [
×
80
                    '--enable-parsers',
81
                    '--enable-decoders',
82
                    '--enable-encoders',
83
                    '--enable-muxers',
84
                    '--enable-demuxers',
85
                ]
86
            else:
87
                # Enable codecs only for .mp4:
88
                flags += [
×
89
                    '--enable-parser=aac,ac3,h261,h264,mpegaudio,mpeg4video,mpegvideo,vc1',
90
                    '--enable-decoder=aac,h264,mpeg4,mpegvideo',
91
                    '--enable-muxer=h264,mov,mp4,mpeg2video',
92
                    '--enable-demuxer=aac,h264,m4v,mov,mpegvideo,vc1,rtsp',
93
                ]
94

95
            # needed to prevent _ffmpeg.so: version node not found for symbol av_init_packet@LIBAVFORMAT_52
96
            # /usr/bin/ld: failed to set dynamic section sizes: Bad value
97
            flags += [
×
98
                '--disable-symver',
99
            ]
100

101
            # disable binaries / doc
102
            flags += [
×
103
                '--disable-programs',
104
                '--disable-doc',
105
            ]
106

107
            # other flags:
108
            flags += [
×
109
                '--enable-filter=aresample,resample,crop,adelay,volume,scale',
110
                '--enable-protocol=file,http,hls,udp,tcp',
111
                '--enable-small',
112
                '--enable-hwaccels',
113
                '--enable-pic',
114
                '--disable-static',
115
                '--disable-debug',
116
                '--enable-shared',
117
            ]
118

119
            if 'arm64' in arch.arch:
×
120
                arch_flag = 'aarch64'
×
121
            elif 'x86' in arch.arch:
×
122
                arch_flag = 'x86'
×
123
                flags += ['--disable-asm']
×
124
            else:
125
                arch_flag = 'arm'
×
126

127
            # android:
128
            flags += [
×
129
                '--target-os=android',
130
                '--enable-cross-compile',
131
                '--cross-prefix={}-'.format(arch.target),
132
                '--arch={}'.format(arch_flag),
133
                '--strip={}'.format(self.ctx.ndk.llvm_strip),
134
                '--sysroot={}'.format(self.ctx.ndk.sysroot),
135
                '--enable-neon',
136
                '--prefix={}'.format(realpath('.')),
137
            ]
138

139
            if arch_flag == 'arm':
×
140
                cflags += [
×
141
                    '-mfpu=vfpv3-d16',
142
                    '-mfloat-abi=softfp',
143
                    '-fPIC',
144
                ]
145

146
            env['CFLAGS'] += ' ' + ' '.join(cflags)
×
147
            env['LDFLAGS'] += ' ' + ' '.join(ldflags)
×
148

149
            configure = sh.Command('./configure')
×
150
            shprint(configure, *flags, _env=env)
×
151
            shprint(sh.make, '-j4', _env=env)
×
152
            shprint(sh.make, 'install', _env=env)
×
153
            # copy libs:
154
            sh.cp('-a', sh.glob('./lib/lib*.so'),
×
155
                  self.ctx.get_libs_dir(arch.arch))
156

157

158
recipe = FFMpegRecipe()
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc