Skip to content

Commit c464b66

Browse files
committed
add build ios framework script
rename bundle
1 parent 92e0663 commit c464b66

File tree

3 files changed

+197
-1
lines changed

3 files changed

+197
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
scratch*
22
thin*
33
fat*
4+
FFmpeg.framework
45
FFmpeg-*
56
.DS_Store

build-ffmpeg-iOS-framework.sh

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/bin/sh
2+
3+
# directories
4+
SCRATCH=`pwd`/"scratch"
5+
ARCHS="arm64 armv7 i386 x86_64"
6+
7+
FFMPEG_VERSION="3.4"
8+
export FFMPEG_VERSION
9+
HEADER_SUFFIX=".h"
10+
CURRENT_FOLDER=`pwd`
11+
FRAMEWORK_NAME="FFmpeg"
12+
FRAMEWORK_EXT=".framework"
13+
FRAMEWORK="$FRAMEWORK_NAME$FRAMEWORK_EXT"
14+
BUILD_FOLDER="$CURRENT_FOLDER/FFmpeg-iOS"
15+
BUILD_THIN_FOLDER="$CURRENT_FOLDER/thin"
16+
BUILD_INCLUDE_FOLDER="$BUILD_FOLDER/include"
17+
BUILD_LIB_FOLDER="$BUILD_FOLDER/lib"
18+
OUTPUT_FOLDER="$CURRENT_FOLDER/$FRAMEWORK"
19+
OUTPUT_INFO_PLIST_FILE="$OUTPUT_FOLDER/Info.plist"
20+
OUTPUT_HEADER_FOLDER="$OUTPUT_FOLDER/Headers"
21+
OUTPUT_UMBRELLA_HEADER="$OUTPUT_HEADER_FOLDER/ffmpeg.h"
22+
OUTPUT_MODULES_FOLDER="$OUTPUT_FOLDER/Modules"
23+
OUTPUT_MODULES_FILE="$OUTPUT_MODULES_FOLDER/module.modulemap"
24+
VERSION_NEW_NAME="Version.h"
25+
BUNDLE_ID="org.ffmpeg.FFmpeg"
26+
27+
function CreateFramework() {
28+
rm -rf $OUTPUT_FOLDER
29+
mkdir -p $OUTPUT_HEADER_FOLDER $OUTPUT_MODULES_FOLDER
30+
}
31+
32+
function CompileSource() {
33+
./build-ffmpeg.sh $ARCHS
34+
./build-ffmpeg.sh lipo
35+
}
36+
37+
function MergeStaticLibrary() {
38+
local files=""
39+
40+
for ARCH in $ARCHS; do
41+
folder="$SCRATCH/$ARCH"
42+
name="$FRAMEWORK_NAME$ARCH.a"
43+
ar cru $name $(find $folder -name "*.o")
44+
files="$files $name"
45+
done
46+
47+
lipo -create $files -output FFmpeg
48+
49+
for file in $files; do
50+
rm -rf $file
51+
done
52+
mv $FRAMEWORK_NAME $OUTPUT_FOLDER
53+
}
54+
55+
function RenameHeader() {
56+
local include_folder="$(pwd)/FFmpeg-iOS/include"
57+
local need_replace_version_folder=""
58+
for folder in "$include_folder"/*; do
59+
local folder_name=`basename $folder`
60+
local verstion_file_name="$folder_name$VERSION_NEW_NAME"
61+
for header in "$folder"/*; do
62+
local header_name=`basename $header`
63+
64+
local dst_name=$header_name
65+
if [ $header_name == "version.h" ]; then
66+
dst_name=$verstion_file_name
67+
fi
68+
69+
local dst_folder=$OUTPUT_HEADER_FOLDER
70+
local file_name="$folder/$header_name"
71+
local dst_file_name="$dst_folder/$dst_name"
72+
cp $file_name $dst_file_name
73+
find "$dst_folder" -name "$dst_name" -type f -exec sed -i '' "s/\"version.h\"/\"$verstion_file_name\"/g" {} \;
74+
done
75+
need_replace_version_folder="$need_replace_version_folder $folder_name"
76+
done
77+
78+
for folder_name in $need_replace_version_folder; do
79+
local verstion_file_name="$folder_name$VERSION_NEW_NAME"
80+
find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/\"$folder_name\/version.h\"/\"$verstion_file_name\"/g" {} \;
81+
done
82+
find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/libavformat\///g" {} \;
83+
find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/libavutil\///g" {} \;
84+
find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/libavcodec\///g" {} \;
85+
}
86+
87+
# COPY MISSING inttypes.h
88+
function CopyInttype() {
89+
local file="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/inttypes.h"
90+
cp $file $OUTPUT_HEADER_FOLDER
91+
find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/<inttypes.h>/\"inttypes.h\"/g" {} \;
92+
}
93+
94+
function CreateModulemapAndUmbrellaHeader() {
95+
#create ffmpeg.h
96+
cat > $OUTPUT_UMBRELLA_HEADER <<EOF
97+
#import <Foundation/Foundation.h>
98+
#import <VideoToolbox/VideoToolbox.h>
99+
#import <AudioToolbox/AudioToolbox.h>
100+
#include "avcodec.h"
101+
#include "avdevice.h"
102+
#include "avfilter.h"
103+
#include "avformat.h"
104+
#include "avutil.h"
105+
#include "swscale.h"
106+
#include "swresample.h"
107+
double FFmpegVersionNumber = $FFMPEG_VERSION;
108+
EOF
109+
110+
cat > $OUTPUT_MODULES_FILE <<EOF
111+
framework module $FRAMEWORK_NAME {
112+
umbrella header "ffmpeg.h"
113+
114+
export *
115+
module * { export * }
116+
}
117+
EOF
118+
}
119+
120+
function CreateInfoPlist() {
121+
DEFAULT_iOS_SDK_VERSION=`defaults read $(xcode-select -p)/Platforms/iPhoneOS.platform/version CFBundleShortVersionString`
122+
DTCompiler=`defaults read $(xcode-select -p)/../info DTCompiler`
123+
DTPlatformBuild=`defaults read $(xcode-select -p)/../info DTPlatformBuild`
124+
DTSDKBuild=`defaults read $(xcode-select -p)/../info DTSDKBuild`
125+
DTXcode=`defaults read $(xcode-select -p)/../info DTXcode`
126+
DTXcodeBuild=`defaults read $(xcode-select -p)/../info DTXcodeBuild`
127+
OS_BUILD_VERSION=$(sw_vers -buildVersion)
128+
cat > $OUTPUT_INFO_PLIST_FILE <<EOF
129+
<?xml version="1.0" encoding="UTF-8"?>
130+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
131+
<plist version="1.0">
132+
<dict>
133+
<key>BuildMachineOSBuild</key>
134+
<string>$OS_BUILD_VERSION</string>
135+
<key>CFBundleDevelopmentRegion</key>
136+
<string>en</string>
137+
<key>CFBundleExecutable</key>
138+
<string>$FRAMEWORK_NAME</string>
139+
<key>CFBundleIdentifier</key>
140+
<string>$BUNDLE_ID</string>
141+
<key>CFBundleInfoDictionaryVersion</key>
142+
<string>6.0</string>
143+
<key>CFBundleName</key>
144+
<string>$FRAMEWORK_NAME</string>
145+
<key>CFBundlePackageType</key>
146+
<string>FMWK</string>
147+
<key>CFBundleShortVersionString</key>
148+
<string>$FFMPEG_VERSION</string>
149+
<key>CFBundleSignature</key>
150+
<string>????</string>
151+
<key>CFBundleSupportedPlatforms</key>
152+
<array>
153+
<string>iPhoneOS</string>
154+
</array>
155+
<key>CFBundleVersion</key>
156+
<string>1</string>
157+
<key>DTCompiler</key>
158+
<string>$DTCompiler</string>
159+
<key>DTPlatformBuild</key>
160+
<string>$DTPlatformBuild</string>
161+
<key>DTPlatformName</key>
162+
<string>iphoneos</string>
163+
<key>DTPlatformVersion</key>
164+
<string>$DEFAULT_iOS_SDK_VERSION</string>
165+
<key>DTSDKBuild</key>
166+
<string>$DTSDKBuild</string>
167+
<key>DTSDKName</key>
168+
<string>iphoneos$DEFAULT_iOS_SDK_VERSION</string>
169+
<key>DTXcode</key>
170+
<string>$DTXcode</string>
171+
<key>DTXcodeBuild</key>
172+
<string>$DTXcodeBuild</string>
173+
<key>MinimumOSVersion</key>
174+
<string>8.0</string>
175+
<key>UIDeviceFamily</key>
176+
<array>
177+
<integer>1</integer>
178+
<integer>2</integer>
179+
</array>
180+
</dict>
181+
</plist>
182+
EOF
183+
}
184+
185+
CompileSource
186+
CreateFramework
187+
MergeStaticLibrary
188+
RenameHeader
189+
CreateModulemapAndUmbrellaHeader
190+
CopyInttype
191+
CreateInfoPlist

build-ffmpeg.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/bin/sh
22

33
# directories
4-
SOURCE="ffmpeg-3.4"
4+
FF_VERSION="3.4"
5+
if [[ $FFMPEG_VERSION != "" ]]; then
6+
FF_VERSION=$FFMPEG_VERSION
7+
fi
8+
SOURCE="ffmpeg-$FF_VERSION"
59
FAT="FFmpeg-iOS"
610

711
SCRATCH="scratch"

0 commit comments

Comments
 (0)