1
- from pythonforandroid .toolchain import Recipe , shprint , shutil , current_directory
2
- from os .path import join , exists
1
+ from pythonforandroid .toolchain import Recipe , shprint , current_directory , ArchARM
2
+ from os .path import exists , join , realpath
3
+ from os import uname
4
+ import glob
3
5
import sh
6
+ import os
7
+ import shutil
4
8
5
- """
6
- FFmpeg for Android compiled with x264, libass, fontconfig, freetype, fribidi and lame (Supports Android 4.1+)
7
9
8
- http://writingminds.github.io/ffmpeg-android/
9
- """
10
10
class FFMpegRecipe (Recipe ):
11
+ version = '2.8.8'
12
+ url = 'http://ffmpeg.org/releases/ffmpeg-{version}.tar.bz2'
13
+ depends = ['openssl' , 'ffpyplayer_codecs' ] # TODO should be opts_depends
14
+ patches = ['patches/fix-libshine-configure.patch' ]
11
15
12
- version = 'master'
13
- url = 'git+https://github.com/WritingMinds/ffmpeg-android.git'
14
- patches = ['settings.patch' ]
16
+ # TODO add should_build(self, arch)
15
17
18
+ def prebuild_arch (self , arch ):
19
+ self .apply_patches (arch )
16
20
17
- def should_build (self , arch ):
18
- return not exists (self .get_build_bin (arch ))
19
-
21
+ def get_recipe_env (self ,arch ):
22
+ env = super (FFMpegRecipe , self ).get_recipe_env (arch )
23
+ env ['NDK' ] = self .ctx .ndk_dir
24
+ return env
20
25
21
26
def build_arch (self , arch ):
22
- super (FFMpegRecipe , self ).build_arch (arch )
23
- env = self .get_recipe_env (arch )
24
- build_dir = self .get_build_dir (arch .arch )
25
- with current_directory (build_dir ):
26
- bash = sh .Command ('bash' )
27
- shprint (bash , 'init_update_libs.sh' )
28
- shprint (bash , 'android_build.sh' , _env = env )
27
+ with current_directory (self .get_build_dir (arch .arch )):
28
+ env = arch .get_env ()
29
29
30
+ flags = ['--disable-everything' ]
31
+ cflags = []
32
+ ldflags = []
30
33
31
- def get_build_bin (self , arch ):
32
- build_dir = self .get_build_dir (arch .arch )
33
- return join (build_dir , 'build' , arch .arch , 'bin' , 'ffmpeg' )
34
+ if 'openssl' in self .ctx .recipe_build_order :
35
+ flags += [
36
+ '--enable-openssl' ,
37
+ '--enable-nonfree' ,
38
+ '--enable-protocol=https,tls_openssl' ,
39
+ ]
40
+ build_dir = Recipe .get_recipe ('openssl' , self .ctx ).get_build_dir (arch .arch )
41
+ cflags += ['-I' + build_dir + '/include/' ]
42
+ ldflags += ['-L' + build_dir ]
34
43
44
+ if 'ffpyplayer_codecs' in self .ctx .recipe_build_order :
45
+ # libx264
46
+ flags += ['--enable-libx264' ]
47
+ build_dir = Recipe .get_recipe ('libx264' , self .ctx ).get_build_dir (arch .arch )
48
+ cflags += ['-I' + build_dir + '/include/' ]
49
+ ldflags += ['-lx264' , '-L' + build_dir + '/lib/' ]
35
50
36
- def get_recipe_env (self , arch ):
37
- env = super (FFMpegRecipe , self ).get_recipe_env (arch )
38
- env ['ANDROID_NDK' ] = self .ctx .ndk_dir
39
- env ['ANDROID_API' ] = str (self .ctx .android_api )
40
- return env
51
+ # libshine
52
+ flags += ['--enable-libshine' ]
53
+ build_dir = Recipe .get_recipe ('libshine' , self .ctx ).get_build_dir (arch .arch )
54
+ cflags += ['-I' + build_dir + '/include/' ]
55
+ ldflags += ['-lshine' , '-L' + build_dir + '/lib/' ]
56
+
57
+ # Enable all codecs:
58
+ flags += [
59
+ '--enable-parsers' ,
60
+ '--enable-decoders' ,
61
+ '--enable-encoders' ,
62
+ '--enable-muxers' ,
63
+ '--enable-demuxers' ,
64
+ ]
65
+ else :
66
+ # Enable codecs only for .mp4:
67
+ flags += [
68
+ '--enable-parser=h264,aac' ,
69
+ '--enable-decoder=h263,h264,aac' ,
70
+ ]
71
+
72
+ # disable some unused algo
73
+ # note: "golomb" are the one used in our video test, so don't use --disable-golomb
74
+ # note: and for aac decoding: "rdft", "mdct", and "fft" are needed
75
+ flags += [
76
+ '--disable-dxva2 --disable-vdpau --disable-vaapi' ,
77
+ '--disable-dct' ,
78
+ ]
79
+
80
+ # needed to prevent _ffmpeg.so: version node not found for symbol av_init_packet@LIBAVFORMAT_52
81
+ # /usr/bin/ld: failed to set dynamic section sizes: Bad value
82
+ flags += [
83
+ '--disable-symver' ,
84
+ ]
85
+
86
+ # disable binaries / doc
87
+ flags += [
88
+ '--disable-ffmpeg' ,
89
+ '--disable-ffplay' ,
90
+ '--disable-ffprobe' ,
91
+ '--disable-ffserver' ,
92
+ '--disable-doc' ,
93
+ ]
94
+
95
+ # other flags:
96
+ flags += [
97
+ '--enable-filter=aresample,resample,crop,adelay,volume' ,
98
+ '--enable-protocol=file,http' ,
99
+ '--enable-small' ,
100
+ '--enable-hwaccels' ,
101
+ '--enable-gpl' ,
102
+ '--enable-pic' ,
103
+ '--disable-static' ,
104
+ '--enable-shared' ,
105
+ ]
106
+
107
+ # android:
108
+ flags += [
109
+ '--target-os=android' ,
110
+ '--cross-prefix=arm-linux-androideabi-' ,
111
+ '--arch=arm' ,
112
+ '--sysroot=' + self .ctx .ndk_platform ,
113
+ '--enable-neon' ,
114
+ '--prefix={}' .format (realpath ('.' )),
115
+ ]
116
+ cflags = [
117
+ '-march=armv7-a' ,
118
+ '-mfpu=vfpv3-d16' ,
119
+ '-mfloat-abi=softfp' ,
120
+ '-fPIC' ,
121
+ '-DANDROID' ,
122
+ ] + cflags
123
+
124
+ env ['CFLAGS' ] += ' ' + ' ' .join (cflags )
125
+ env ['LDFLAGS' ] += ' ' + ' ' .join (ldflags )
41
126
127
+ configure = sh .Command ('./configure' )
128
+ shprint (configure , * flags , _env = env )
129
+ shprint (sh .make , '-j4' , _env = env )
130
+ shprint (sh .make , 'install' , _env = env )
131
+ # copy libs:
132
+ sh .cp ('-a' , sh .glob ('./lib/lib*.so' ), self .ctx .get_libs_dir (arch .arch ))
42
133
43
- recipe = FFMpegRecipe ()
134
+ recipe = FFMpegRecipe ()
0 commit comments