Skip to content

Commit f966541

Browse files
authored
Merge pull request kivy#954 from germn/ffpyplayer_new_toolchain
Add ffpyplayer and dependencies recipes for new toolchain.
2 parents e2ba89f + 4c32511 commit f966541

File tree

8 files changed

+240
-48
lines changed

8 files changed

+240
-48
lines changed

doc/source/quickstart.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ p4a has several dependencies that must be installed:
6161
- unzip
6262
- virtualenv (can be installed via pip)
6363
- ccache (optional)
64+
- autoconf (for ffpyplayer_codecs recipe)
65+
- libtool (for ffpyplayer_codecs recipe)
6466

6567
On recent versions of Ubuntu and its derivatives you may be able to
6668
install most of these with::
6769

6870
sudo dpkg --add-architecture i386
6971
sudo apt-get update
70-
sudo apt-get install -y build-essential git zlib1g-dev python2.7 python2.7-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-7-jdk unzip ant ccache
72+
sudo apt-get install -y build-essential ccache git zlib1g-dev python2.7 python2.7-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-7-jdk unzip ant ccache autoconf libtool
7173

7274
On Arch Linux (64 bit) you should be able to run the following to
7375
install most of the dependencies (note: this list may not be
Lines changed: 123 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,138 @@
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-
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']
1617

1718
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'))
1921

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
2029

2130
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()
2933

34+
flags = ['--disable-everything']
35+
cflags = []
36+
ldflags = []
3037

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

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

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

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

43-
recipe = FFMpegRecipe()
138+
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 = 'master'
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+
env["SDL_INCLUDE_DIR"] = join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include')
19+
env["SDL_LIB_DIR"] = join(self.ctx.bootstrap.build_dir, 'libs', arch.arch)
20+
21+
build_dir = Recipe.get_recipe('ffmpeg', self.ctx).get_build_dir(arch.arch)
22+
env["FFMPEG_INCLUDE_DIR"] = join(build_dir, "include")
23+
env["FFMPEG_LIB_DIR"] = join(build_dir, "lib")
24+
25+
return env
26+
27+
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 = '20aee967f67abefd065c196eec7ce21adbbe1549'
10+
url = 'https://github.com/toots/shine/archive/{version}.zip'
11+
md5sum = 'bbf1f657e6adccb5e79f59da9ecfac2d'
12+
13+
def should_build(self, arch):
14+
build_dir = self.get_build_dir(arch.arch)
15+
return not exists(join(build_dir, 'lib', 'libshine.a'))
16+
17+
def build_arch(self, arch):
18+
with current_directory(self.get_build_dir(arch.arch)):
19+
env = self.get_recipe_env(arch)
20+
shprint(sh.Command('./bootstrap'))
21+
configure = sh.Command('./configure')
22+
shprint(configure,
23+
'--host=arm-linux',
24+
'--enable-pic',
25+
'--disable-shared',
26+
'--enable-static',
27+
'--prefix={}'.format(realpath('.')),
28+
_env=env)
29+
shprint(sh.make, '-j4', _env=env)
30+
shprint(sh.make, 'install', _env=env)
31+
32+
recipe = LibShineRecipe()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 = 'x264-snapshot-20170608-2245-stable' # using mirror url since can't use ftp
10+
url = 'http://mirror.yandex.ru/mirrors/ftp.videolan.org/x264/snapshots/{version}.tar.bz2'
11+
md5sum = 'adf3b87f759b5cc9f100f8cf99276f77'
12+
13+
def should_build(self, arch):
14+
build_dir = self.get_build_dir(arch.arch)
15+
return not exists(join(build_dir, 'lib', 'libx264.a'))
16+
17+
def build_arch(self, arch):
18+
with current_directory(self.get_build_dir(arch.arch)):
19+
env = self.get_recipe_env(arch)
20+
configure = sh.Command('./configure')
21+
shprint(configure,
22+
'--cross-prefix=arm-linux-androideabi-',
23+
'--host=arm-linux',
24+
'--disable-asm',
25+
'--disable-cli',
26+
'--enable-pic',
27+
'--disable-shared',
28+
'--enable-static',
29+
'--prefix={}'.format(realpath('.')),
30+
_env=env)
31+
shprint(sh.make, '-j4', _env=env)
32+
shprint(sh.make, 'install', _env=env)
33+
34+
recipe = LibX264Recipe()

0 commit comments

Comments
 (0)