Skip to content

Commit 5b6ed28

Browse files
committed
Add ffpyplayer and dependencies recipes for new toolchain.
1 parent 31a3d59 commit 5b6ed28

File tree

7 files changed

+228
-47
lines changed

7 files changed

+228
-47
lines changed
Lines changed: 119 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,134 @@
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
35
import sh
6+
import os
7+
import shutil
48

5-
"""
6-
FFmpeg for Android compiled with x264, libass, fontconfig, freetype, fribidi and lame (Supports Android 4.1+)
79

8-
http://writingminds.github.io/ffmpeg-android/
9-
"""
1010
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']
1115

12-
version = 'master'
13-
url = 'git+https://github.com/WritingMinds/ffmpeg-android.git'
14-
patches = ['settings.patch']
16+
# TODO add should_build(self, arch)
1517

18+
def prebuild_arch(self, arch):
19+
self.apply_patches(arch)
1620

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
2025

2126
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()
2929

30+
flags = ['--disable-everything']
31+
cflags = []
32+
ldflags = []
3033

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]
3443

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/']
3550

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)
41126

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))
42133

43-
recipe = FFMpegRecipe()
134+
recipe = FFMpegRecipe()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- ./configure.orig 2016-09-19 04:41:33.000000000 +0300
2+
+++ ./configure 2016-12-06 19:12:05.046025000 +0300
3+
@@ -5260,7 +5260,7 @@
4+
enabled libquvi && require_pkg_config libquvi quvi/quvi.h quvi_init
5+
enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
6+
enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
7+
-enabled libshine && require_pkg_config shine shine/layer3.h shine_encode_buffer
8+
+enabled libshine && require "shine" shine/layer3.h shine_encode_buffer -lshine
9+
enabled libsmbclient && { use_pkg_config smbclient libsmbclient.h smbc_init ||
10+
require smbclient libsmbclient.h smbc_init -lsmbclient; }
11+
enabled libsnappy && require snappy snappy-c.h snappy_compress -lsnappy

pythonforandroid/recipes/ffmpeg/settings.patch

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from pythonforandroid.toolchain import Recipe, CythonRecipe, shprint, current_directory, ArchARM
2+
from os.path import exists, join, realpath
3+
from os import uname
4+
import glob
5+
import sh
6+
import os
7+
8+
9+
class FFPyPlayerRecipe(CythonRecipe):
10+
version = 'v4.0.0'
11+
url = 'https://github.com/matham/ffpyplayer/archive/{version}.zip'
12+
depends = ['python2', 'sdl2', 'ffmpeg']
13+
opt_depends = ['openssl', 'ffpyplayer_codecs']
14+
15+
def get_recipe_env(self, arch, with_flags_in_cc=True):
16+
env = super(FFPyPlayerRecipe, self).get_recipe_env(arch)
17+
18+
# TODO cannot find -lsdl error
19+
20+
env["SDL_INCLUDE_DIR"] = join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include')
21+
env["SDL_LIB_DIR"] = join(self.ctx.bootstrap.build_dir, 'libs', arch.arch)
22+
23+
build_dir = Recipe.get_recipe('ffmpeg', self.ctx).get_build_dir(arch.arch)
24+
env["FFMPEG_INCLUDE_DIR"] = join(build_dir, "include")
25+
env["FFMPEG_LIB_DIR"] = join(build_dir, "lib")
26+
return env
27+
28+
recipe = FFPyPlayerRecipe()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pythonforandroid.toolchain import Recipe
2+
3+
4+
class FFPyPlayerCodecsRecipe(Recipe):
5+
depends = ['libshine', 'libx264']
6+
7+
def build_arch(self, arch):
8+
pass
9+
10+
recipe = FFPyPlayerCodecsRecipe()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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
5+
import sh
6+
7+
8+
class LibShineRecipe(Recipe):
9+
version = 'master'
10+
url = 'https://github.com/toots/shine/archive/{version}.zip'
11+
12+
# TODO add should_build(self, arch)
13+
14+
def build_arch(self, arch):
15+
with current_directory(self.get_build_dir(arch.arch)):
16+
env = self.get_recipe_env(arch)
17+
shprint(sh.Command('./bootstrap'))
18+
configure = sh.Command('./configure')
19+
shprint(configure,
20+
'--host=arm-linux',
21+
'--enable-pic',
22+
'--disable-shared',
23+
'--enable-static',
24+
'--prefix={}'.format(realpath('.')),
25+
_env=env)
26+
shprint(sh.make, '-j4', _env=env)
27+
shprint(sh.make, 'install', _env=env)
28+
29+
recipe = LibShineRecipe()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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
5+
import sh
6+
7+
8+
class LibX264Recipe(Recipe):
9+
version = 'last_stable'
10+
url = 'http://mirror.yandex.ru/mirrors/ftp.videolan.org/x264/snapshots/{version}_x264.tar.bz2'
11+
12+
# TODO add should_build(self, arch)
13+
14+
def build_arch(self, arch):
15+
with current_directory(self.get_build_dir(arch.arch)):
16+
env = self.get_recipe_env(arch)
17+
configure = sh.Command('./configure')
18+
shprint(configure,
19+
'--cross-prefix=arm-linux-androideabi-',
20+
'--host=arm-linux',
21+
'--disable-asm',
22+
'--disable-cli',
23+
'--enable-pic',
24+
'--disable-shared',
25+
'--enable-static',
26+
'--prefix={}'.format(realpath('.')),
27+
_env=env)
28+
shprint(sh.make, '-j4', _env=env)
29+
shprint(sh.make, 'install', _env=env)
30+
31+
recipe = LibX264Recipe()

0 commit comments

Comments
 (0)