Skip to content

Commit f511f38

Browse files
Upgrade ffmpeg to v7.0.1, dylibs cleanup
1 parent 162ea57 commit f511f38

File tree

20 files changed

+385
-95
lines changed

20 files changed

+385
-95
lines changed

FFmpegPlayer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
3E1B587C2C58198E0097ABBF /* build-ffmpeg.sh in Resources */ = {isa = PBXBuildFile; fileRef = 3E1B58742C58198E0097ABBF /* build-ffmpeg.sh */; };
1111
3E1B58802C58198E0097ABBF /* README.txt in Resources */ = {isa = PBXBuildFile; fileRef = 3E1B58782C58198E0097ABBF /* README.txt */; };
1212
3E1B58842C583F210097ABBF /* FFmpegChannelLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E1B58832C583F210097ABBF /* FFmpegChannelLayout.swift */; };
13+
3E5701942C6EA5FB007B8611 /* FFmpegReplayGain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E5701932C6EA5FB007B8611 /* FFmpegReplayGain.swift */; };
1314
3E7B652D291199B600FDB51F /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E7B6481291199B600FDB51F /* Constants.swift */; };
1415
3E7B652E291199B600FDB51F /* OpenDialogButtonCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E7B6483291199B600FDB51F /* OpenDialogButtonCell.swift */; };
1516
3E7B652F291199B600FDB51F /* SliderCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E7B6484291199B600FDB51F /* SliderCells.swift */; };
@@ -84,6 +85,7 @@
8485
3E1B58742C58198E0097ABBF /* build-ffmpeg.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "build-ffmpeg.sh"; sourceTree = "<group>"; };
8586
3E1B58782C58198E0097ABBF /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
8687
3E1B58832C583F210097ABBF /* FFmpegChannelLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FFmpegChannelLayout.swift; sourceTree = "<group>"; };
88+
3E5701932C6EA5FB007B8611 /* FFmpegReplayGain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FFmpegReplayGain.swift; sourceTree = "<group>"; };
8789
3E7B64702911993300FDB51F /* FFmpegPlayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FFmpegPlayer.app; sourceTree = BUILT_PRODUCTS_DIR; };
8890
3E7B6481291199B600FDB51F /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
8991
3E7B6483291199B600FDB51F /* OpenDialogButtonCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenDialogButtonCell.swift; sourceTree = "<group>"; };
@@ -238,6 +240,7 @@
238240
3E7B6496291199B600FDB51F /* FFmpegStreamProtocol.swift */,
239241
3E7B6497291199B600FDB51F /* FFmpegCodec.swift */,
240242
3E1B58832C583F210097ABBF /* FFmpegChannelLayout.swift */,
243+
3E5701932C6EA5FB007B8611 /* FFmpegReplayGain.swift */,
241244
);
242245
path = Wrappers;
243246
sourceTree = "<group>";
@@ -448,6 +451,7 @@
448451
3E7B652E291199B600FDB51F /* OpenDialogButtonCell.swift in Sources */,
449452
3E7B654A291199B600FDB51F /* ConcurrentArray.swift in Sources */,
450453
3E7B6556291199B600FDB51F /* AudioEngine.swift in Sources */,
454+
3E5701942C6EA5FB007B8611 /* FFmpegReplayGain.swift in Sources */,
451455
3E7B653F291199B600FDB51F /* FFmpegCodec.swift in Sources */,
452456
3E7B6545291199B600FDB51F /* FFmpegPacketFrames.swift in Sources */,
453457
3E7B6541291199B600FDB51F /* FFmpegPacketTable.swift in Sources */,
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Resources/ffmpeg/build-ffmpeg.sh

Lines changed: 136 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,68 @@
11
#!/bin/sh
22

3-
# Pre-requisites (need to be installed on this system to build FFmpeg) :
3+
# common.sh
4+
# Aural-macOS
45
#
5-
# 1 - Homebrew (Download instructions here: https://brew.sh/)
6-
# 2 - nasm - assembler for x86 (Run "brew install nasm" ... after installing Homebrew)
7-
# 3 - clang - C compiler (Run "xcode-select --install")
6+
# Created by Kartik Venugopal on 22/09/22.
7+
# Copyright © 2024 Kartik Venugopal. All rights reserved.
88

9-
# MARK: Constants -------------------------------------------------------------------------------------
9+
# Common variables and functions used across the ffmpeg build scripts.
1010

