build.lua 6196 bytes · raw
-- FFmpeg's own configure (not autoconf: no --host, its own --toolchain, --arch, --target-os) and make, out of the tree
-- in slice.build, with MSVC (--toolchain=msvc: cl.exe, lib.exe, link.exe through FFmpeg's mslink) under the MSYS2 of
-- the make recipe, whose sh runs configure. 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" }
-- A path as the programs of MSYS2 name it: C:/x is /c/x.
local function msys(path)
return (path:gsub("^(%a):/", function(drive) return "/" .. drive:lower() .. "/" end))
end
-- MSVC's options with '-': MSYS2 takes /O2 for a path and turns it into C:/…/O2 for native programs
local function joined(flags)
local all = {}
for _, f in ipairs(flags) do all[#all + 1] = (f:gsub("^/", "-")) 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
-- PATH with MSYS2's programs after the toolchain's (Visual Studio's link.exe, not coreutils' link) and before Windows'
-- own (whose bash.exe is WSL's)
local function msys_path_variable(slice, msys_bin)
local path = slice.toolchain.env.PATH or slice.toolchain.env.Path or ""
local root = (slice.toolchain.env.SystemRoot or slice.toolchain.env.SYSTEMROOT or "C:\\Windows"):lower():gsub("\\", "/")
local dirs, at = {}, nil
for dir in path:gmatch("[^;]+") do
local lower = dir:lower():gsub("\\", "/")
if not at and (lower == root or lower:sub(1, #root + 1) == root .. "/") then
at = #dirs + 1
dirs[at] = msys_bin
end
dirs[#dirs + 1] = dir
end
if not at then dirs[#dirs + 1] = msys_bin end
return table.concat(dirs, ";")
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"))
local make = slice.toolchains.make
local msys_bin = make:match("^(.*)/[^/]*$")
-- the dependencies under the names FFmpeg's flags for MSVC give them: -lz is zlib.lib, -ldav1d dav1d.lib (meson
-- names a static dav1d libdav1d.a)
local libs = slice.build .. "/otok-deps"
local include = {}
for name, d in pairs(deps) do
if name ~= "tools" then include[#include + 1] = "-I" .. d.include end
end
otok.copy(deps.zlib.libraries.z, libs .. "/zlib.lib")
if options.dav1d then otok.copy(deps.dav1d.libraries.dav1d, libs .. "/dav1d.lib") end
local args = {
(make:gsub("make%.exe$", "sh.exe")), msys(slice.source) .. "/configure",
"--prefix=" .. msys(slice.prefix),
"--libdir=" .. msys(slice.prefix) .. "/lib",
"--incdir=" .. msys(slice.prefix) .. "/include",
dynamic and "--enable-shared" or "--disable-shared",
dynamic and "--disable-static" or "--enable-static",
"--toolchain=msvc", "--target-os=win64", "--arch=x86_64",
"--disable-programs", "--disable-doc", "--disable-avdevice", "--disable-stripping",
"--disable-autodetect", "--enable-w32threads", "--enable-zlib",
"--enable-d3d11va", "--enable-d3d12va", "--enable-dxva2",
-- otok's flags choose the configuration: FFmpeg's -O2 follows them in release, none in debug
debug and "--disable-optimizations" or "--enable-optimizations",
debug and "--enable-debug" or "--disable-debug",
"--pkg-config=" .. msys(slice.toolchains["pkg-config"]),
"--x86asmexe=" .. msys(slice.toolchains.nasm),
"--extra-cflags=" .. joined(t.cflags) .. " " .. table.concat(include, " "),
"--extra-cxxflags=" .. joined(t.cxxflags) .. " " .. table.concat(include, " "),
-- link.exe's options, which configure passes on as they are
"--extra-ldflags=" .. joined(t.ldflags) .. " -libpath:" .. libs,
}
if slice.c_standard then args[#args + 1] = "--stdc=c" .. slice.c_standard end
if options.dav1d then args[#args + 1] = "--enable-libdav1d" end
-- dav1d's pkg-config file, of the dependency's prefix, for pkgconf, a Windows program
local pc = {}
for name, d in pairs(deps) do
if name ~= "tools" then pc[#pc + 1] = d.prefix .. "/lib/pkgconfig" end
end
local env = {
PATH = msys_path_variable(slice, msys_bin), Path = false,
PKG_CONFIG_PATH = table.concat(pc, ";"),
CC = false, CXX = false, CFLAGS = false, CXXFLAGS = false, CPPFLAGS = false, LDFLAGS = false,
}
otok.run(args, { cwd = slice.build, env = env })
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, env = env }
-- lib/avcodec.lib, static, or bin/avcodec.lib, the import library of bin/avcodec-63.dll beside it
local p = slice.prefix
local result = {}
for _, name in ipairs(libraries) do
local lib = otok.glob((dynamic and "bin/" or "lib/") .. name .. ".lib", p)[1]
assert(lib, "FFmpeg installed no " .. name .. ".lib")
if dynamic then
local dll = otok.glob("bin/" .. name .. "-*.dll", p)[1]
assert(dll, "FFmpeg installed no " .. name .. "-*.dll")
result[name] = { link = lib, runtime = dll }
else
result[name] = lib
end
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 2462 bytes · raw
# The otok recipe of FFmpeg (https://github.com/apotocki/otok): libavutil, libavcodec, libavformat, libavfilter,
# libswscale and libswresample for Windows on x86_64, LGPL only (no GPL or nonfree parts), with FFmpeg's own configure
# and make under MSYS2 (the tree of the make recipe) and MSVC; D3D11VA, D3D12VA and DXVA2,
# zlib and dav1d from their recipes; 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
patches = ["patches/0001-swscale-framepool-names.patch"]
[platforms]
supported = ["windows"]
# arm64 needs FFmpeg's gas-preprocessor before armasm64, not yet
architectures = { windows = ["x86_64"] }
build-on = ["windows/msvc"]
[options.dav1d]
type = "bool"
default = true
doc = "AV1 decoding with dav1d (the decoder libdav1d), much faster than FFmpeg's own AV1 decoder."
[deps.zlib]
version = ">= 1.2"
default-recipe = "apotocki/zlib"
[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 = ["bcrypt", "ole32", "user32", "ws2_32"] }