-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
112 lines (100 loc) · 5.99 KB
/
Copy pathDockerfile
File metadata and controls
112 lines (100 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# escape=`
#
# Builds FFmpeg on Windows as SHARED libraries (avcodec-61.dll, avformat-61.dll,
# ...) with the MSVC toolchain and packages the headers + import libraries + DLLs
# into zip files that FreeSWITCH's mod_av can download and link, instead of
# compiling the whole of FFmpeg inside the Visual Studio solution.
#
# The compiler is MSVC (cl.exe) throughout. FFmpeg (and x264) have no native
# MSBuild/CMake project -- their only build system is configure+make -- so MSYS2
# bash is installed purely as the POSIX *script driver*. This is exactly how
# vcpkg builds ffmpeg on Windows. Nothing POSIX ends up in the produced
# DLLs/import libs. (openh264 isn't compiled here at all: its import lib +
# headers are derived from Cisco's prebuilt DLL.)
#
# This image only contains the TOOLCHAIN (+ prebuilt openh264/x264 dev libs).
# The actual FFmpeg version is built at `docker run` time from an env var, so a
# new release can be produced without rebuilding the (slow, multi-GB) toolchain.
#
# Build the toolchain image once:
# docker build -t ffmpeg-packaging .
#
# Produce the openh264 (non-GPL) zips for FFmpeg 7.1.5 (writes to .\artifacts):
# docker run --rm --cpus 8 --memory 16g `
# -e FFMPEG_VERSION=7.1.5 -e VARIANT=openh264 `
# -v ${PWD}\artifacts:C:\artifacts `
# ffmpeg-packaging
#
# Build from a local source tree instead of downloading:
# ... -e FFMPEG_SRC=C:\ffmpeg-src -v ${PWD}\ffmpeg-7.1.5:C:\ffmpeg-src ...
#
# Requires Windows containers. With Docker Desktop's default hyperv isolation
# any base image build works; otherwise the host must be equal-or-newer than the
# base image for process isolation.
ARG WINDOWS_BASE=mcr.microsoft.com/windows/servercore:ltsc2025
FROM ${WINDOWS_BASE}
ARG VS_BOOTSTRAPPER_URL=https://aka.ms/vs/17/release/vs_buildtools.exe
SHELL ["powershell", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue';"]
# ---------------------------------------------------------------------------
# 1. Chocolatey + non-VS prerequisites:
# - git : clone openh264/x264 (and optionally ffmpeg) sources
# - nasm : x86 assembler for ffmpeg/openh264/x264 (on PATH for cl)
# - msys2 : the POSIX shell that drives configure/make (NOT a compiler)
# - 7zip : decompress Cisco's prebuilt openh264 .dll.bz2
# ---------------------------------------------------------------------------
RUN [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; `
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
RUN choco install -y --no-progress git nasm 7zip msys2; `
if ($LASTEXITCODE -ne 0) { throw "choco install failed ($LASTEXITCODE)" }
# ---------------------------------------------------------------------------
# 2. Visual Studio 2022 Build Tools: C++ workload (MSVC v143 + Windows SDK).
# Exit code 3010 == success-but-reboot-required, fine in an image.
# ---------------------------------------------------------------------------
RUN Invoke-WebRequest -Uri $env:VS_BOOTSTRAPPER_URL -OutFile C:\vs_buildtools.exe; `
Write-Host 'Installing Visual Studio Build Tools (this takes a while)...'; `
$p = Start-Process -FilePath C:\vs_buildtools.exe -Wait -PassThru -ArgumentList `
'--quiet','--wait','--norestart','--nocache', `
'--installPath','C:\BuildTools', `
'--add','Microsoft.VisualStudio.Workload.VCTools', `
'--includeRecommended'; `
if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) { throw "VS Build Tools install failed ($($p.ExitCode))" }; `
Remove-Item C:\vs_buildtools.exe -Force
# ---------------------------------------------------------------------------
# 3. MSYS2 packages needed to *drive* the builds: make + automake (ar-lib) +
# pkgconf (for --enable-libopenh264 detection) + diffutils + tar/xz.
# These are POSIX build tooling, not compilers.
# ---------------------------------------------------------------------------
RUN $bash = 'C:\tools\msys64\usr\bin\bash.exe'; `
& $bash -lc 'pacman -Sy --noconfirm'; `
& $bash -lc 'pacman -S --noconfirm --needed make automake diffutils pkgconf tar xz'; `
if ($LASTEXITCODE -ne 0) { throw "pacman package install failed ($LASTEXITCODE)" }
# ---------------------------------------------------------------------------
# 4. Codec dev libs into C:\deps: openh264 (import lib + wels headers derived
# from Cisco's prebuilt DLL) and x264 (built from source as a shared DLL).
# avcodec imports both at runtime. openh264 is required (non-GPL variant);
# x264 is best-effort (GPL variant).
# ---------------------------------------------------------------------------
# OPENH264_VERSION must match the openh264.dll FreeSWITCH downloads at runtime
# (stack w32\download_openh264.props + Setup.CA.DownloadOpenH264 == 1.8.0), since
# ffmpeg's libopenh264 wrapper is version-gated against the wels headers.
ENV DEPS_PREFIX=C:\deps `
MSYS2_ROOT=C:\tools\msys64 `
OPENH264_VERSION=1.8.0 `
X264_BRANCH=stable
COPY build-deps.ps1 C:\build-deps.ps1
RUN C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass `
-File C:\build-deps.ps1 -Deps 'openh264 x264'
# ---------------------------------------------------------------------------
# 5. Build driver + runtime defaults. Override any with `docker run -e ...`.
# ---------------------------------------------------------------------------
COPY build-ffmpeg.ps1 C:\build-ffmpeg.ps1
# Cisco openh264 binary-license notice, bundled into the openh264 zip by
# build-ffmpeg.ps1 (it looks for this next to the script, i.e. C:\ in the image).
COPY OPENH264_BINARY_LICENSE.txt C:\OPENH264_BINARY_LICENSE.txt
ENV FFMPEG_VERSION=7.1.5 `
CONFIGS="Release Debug" `
ARCH=x64 `
VARIANT=openh264 `
PKG_PREFIX=ffmpeg `
OUT_DIR=C:\artifacts
ENTRYPOINT ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "C:\\build-ffmpeg.ps1"]