This repository was archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathffmpeg-android.sh
executable file
·218 lines (174 loc) · 4.93 KB
/
ffmpeg-android.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
VERSION=3.4.2
ARCHS="arm x86"
HOST=$(uname -sm | tr 'A-Z' 'a-z' | sed "s/\ /\-/g")
TOOLCHAIN_ROOT="/shared/dev/toolchain/android/$HOST/ndk-r16"
THREADS="-j$(sysctl -n hw.ncpu)"
cd "`dirname \"$0\"`"
########################################
usage()
{
cat << EOF
usage: $0 options
Build FFmpeg for Android
OPTIONS:
-h | --help
Display these options and exit.
--toolchain
Specify the Android NDK standalone toolchain root. Default: $TOOLCHAIN_ROOT
-version
Specify which version of FFmpeg to build. Default: $VERSION
-debug
Build without optimizations and without stripping symbols.
-v | --verbose
Display more output while running
EOF
}
missingParameter()
{
echo $1 requires a parameter
exit 1
}
unknownParameter()
{
if [[ -n $2 && $2 != "" ]]; then
echo Unknown argument \"$2\" for parameter $1.
else
echo Unknown argument $1
fi
exit 1
}
parseArgs()
{
while [ "$1" != "" ]; do
case $1 in
-h | --help)
usage
exit
;;
--debug)
DEBUG=1
;;
--toolchain)
if [[ -n $2 ]]; then
TOOLCHAIN_ROOT=$2
shift
else
missingParameter $1
fi
;;
--version)
if [[ -n $2 ]]; then
VERSION=$2
shift
else
missingParameter $1
fi
;;
-v | --verbose)
VERBOSE=1
;;
*)
unknownParameter $1
;;
esac
shift
done
}
########################################
unpackArchive()
{
# Exit the script if an error happens
set -e
if [ ! -e "ffmpeg-$VERSION.tar.bz2" ]; then
printf "Downloading ffmpeg-$VERSION.tar.bz2\n"
curl -L -o "$SRCDIR.tar.bz2" http://ffmpeg.org/releases/ffmpeg-$VERSION.tar.bz2
else
printf "Using ffmpeg-$VERSION.tar.bz2\n"
fi
rm -rf $SRCDIR
tar zxf ffmpeg-$VERSION.tar.bz2
}
########################################
buildFFmpeg()
{
cd $SRCDIR
codecs="aac pcm_alaw pcm_mulaw adpcm_g726 adpcm_ima_wav mjpeg wmav1 wmav2 wmv1 wmv2"
decoders="aac_fixed aac_latm adpcm_g726le h263 h264 hevc mjpegb mpeg4"
parsers="aac h263 h264 hevc mjpeg"
muxdemuxers="asf avi h263 h264 hevc mjpeg pcm_alaw pcm_mulaw wav"
demuxers="aac"
CONFIG_OPTS=("--disable-everything"
"--disable-programs"
"--disable-doc"
"--disable-network"
"--disable-armv5te"
"--disable-iconv"
"--enable-shared"
"--enable-neon"
"--enable-cross-compile"
"--enable-pic")
for x in ${codecs}; do
CONFIG_OPTS+=("--enable-encoder=$x" "--enable-decoder=$x")
done
for x in ${decoders}; do
CONFIG_OPTS+=("--enable-decoder=$x")
done
for x in ${parsers}; do
CONFIG_OPTS+=("--enable-parser=$x")
done
for x in ${muxdemuxers}; do
CONFIG_OPTS+=("--enable-muxer=$x" "--enable-demuxer=$x")
done
for x in ${demuxers}; do
CONFIG_OPTS+=("--enable-demuxer=$x")
done
if [[ -n $DEBUG ]]; then
CONFIG_OPTS+=("--disable-optimizations" "--disable-stripping")
fi
for ARCH in ${ARCHS}; do
mkdir -p "${OUTPUTDIR}/${ARCH}"
case $ARCH in
arm)
CONFIG_OPTS+=("--disable-asm")
CROSS_PREFIX="$TOOLCHAIN_ROOT/android-19/arm/bin/arm-linux-androideabi-"
;;
x86)
CROSS_PREFIX="$TOOLCHAIN_ROOT/android-19/x86/bin/i686-linux-android-"
;;
esac
configCmd=("./configure"
"--prefix=${OUTPUTDIR}/${ARCH}"
"--target-os=android"
"--arch=$ARCH"
"--cc=${CROSS_PREFIX}clang"
"--enable-cross-compile"
"--cross-prefix=$CROSS_PREFIX"
"${CONFIG_OPTS[*]}"
"> $OUTPUTDIR/$ARCH.log")
if [[ -n $VERBOSE ]]; then
printf "Configuring for $ARCH with:\n%s\n" "${configCmd[*]}"
else
printf "Configuring for $ARCH\n"
fi
eval "${configCmd[*]}"
printf "Building for ${ARCH}\n"
make clean >> $OUTPUTDIR/$ARCH.log
make $THREADS install >> $OUTPUTDIR/$ARCH.log
printf " - Done\n"
done
}
########################################
parseArgs $@
SRCDIR=$(pwd)/ffmpeg-$VERSION
OUTPUTDIR=$(pwd)/output/ffmpeg-$VERSION
format="%-18s %s\n"
printf "$format" "ARCHS:" $ARCHS
printf "$format" "VERSION:" $VERSION
printf "$format" "TOOLCHAIN_ROOT:" $TOOLCHAIN_ROOT
printf "$format" "DEBUG:" $( [[ -n $DEBUG ]] && printf "YES" || printf "NO")
rm -rf $OUTPUTDIR
mkdir -p $OUTPUTDIR
unpackArchive
buildFFmpeg
printf "Finished Successfully\n"