Ticket #6324: build-ffmpeg.sh

File build-ffmpeg.sh, 4.0 KB (added by ioeir2, 9 years ago)
Line 
1#!/bin/sh
2
3# directories
4SOURCE="ffmpeg-3.3"
5FAT="FFmpeg-iOS"
6
7SCRATCH="scratch"
8# must be an absolute path
9THIN=`pwd`/"thin"
10
11# absolute path to x264 library
12#X264=`pwd`/fat-x264
13
14#FDK_AAC=`pwd`/../fdk-aac-build-script-for-iOS/fdk-aac-ios
15
16CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \
17 --disable-doc --enable-pic"
18
19#if [ "$X264" ]
20#then
21# CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
22#fi
23
24#if [ "$FDK_AAC" ]
25#then
26# CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-libfdk-aac"
27#fi
28
29# avresample
30#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"
31
32#ARCHS="arm64 armv7 x86_64 i386"
33ARCHS="arm64"
34
35COMPILE="y"
36LIPO="y"
37
38DEPLOYMENT_TARGET="9.0"
39
40if [ "$*" ]
41then
42 if [ "$*" = "lipo" ]
43 then
44 # skip compile
45 COMPILE=
46 else
47 ARCHS="$*"
48 if [ $# -eq 1 ]
49 then
50 # skip lipo
51 LIPO=
52 fi
53 fi
54fi
55
56if [ "$COMPILE" ]
57then
58 if [ ! `which yasm` ]
59 then
60 echo 'Yasm not found'
61 if [ ! `which brew` ]
62 then
63 echo 'Homebrew not found. Trying to install...'
64 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
65 || exit 1
66 fi
67 echo 'Trying to install Yasm...'
68 brew install yasm || exit 1
69 fi
70 if [ ! `which gas-preprocessor.pl` ]
71 then
72 echo 'gas-preprocessor.pl not found. Trying to install...'
73 (curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
74 -o /usr/local/bin/gas-preprocessor.pl \
75 && chmod +x /usr/local/bin/gas-preprocessor.pl) \
76 || exit 1
77 fi
78
79 if [ ! -r $SOURCE ]
80 then
81 echo 'FFmpeg source not found. Trying to download...'
82 curl http://www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj \
83 || exit 1
84 fi
85
86 CWD=`pwd`
87
88 for ARCH in $ARCHS
89 do
90 echo "building $ARCH..."
91 mkdir -p "$SCRATCH/$ARCH"
92 cd "$SCRATCH/$ARCH"
93
94 CFLAGS="-arch $ARCH"
95 if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
96 then
97 PLATFORM="iPhoneSimulator"
98 CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
99 else
100 PLATFORM="iPhoneOS"
101 CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"
102 if [ "$ARCH" = "arm64" ]
103 then
104 EXPORT="GASPP_FIX_XCODE5=1"
105 fi
106 fi
107
108 XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
109 CC="xcrun -sdk $XCRUN_SDK clang"
110 CXXFLAGS="$CFLAGS"
111 LDFLAGS="$CFLAGS"
112# if [ "$X264" ]
113# then
114# CFLAGS="$CFLAGS -I$X264/include"
115# LDFLAGS="$LDFLAGS -L$X264/lib"
116# fi
117# if [ "$FDK_AAC" ]
118# then
119# CFLAGS="$CFLAGS -I$FDK_AAC/include"
120# LDFLAGS="$LDFLAGS -L$FDK_AAC/lib"
121# fi
122
123 TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
124 --target-os=darwin \
125 --arch=$ARCH \
126 --cc="$CC" \
127 $CONFIGURE_FLAGS \
128 --extra-cflags="$CFLAGS" \
129 --extra-ldflags="$LDFLAGS" \
130 --prefix="$THIN/$ARCH" \
131 --disable-shared \
132 --enable-static \
133 --disable-everything \
134 --enable-decoder=hevc \
135 --enable-decoder=h264 \
136 --enable-decoder=mjpeg \
137 --enable-decoder=mpeg4 \
138 --enable-decoder=amrnb \
139 --enable-decoder=aac \
140 --enable-parser=hevc \
141 --enable-parser=h264 \
142 --enable-parser=mpegvideo \
143 --enable-parser=mjpeg \
144 --enable-network \
145 --enable-protocol=tcp \
146 --enable-demuxer=hevc \
147 --enable-demuxer=h264 \
148 --enable-demuxer=rtsp \
149 --enable-demuxer=mjpeg \
150 --disable-ffplay \
151 --disable-ffmpeg \
152 --disable-ffprobe \
153 --disable-avfilter \
154 --disable-avdevice \
155 --disable-ffserver \
156 --enable-cross-compile \
157 || exit 1
158
159 # Fixing RTSP issue on iOS9 compiled against iOS10
160 sed -i -- 's/HAVE_CLOCK_GETTIME 1/HAVE_CLOCK_GETTIME 0/g' config.h
161
162 make -j8 install $EXPORT || exit 1
163 cd $CWD
164 done
165fi
166
167if [ "$LIPO" ]
168then
169 echo "building fat binaries..."
170 mkdir -p $FAT/lib
171 set - $ARCHS
172 CWD=`pwd`
173 cd $THIN/$1/lib
174 for LIB in *.a
175 do
176 cd $CWD
177 echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
178 lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
179 done
180
181 cd $CWD
182 cp -rf $THIN/$1/include $FAT
183fi
184
185echo Done