11-
# FFmpeg release version
12-
export ffmpegVersion="4.4"
11+
# MARK: Constants -------------------------------------------------------------------------------------
1312

1413
# Architectures
1514
export architectures=("x86_64" "arm64")
1615

17-
# Library versions
18-
export avcodecVersion=58
19-
export avformatVersion=58
20-
export avutilVersion=56
21-
export swresampleVersion=3
16+
# Deployment target for Aural Player.
17+
export deploymentTarget="11.0"
18+
19+
# Points to the latest MacOS SDK installed.
20+
export sdk="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
21+
22+
# FFmpeg release version
23+
export ffmpegVersion="7.0.1"
2224

2325
export avcodecLibName="libavcodec"
2426
export avformatLibName="libavformat"
2527
export avutilLibName="libavutil"
2628
export swresampleLibName="libswresample"
2729

28-
export libNames=($avcodecLibName $avformatLibName $avutilLibName $swresampleLibName)
29-
30-
export avcodecHeaderNames=("ac3_parser.h" "adts_parser.h" "avcodec.h" "avdct.h" "avfft.h" "bsf.h" "codec.h" "codec_desc.h" "codec_id.h" "codec_par.h" "d3d11va.h" "dirac.h" "dv_profile.h" "dxva2.h" "jni.h" "mediacodec.h" "packet.h" "qsv.h" "vaapi.h" "vdpau.h" "version.h" "videotoolbox.h" "vorbis_parser.h" "xvmc.h")
31-
32-
export avformatHeaderNames=("avformat.h" "avio.h" "version.h")
33-
34-
export avutilHeaderNames=("adler32.h" "aes.h" "aes_ctr.h" "attributes.h" "audio_fifo.h" "avassert.h" "avconfig.h" "avstring.h" "avutil.h" "base64.h" "blowfish.h" "bprint.h" "bswap.h" "buffer.h" "camellia.h" "cast5.h" "channel_layout.h" "common.h" "cpu.h" "crc.h" "des.h" "dict.h" "display.h" "dovi_meta.h" "downmix_info.h" "encryption_info.h" "error.h" "eval.h" "fifo.h" "file.h" "film_grain_params.h" "frame.h" "hash.h" "hdr_dynamic_metadata.h" "hmac.h" "hwcontext.h" "hwcontext_cuda.h" "hwcontext_d3d11va.h" "hwcontext_drm.h" "hwcontext_dxva2.h" "hwcontext_mediacodec.h" "hwcontext_opencl.h" "hwcontext_qsv.h" "hwcontext_vaapi.h" "hwcontext_vdpau.h" "hwcontext_videotoolbox.h" "hwcontext_vulkan.h" "imgutils.h" "intfloat.h" "intreadwrite.h" "lfg.h" "log.h" "lzo.h" "macros.h" "mastering_display_metadata.h" "mathematics.h" "md5.h" "mem.h" "motion_vector.h" "murmur3.h" "opt.h" "parseutils.h" "pixdesc.h" "pixelutils.h" "pixfmt.h" "random_seed.h" "rational.h" "rc4.h" "replaygain.h" "ripemd.h" "samplefmt.h" "sha.h" "sha512.h" "spherical.h" "stereo3d.h" "tea.h" "threadmessage.h" "time.h" "timecode.h" "timestamp.h" "tree.h" "twofish.h" "tx.h" "version.h" "video_enc_params.h" "xtea.h")
35-
36-
export swresampleHeaderNames=("swresample.h" "version.h")
30+
# Library versions
31+
export avcodecVersion=61
32+
export avformatVersion=61
33+
export avutilVersion=59
34+
export swresampleVersion=5
3735

3836
# Aliases for the library files.
3937
export avcodecLib="${avcodecLibName}.${avcodecVersion}.dylib"
4038
export avformatLib="${avformatLibName}.${avformatVersion}.dylib"
4139
export avutilLib="${avutilLibName}.${avutilVersion}.dylib"
4240
export swresampleLib="${swresampleLibName}.${swresampleVersion}.dylib"
4341

