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