forked from jold/CocoaFFmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-ffmpeg.sh
executable file
·236 lines (213 loc) · 5.33 KB
/
build-ffmpeg.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/sh
#
# this script has been optimized to decrease the size by compiling the necessary formats only
# video codecs: h264 (enable h263)
# audio codecs: AAC (enable mp3)
#
# to download the latest ffmpeg project use: git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
# directories
SOURCE="ffmpeg"
FAT="universal"
VERSION="2.2"
ARGS=`echo "$@" | sed "s@minimal@@"`
ARCHS="arm64 armv7s armv7 x86_64 i386"
COMPILE="y"
LIPO="y"
if [[ $# == 0 || $ARGS =~ .*-h|--help* ]]; then
echo "\
Usage: `basename $0` [minimal|entire] [arm64|armv7s|armv7|x86_64|i386] [lipo] \n\
common:\n\
`basename $0` minimal - build optimized libraries with all necessary stuff and h264 codec \n\
`basename $0` minimal arm64 armv7s armv7 - build minimal configuration for device architectures only \n\
miscellaneous: \n\
`basename $0` universal - build configuration with all codecs \n\
`basename $0` lipo - join created libraries only for architectures into one fat library"
exit 0
fi
if [ "$ARGS" ]
then
if [[ "$@" =~ .*lipo* ]]
then
ARGS=`echo $ARGS | sed "s@lipo@@"`
echo "skip compile"
# skip compile
COMPILE=
fi
if [[ $ARCHS =~ .$`echo $ARGS`$ ]]
then
# skip lipo
LIPO=
fi
ARCHS=$ARGS
fi
echo $ARCHS
DEPLOYMENT_TARGET="6.0"
SCRATCH="scratch"
# must be an absolute path
THIN=`pwd`/"thin"
# absolute path to x264 library
#X264=`pwd`/fat_x264
DEVELOPER=`xcode-select -print-path`
# universal library
CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \
--disable-doc --enable-pic"
# optimized library
if [[ "$@" =~ .*minimal* ]]
then
CONFIGURE_FLAGS="--enable-cross-compile \
--disable-everything \
--disable-logging \
--disable-network \
--disable-encoders \
--disable-decoders \
--disable-muxers \
--disable-demuxers \
--disable-protocols \
--disable-devices \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-avfilter \
--disable-iconv \
--disable-bzlib \
--disable-mmx \
--disable-mmxext \
--disable-amd3dnow \
--disable-amd3dnowext \
--disable-sse \
--disable-sse2 \
--disable-sse3 \
--disable-sse4 \
--disable-avx \
--disable-fma4 \
--disable-swresample \
--disable-postproc \
--disable-bsfs \
--disable-filters \
--disable-asm \
--disable-yasm \
--disable-debug \
--disable-doc \
--disable-armv5te \
--disable-armv6 \
--disable-armv6t2 \
--enable-protocol=file \
--enable-avformat \
--enable-avcodec \
--enable-swscale \
--enable-demuxer=aac \
--enable-demuxer=mov \
--enable-demuxer=h264 \
--enable-decoder=aac \
--enable-decoder=h264 \
--enable-decoder=mpeg4 \
--enable-encoder=aac \
--enable-encoder=mpeg4 \
--enable-parser=aac \
--enable-parser=h264 \
--enable-pic"
echo 'minimalistic library configured'
fi
if [ "$X264" ]
then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
fi
# avresample
#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"
if [ "$COMPILE" ]
then
if [ ! `which yasm` ]
then
echo 'Yasm not found'
if [ ! `which brew` ]
then
echo 'Homebrew not found. Trying to install...'
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" \
|| exit 1
fi
echo 'Trying to install Yasm...'
brew install yasm || exit 1
fi
if [ ! `which gas-preprocessor.pl` ]
then
echo 'gas-preprocessor.pl not found. Trying to install...'
(curl --progress-bar -3L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
-o /usr/local/bin/gas-preprocessor.pl \
&& chmod +x /usr/local/bin/gas-preprocessor.pl) \
|| exit 1
fi
if [ ! -r $SOURCE-$VERSION ]
then
echo 'FFmpeg source not found. Trying to download...'
curl --progress-bar http://www.ffmpeg.org/releases/$SOURCE-$VERSION.tar.bz2 | tar xj \
|| exit 1
fi
CWD=`pwd`
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
CFLAGS="-arch $ARCH"
FF_ARCH="arm"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
else
PLATFORM="iPhoneOS"
CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET"
if [ "$ARCH" = "arm64" ]
then
FF_ARCH="aarch64"
EXPORT="GASPP_FIX_XCODE5=1"
fi
fi
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="$DEVELOPER/usr/bin/xcrun -sdk $XCRUN_SDK clang"
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
if [ "$X264" ]
then
CFLAGS="$CFLAGS -I$X264/include"
LDFLAGS="$LDFLAGS -L$X264/lib"
fi
$CWD/$SOURCE-$VERSION/configure \
--target-os=darwin \
--arch=$FF_ARCH \
--cc="$CC" \
$CONFIGURE_FLAGS \
--extra-cflags="$CFLAGS" \
--extra-cxxflags="$CXXFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$THIN/$ARCH" \
|| exit 1
make install -j3 --silent $EXPORT || exit 1
cd $CWD
done
fi
if [ "$LIPO" ]
then
for ARCH in $ARCHS
do
echo "creating universal binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$ARCH/lib
for LIB in *.a
do
cd $CWD
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
done
cd $CWD
cp -rf $THIN/$ARCH/include $FAT
done
fi
rm -rf $SCRATCH
echo "universal binaries can be found in '$FAT' folder"
echo 'library size: ' + `du -sh $FAT`
echo 'Build done, enjoy your custom FFMPEG library'
open $FAT