42+
# Names of public headers to include in XCFrameworks
43+
export avcodecHeaderNames=("ac3_parser.h" "adts_parser.h" "avcodec.h" "avdct.h" "avfft.h" "bsf.h" "codec.h" "codec_desc.h" "codec_id.h" "codec_par.h" "d3d11va.h" "defs.h" "dirac.h" "dv_profile.h" "dxva2.h" "jni.h" "mediacodec.h" "packet.h" "qsv.h" "vdpau.h" "version.h" "version_major.h" "videotoolbox.h" "vorbis_parser.h")
44+
45+
export avformatHeaderNames=("avformat.h" "avio.h" "version.h" "version_major.h")
46+
47+
export avutilHeaderNames=("adler32.h" "aes.h" "aes_ctr.h" "attributes.h" "audio_fifo.h" "avassert.h" "avconfig.h" "avstring.h" "avutil.h" "base64.h" "blowfish.h" "bprint.h" "bswap.h" "buffer.h" "camellia.h" "cast5.h" "channel_layout.h" "common.h" "cpu.h" "crc.h" "des.h" "dict.h" "display.h" "dovi_meta.h" "downmix_info.h" "encryption_info.h" "error.h" "eval.h" "fifo.h" "file.h" "film_grain_params.h" "frame.h" "hash.h" "hdr_dynamic_metadata.h" "hmac.h" "hwcontext.h" "hwcontext_cuda.h" "hwcontext_d3d11va.h" "hwcontext_drm.h" "hwcontext_dxva2.h" "hwcontext_mediacodec.h" "hwcontext_opencl.h" "hwcontext_qsv.h" "hwcontext_vaapi.h" "hwcontext_vdpau.h" "hwcontext_videotoolbox.h" "hwcontext_vulkan.h" "imgutils.h" "intfloat.h" "intreadwrite.h" "lfg.h" "log.h" "lzo.h" "macros.h" "mastering_display_metadata.h" "mathematics.h" "md5.h" "mem.h" "motion_vector.h" "murmur3.h" "opt.h" "parseutils.h" "pixdesc.h" "pixelutils.h" "pixfmt.h" "random_seed.h" "rational.h" "rc4.h" "replaygain.h" "ripemd.h" "samplefmt.h" "sha.h" "sha512.h" "spherical.h" "stereo3d.h" "tea.h" "threadmessage.h" "time.h" "timecode.h" "timestamp.h" "tree.h" "twofish.h" "tx.h" "version.h" "version_major.h" "video_enc_params.h" "xtea.h")
48+
49+
export swresampleHeaderNames=("swresample.h" "version.h" "version_major.h")
50+
4451
# The name of the FFmpeg source archive file.
45-
export srcArchiveName="ffmpeg-${ffmpegVersion}.tar.bz2"
52+
export srcArchiveName="ffmpeg-${ffmpegVersion}.tar.xz"
4653

4754
# The name of the FFmpeg source directory (once the archive has been uncompressed).
4855
export srcDirName="ffmpeg-${ffmpegVersion}"
4956

50-
# Deployment target for Aural Player.
51-
export minMacOSVersion="10.12"
57+
# MARK: Functions -------------------------------------------------------------------------------------
5258

53-
# Points to the latest MacOS SDK installed.
54-
export sdk="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
59+
function runBuild {
5560

56-
# MARK: Functions -------------------------------------------------------------------------------------
61+
cleanXCFrameworksDir
62+
buildFFmpeg
63+
createFatLibs
64+
copyHeaders
65+
}
5766

