build.lua 5914 bytes · raw
-- FFmpeg's own configure (not autoconf: no --host, its own --cc, --arch, --target-os) and make, out of the tree in
-- slice.build, cross-compiling every slice. Nothing is detected on the machine: --disable-autodetect turns off every
-- library configure would find, the threads too, and what the recipe wants is enabled by name.
local libraries = { "avutil", "avcodec", "avformat", "avfilter", "swscale", "swresample" }
-- the installed headers of the acceleration of other platforms
local foreign_headers = {
"libavcodec/d3d11va.h", "libavcodec/dxva2.h", "libavcodec/jni.h", "libavcodec/mediacodec.h", "libavcodec/qsv.h",
"libavcodec/vdpau.h",
"libavutil/hwcontext_amf.h", "libavutil/hwcontext_cuda.h", "libavutil/hwcontext_d3d11va.h",
"libavutil/hwcontext_d3d12va.h", "libavutil/hwcontext_drm.h", "libavutil/hwcontext_dxva2.h",
"libavutil/hwcontext_mediacodec.h", "libavutil/hwcontext_oh.h", "libavutil/hwcontext_opencl.h",
"libavutil/hwcontext_qsv.h", "libavutil/hwcontext_vaapi.h", "libavutil/hwcontext_vdpau.h",
"libavutil/hwcontext_vulkan.h",
}
-- FFmpeg's names of the architectures
local arch = { arm64 = "aarch64", arm64e = "aarch64", x86_64 = "x86_64" }
-- the flags as one argument of configure
local function joined(flags, extra)
local all = {}
for _, f in ipairs(flags) do all[#all + 1] = f end
for _, f in ipairs(extra or {}) do all[#all + 1] = f end
return table.concat(all, " ")
end
-- What av*_configuration() tell: the arguments of configure without the paths of this build, which would make the
-- libraries differ from one build to the next and carry the machine's directories
local function configuration(args)
local shown = {}
for i = 3, #args do
if not args[i]:find("[/\\]") then shown[#shown + 1] = args[i] end
end
return table.concat(shown, " ")
end
function build(slice, options, deps)
local t = slice.toolchain
local dynamic = slice.linkage == "dynamic"
local debug = slice.configuration == "debug"
-- VERSION, as the release archive has it (without it, and without .git, version.sh takes RELEASE)
otok.write(slice.source .. "/VERSION", otok.read(slice.source .. "/RELEASE"))
-- the macOS SDK of the Xcode of the slice's SDK
local macos_sdk = slice.apple.sdk_path:gsub("/Platforms/[^/]+%.platform/Developer/SDKs/[^/]+$",
"/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
local args = {
"sh", slice.source .. "/configure",
"--prefix=" .. slice.prefix,
"--libdir=" .. slice.prefix .. "/lib",
"--incdir=" .. slice.prefix .. "/include",
dynamic and "--enable-shared" or "--disable-shared",
dynamic and "--disable-static" or "--enable-static",
-- the dynamic libraries as the consumer's executable finds them
"--install-name-dir=@rpath",
"--enable-cross-compile", "--target-os=darwin", "--arch=" .. assert(arch[slice.arch], slice.arch),
"--sysroot=" .. slice.apple.sdk_path,
"--disable-programs", "--disable-doc", "--disable-avdevice", "--disable-stripping",
"--disable-autodetect", "--enable-pthreads", "--enable-zlib",
"--enable-videotoolbox", "--enable-audiotoolbox",
-- otok's flags choose the configuration: FFmpeg's -O3 follows them in release, none in debug
debug and "--disable-optimizations" or "--enable-optimizations",
debug and "--enable-debug" or "--disable-debug",
"--cc=" .. t.cc, "--cxx=" .. t.cxx, "--objcc=" .. t.cc, "--dep-cc=" .. t.cc,
"--ar=" .. t.ar, "--ranlib=" .. t.ranlib, "--nm=" .. t.nm, "--strip=" .. t.strip,
"--pkg-config=" .. slice.toolchains["pkg-config"],
"--extra-cflags=" .. joined(t.cflags),
"--extra-objcflags=" .. joined(t.cflags),
"--extra-cxxflags=" .. joined(t.cxxflags),
"--extra-ldflags=" .. joined(t.ldflags),
-- the programs the build runs (libswscale's ops_asmgen) are the Mac's: Xcode's clang with the macOS SDK, whose
-- version flag wins over the deployment variables of the slice's environment
"--host-cc=" .. t.cc,
"--host-cflags=-isysroot " .. macos_sdk .. " -mmacosx-version-min=11.0",
"--host-ldflags=-isysroot " .. macos_sdk .. " -mmacosx-version-min=11.0",
}
if slice.c_standard then args[#args + 1] = "--stdc=c" .. slice.c_standard end
if slice.toolchains.nasm then args[#args + 1] = "--x86asmexe=" .. slice.toolchains.nasm end
if options.dav1d then args[#args + 1] = "--enable-libdav1d" end
-- dav1d's pkg-config file, of the dependency's prefix
local pc = {}
for name, d in pairs(deps) do
if name ~= "tools" then pc[#pc + 1] = d.prefix .. "/lib/pkgconfig" end
end
otok.run(args, { cwd = slice.build, env = {
PKG_CONFIG_PATH = table.concat(pc, ":"),
CFLAGS = false, CXXFLAGS = false, CPPFLAGS = false, LDFLAGS = false,
} })
local config = slice.build .. "/config.h"
local text, n = otok.read(config):gsub('#define FFMPEG_CONFIGURATION "[^\n]*"',
function() return '#define FFMPEG_CONFIGURATION "' .. configuration(args) .. '"' end)
assert(n == 1, "config.h has no FFMPEG_CONFIGURATION")
otok.write(config, text)
otok.make{ "install", cwd = slice.build }
local p = slice.prefix
-- FFmpeg installs the headers of every platform's acceleration; those of others than Apple's include what the
-- SDKs do not have (d3d11.h, va/va.h), and the Clang module of the product takes every header
for _, header in ipairs(foreign_headers) do otok.remove(p .. "/include/" .. header) end
local result = {}
for _, name in ipairs(libraries) do
local file = otok.glob("lib/lib" .. name .. (dynamic and ".dylib" or ".a"), p)[1]
assert(file, "FFmpeg installed no lib" .. name)
result[name] = file
end
return { libraries = result, headers = p .. "/include" }
end
patches/0001-swscale-framepool-names.patch 2191 bytes · raw
diff --git a/libswscale/framepool.c b/libswscale/framepool.c
index 2d6bcb1..1dd0483 100644
--- a/libswscale/framepool.c
+++ b/libswscale/framepool.c
@@ -16,4 +16,5 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "framepool_names.h"
#include "libavfilter/framepool.c"
diff --git a/libswscale/framepool_names.h b/libswscale/framepool_names.h
new file mode 100644
index 0000000..bae43dc
--- /dev/null
+++ b/libswscale/framepool_names.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * libswscale's copy of libavfilter's frame pool under names of its own, so that
+ * the static libraries libswscale and libavfilter define no symbol twice.
+ */
+
+#ifndef SWSCALE_FRAMEPOOL_NAMES_H
+#define SWSCALE_FRAMEPOOL_NAMES_H
+
+#define ff_frame_pool_video_reinit sws_ff_frame_pool_video_reinit
+#define ff_frame_pool_audio_reinit sws_ff_frame_pool_audio_reinit
+#define ff_frame_pool_get sws_ff_frame_pool_get
+#define ff_frame_pool_uninit sws_ff_frame_pool_uninit
+
+#endif /* SWSCALE_FRAMEPOOL_NAMES_H */
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index 9a822cb..de3a033 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -28,6 +28,7 @@
#include "swscale.h"
#include "graph.h"
+#include "framepool_names.h"
#include "libavfilter/framepool.h"
#include "libavutil/avassert.h"
#include "libavutil/common.h"
recipe.toml 2746 bytes · raw
# The otok recipe of FFmpeg (https://github.com/apotocki/otok): libavutil, libavcodec, libavformat, libavfilter,
# libswscale and libswresample for the Apple platforms but watchOS, LGPL only (no GPL or nonfree parts), with FFmpeg's
# own configure and make; VideoToolbox and AudioToolbox, the SDK's zlib, dav1d from its recipe; static or dynamic.
[recipe]
api = 1
library = "ffmpeg"
name = "ffmpeg"
version = "9.0.2"
revision = 1
license = "LGPL-2.1-or-later"
license-files = ["COPYING.LGPLv2.1", "LICENSE.md"]
homepage = "https://ffmpeg.org"
documentation = "https://ffmpeg.org/documentation.html"
description = "FFmpeg's libraries (avutil, avcodec, avformat, avfilter, swscale, swresample) under the LGPL."
keywords = ["video", "audio", "codec", "multimedia", "ffmpeg"]
linkage = ["static", "dynamic"]
c-standard = ">= 11"
# The tag of the release in FFmpeg's mirror on GitHub (ffmpeg.org often fails to answer): its tree is that of the
# release archive ffmpeg-9.0.2.tar.xz, signed by FFmpeg's release key FCF9 86EA 15E6 E293 A564 4F10 B432 2F04 D676 58D8,
# without the file VERSION, which build.lua writes from RELEASE as the archive has it.
[source]
git = "https://github.com/FFmpeg/FFmpeg"
commit = "946fcce07b6dcd0331c8cc609192aeff5e1924f8"
tag = "n9.0.2"
# libswscale compiles libavfilter's frame pool too: under names of its own, so that the static libraries do not both
# define them; VideoToolbox's buffers without the OpenGL ES key in Mac Catalyst and visionOS, which do not have it
patches = ["patches/0001-swscale-framepool-names.patch", "patches/0002-videotoolbox-opengl-keys.patch"]
# watchOS has no VideoToolbox, which the product links
[platforms]
supported = ["ios", "iossim", "macosx", "catalyst", "tvos", "tvossim", "xros", "xrossim"]
build-on = ["macos/xcode"]
[options.dav1d]
type = "bool"
default = true
doc = "AV1 decoding with dav1d (the decoder libdav1d), much faster than FFmpeg's own AV1 decoder."
[deps.dav1d]
version = ">= 1.0"
default-recipe = "apotocki/dav1d"
when = { option = "dav1d" }
[toolchains]
make = { version = ">= 3.81", default-recipe = "apotocki/make" }
pkg-config = { version = ">= 1", default-recipe = "apotocki/pkgconf" } # configure finds dav1d through it
nasm = { version = ">= 2.13", default-recipe = "apotocki/nasm", when = { arch = ["x86_64"] } } # the assembly of x86_64
[[product]]
name = "FFmpeg"
libraries = ["avfilter", "avformat", "avcodec", "swscale", "swresample", "avutil"]
headers = "avutil"
link = { libraries = ["z"] }
# stat and fstat of libavformat and libavutil: the file timestamp APIs
apple = { module = "CFFmpeg", frameworks = ["VideoToolbox", "AudioToolbox", "CoreMedia", "CoreVideo", "CoreFoundation", "CoreServices"], privacy-manifest = "PrivacyInfo.xcprivacy" }