5867
function cleanXCFrameworksDir {
5968

@@ -62,8 +71,19 @@ function cleanXCFrameworksDir {
6271
fi
6372
}
6473

74+
function extractSources {
75+
76+
# Extract source code from archive.
77+
if [ ! -d ${srcDirName} ]; then
78+
tar xjf ${srcArchiveName}
79+
fi
80+
}
81+
6582
function buildFFmpeg {
6683

84+
extractSources
85+
86+
# Run all builds in parallel and wait till they all finish.
6787
for arch in ${architectures[@]}; do
6888
buildFFmpegForArch $arch &
6989
done
@@ -74,41 +94,61 @@ function buildFFmpeg {
7494
function buildFFmpegForArch {
7595

7696
arch=$1
97+
7798
echo "\nBuilding FFmpeg for architecture '${arch}' ..."
7899

79-
# Extract source code from archive
80-
srcBaseDir="src-${arch}"
81-
mkdir ${srcBaseDir}
82-
tar xjf ${srcArchiveName} -C ${srcBaseDir}
100+
# Make a copy of the source code.
101+
srcBaseDir="src/${arch}"
102+
mkdir -p ${srcBaseDir}
103+
cp -r $srcDirName/* $srcBaseDir
83104

84-
configureAndMake $arch
105+
configureFFmpeg $arch $srcBaseDir
106+
makeFFmpeg
107+
85108
copyLibs $arch
86109
fixInstallNames $arch
87110
}
88111

89-
function configureAndMake {
112+
# Determine compiler / linker flags based on architecture.
113+
function setCompilerAndLinkerFlags {
90114

91115
arch=$1
92116

93-
# CD to the source directory.
94-
cd "src-${arch}/${srcDirName}"
117+
export compiler="/usr/bin/clang"
118+
119+
# Architecture of the host machine running this build.
120+
hostArchitecture=$(uname -m)
95121

96-
# Determine compiler / linker flags based on architecture.
97-
if [[ "$arch" == "arm64" ]]
122+
if [[ "$arch" != "$hostArchitecture" ]]
98123
then
99-
archInFlags="-arch arm64 "
100-
crossCompileAndArch="--enable-cross-compile --arch=arm64"
101-
else
102-
archInFlags=""
103-
crossCompileAndArch=""
124+
archInFlags="-arch ${arch} "
125+
export crossCompileOption="--enable-cross-compile"
126+
export archOption="--arch=${arch}"
104127
fi
105128

129+
export extraCompilerFlags="${archInFlags}-mmacosx-version-min=${deploymentTarget} -isysroot ${sdk}"
130+
export extraLinkerFlags=${extraCompilerFlags}
131+
}
132+
133+
function configureFFmpeg {
134+
135+
arch=$1
136+
srcDir=$2
137+
138+
# CD to the source directory.
139+
cd ${srcDir}
140+
141+
setCompilerAndLinkerFlags $arch
142+
106143
# Configure FFmpeg
107144
./configure \
108-
--cc=/usr/bin/clang \
109-
--extra-ldflags="${archInFlags}-mmacosx-version-min=${minMacOSVersion} -isysroot ${sdk}" \
110-
--extra-cflags="${archInFlags}-mmacosx-version-min=${minMacOSVersion} -isysroot ${sdk}" \
111-
${crossCompileAndArch} \
145+
--target-os=darwin \
146+
${archOption} \
147+
--cc="${compiler}" \
148+
--as="${assembler}" \
149+
--extra-cflags="${extraCompilerFlags}" \
150+
--extra-ldflags="${extraLinkerFlags}" \
151+
${crossCompileOption} \
112152
--enable-gpl \
113153
--enable-version3 \
114154
--enable-shared \
@@ -118,14 +158,15 @@ function configureAndMake {
118158
--enable-pthreads \
119159
--disable-doc \
120160
--disable-debug \
161+
--disable-network \
121162
--disable-all \
122163
--enable-avcodec \
123164
--enable-avformat \
124165
--enable-swresample \
125-
--enable-avfoundation \
126-
--enable-audiotoolbox \
127-
--enable-coreimage \
128-
--enable-zlib \
166+
--disable-avfoundation \
167+
--disable-audiotoolbox \
168+
--disable-coreimage \
169+
--disable-zlib \
129170
--disable-everything \
130171
--disable-appkit \
131172
--disable-iconv \
@@ -137,7 +178,10 @@ function configureAndMake {
137178
--enable-parsers \
138179
--enable-decoders \
139180
--enable-protocol=file
140-
181+
}
182+
183+
function makeFFmpeg {
184+
141185
# Build FFmpeg (use multithreading).
142186
tokens=$(sysctl hw.physicalcpu)
143187
numCores="$(cut -d' ' -f2 <<<$tokens)"
@@ -151,10 +195,11 @@ function copyLibs {
151195
arch=$1
152196

153197
# Create the directory where the libs will be installed in.
154-
mkdir -p "dylibs/${arch}"
155-
cd "dylibs/${arch}"
198+
libsDir="dylibs/${arch}"
199+
mkdir -p $libsDir
200+
cd $libsDir
156201

157-
srcDir="../../src-${arch}/${srcDirName}"
202+
srcDir="../../src/${arch}"
158203

159204
cp ${srcDir}/${avcodecLibName}/${avcodecLib} .
160205
cp ${srcDir}/${avformatLibName}/${avformatLib} .
@@ -184,45 +229,63 @@ function fixInstallNames {
184229
install_name_tool -id @rpath/${swresampleLib} ${swresampleLib}
185230
install_name_tool -change /usr/local/lib/${avutilLib} @rpath/${avutilLib} ${swresampleLib}
186231

187-
cd ../..
232+
cd ../../..
188233
}
189234

190235
function createFatLibs {
191236

192237
# Combine x86_64 and arm64 dylibs into "fat" universal dylibs.
193-
194-
cd dylibs/x86_64
195-
for file in *; do
196-
lipo "${file}" "../arm64/${file}" -output "../${file}" -create
238+
cd dylibs
239+
240+
allDylibs=($avcodecLib $avformatLib $avutilLib $swresampleLib)
241+
242+
for lib in ${allDylibs[@]}; do
243+
244+
nonFatLibFiles=""
245+
246+
for arch in ${architectures[@]}; do
247+
nonFatLibFiles="${nonFatLibFiles} ${arch}/${lib}"
248+
done
249+
250+
lipo ${nonFatLibFiles} -output ${lib} -create
251+
197252
done
198253

199-
cd ../..
254+
cd ..
200255
}
201256

202257
function copyHeaders {
203258

204259
mkdir "headers"
205260

206-
copyHeadersForLib $avcodecLibName "${avcodecHeaderNames[@]}"
207-
copyHeadersForLib $avformatLibName "${avformatHeaderNames[@]}"
208-
copyHeadersForLib $avutilLibName "${avutilHeaderNames[@]}"
209-
copyHeadersForLib $swresampleLibName "${swresampleHeaderNames[@]}"
261+
srcBaseDir="src/arm64"
262+
headersBaseDir="headers"
263+
264+
copyHeadersForLib $srcBaseDir $avcodecLibName $headersBaseDir "${avcodecHeaderNames[@]}"
265+
copyHeadersForLib $srcBaseDir $avformatLibName $headersBaseDir "${avformatHeaderNames[@]}"
266+
copyHeadersForLib $srcBaseDir $avutilLibName $headersBaseDir "${avutilHeaderNames[@]}"
267+
copyHeadersForLib $srcBaseDir $swresampleLibName $headersBaseDir "${swresampleHeaderNames[@]}"
210268
}
211269

212270
function copyHeadersForLib {
213271

214-
libName=$1
272+
srcBaseDir=$1
273+
libName=$2
274+
headersBaseDir=$3
275+
shift
276+
shift
215277
shift
216278
headerNames=("$@")
217-
srcDir="src-arm64/${srcDirName}/${libName}"
279+
srcDir="${srcBaseDir}/${libName}"
218280

219281
# Add a 2nd level folder with the same library name (otherwise headers are not resolved properly in the XCode project).
220282
# For example: "/libavcodec/libavcodec/someHeader.h"
221283

222-
mkdir -p "headers/${libName}/${libName}"
284+
headersDestDir="${headersBaseDir}/${libName}/${libName}"
285+
mkdir -p $headersDestDir
223286

224287
for file in ${headerNames[@]}; do
225-
cp "${srcDir}/${file}" "./headers/${libName}/${libName}"
288+
cp "${srcDir}/${file}" "${headersDestDir}"
226289
done
227290
}
228291

@@ -246,33 +309,16 @@ function createXCFrameworkForLib {
246309
-output "xcframeworks/${libName}.xcframework"
247310
}
248311

249-
function deleteSource {
250-
251-
for arch in ${architectures[@]}; do
252-
rm -rf "src-${arch}"
253-
done
254-
}
312+
function cleanUp {
255313

256-
function deleteDylibs {
314+
rm -rf ${srcDirName}
315+
rm -rf src
257316
rm -rf dylibs
258-
}
259-
260-
function deleteHeaders {
261317
rm -rf headers
262318
}
263319

264-
# MARK: Script -------------------------------------------------------------------------------------
265-
266-
cleanXCFrameworksDir
267-
buildFFmpeg
268-
269-
createFatLibs
270-
copyHeaders
271-
320+
runBuild
272321
createXCFrameworks
273-
274-
deleteSource
275-
deleteDylibs
276-
deleteHeaders
322+
cleanUp
277323

278324
echo "\nAll done !\n"

Resources/ffmpeg/ffmpeg

-243 KB
Binary file not shown.

Resources/ffmpeg/ffprobe

-153 KB
Binary file not shown.

0 commit comments

Comments
 (0)