Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use custom ffmpeg build on MS Windows #3166

Closed
totaam opened this issue Jun 13, 2021 · 5 comments
Closed

use custom ffmpeg build on MS Windows #3166

totaam opened this issue Jun 13, 2021 · 5 comments

Comments

@totaam
Copy link
Collaborator

totaam commented Jun 13, 2021

The default one from MSYS2 brings in too many libraries.
The latest dependencies add dozens of megabytes to the installer for things we will never use.

Maybe keep this as a patch to the PKGBUILD file so we can more easily rebuild when there are updates?
Some gstreamer packages may depend on some of those libraries but since we don't ship those codecs, I think we're OK.

(consider doing the same thing for opencv?)

@totaam
Copy link
Collaborator Author

totaam commented Jun 30, 2021

The modified PKGBUILD makes a massive difference:

Packages (1) mingw-w64-x86_64-ffmpeg-4.4-7

Total Installed Size:   17.68 MiB
Net Upgrade Size:      -34.61 MiB

With this one change alone, when comparing with the 4.2 release:

  • the full EXE installer has shrunk from 123MB down to 109MB
  • the "client" EXE installer shrinks from 71MB down to 60MB.

Here's the diff:

diff --git a/mingw-w64-ffmpeg/PKGBUILD b/mingw-w64-ffmpeg/PKGBUILD
index 9b70dfb22..da758b794 100644
--- a/mingw-w64-ffmpeg/PKGBUILD
+++ b/mingw-w64-ffmpeg/PKGBUILD
@@ -7,56 +7,21 @@ _realname=ffmpeg
 pkgbase="mingw-w64-${_realname}"
 pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
 pkgver=4.4
-pkgrel=6
+pkgrel=7
 pkgdesc="Complete and free Internet live audio and video broadcasting solution (mingw-w64)"
 arch=('any')
 mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
 url="https://ffmpeg.org/"
 license=('GPL')
 options=('staticlibs' 'strip')
-depends=("${MINGW_PACKAGE_PREFIX}-aom"
-         "${MINGW_PACKAGE_PREFIX}-bzip2"
-         "${MINGW_PACKAGE_PREFIX}-celt"
-         "${MINGW_PACKAGE_PREFIX}-frei0r-plugins"
-         "${MINGW_PACKAGE_PREFIX}-fontconfig"
-         "${MINGW_PACKAGE_PREFIX}-dav1d"
-         "${MINGW_PACKAGE_PREFIX}-gnutls"
-         "${MINGW_PACKAGE_PREFIX}-gsm"
-         "${MINGW_PACKAGE_PREFIX}-lame"
-         "${MINGW_PACKAGE_PREFIX}-libass"
-         "${MINGW_PACKAGE_PREFIX}-libbluray"
-         "${MINGW_PACKAGE_PREFIX}-libcaca"
-         "${MINGW_PACKAGE_PREFIX}-libexif"
-         "${MINGW_PACKAGE_PREFIX}-libmfx"
-         "${MINGW_PACKAGE_PREFIX}-libmodplug"
-         "${MINGW_PACKAGE_PREFIX}-libsoxr"
-         "${MINGW_PACKAGE_PREFIX}-libtheora"
-         "${MINGW_PACKAGE_PREFIX}-libvorbis"
-         "${MINGW_PACKAGE_PREFIX}-libvpx"
-         "${MINGW_PACKAGE_PREFIX}-libwebp"
-         "${MINGW_PACKAGE_PREFIX}-libxml2"
-         "${MINGW_PACKAGE_PREFIX}-openal"
-         "${MINGW_PACKAGE_PREFIX}-opencore-amr"
-         "${MINGW_PACKAGE_PREFIX}-openjpeg2"
-         "${MINGW_PACKAGE_PREFIX}-opus"
-         "${MINGW_PACKAGE_PREFIX}-rtmpdump"
-         "${MINGW_PACKAGE_PREFIX}-SDL2"
-         "${MINGW_PACKAGE_PREFIX}-speex"
-         "${MINGW_PACKAGE_PREFIX}-srt"
-         "${MINGW_PACKAGE_PREFIX}-vulkan"
-         "${MINGW_PACKAGE_PREFIX}-x264"
-         "${MINGW_PACKAGE_PREFIX}-x265"
-         "${MINGW_PACKAGE_PREFIX}-xvidcore"
-         "${MINGW_PACKAGE_PREFIX}-zlib")
-makedepends=("${MINGW_PACKAGE_PREFIX}-dlfcn"
-             "${MINGW_PACKAGE_PREFIX}-gcc"
+depends=("${MINGW_PACKAGE_PREFIX}-libvpx"
+	 "${MINGW_PACKAGE_PREFIX}-x264")
+makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
              "${MINGW_PACKAGE_PREFIX}-pkg-config"
-             "${MINGW_PACKAGE_PREFIX}-amf-headers"
              "${MINGW_PACKAGE_PREFIX}-ffnvcodec-headers"
              "${MINGW_PACKAGE_PREFIX}-nasm")
 source=(https://ffmpeg.org/releases/${_realname}-${pkgver}.tar.xz{,.asc}
         "0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch")
-validpgpkeys=('FCF986EA15E6E293A5644F10B4322F04D67658D8')
 sha256sums=('06b10a183ce5371f915c6bb15b7b1fffbe046e8275099c96affc29e17645d909'
             'SKIP'
             'b32cad81226d8a72d99fc9cb509acb6a0533378bd351da65391945d7e0e81746')
@@ -64,8 +29,6 @@ sha256sums=('06b10a183ce5371f915c6bb15b7b1fffbe046e8275099c96affc29e17645d909'
 prepare() {
   cd "${srcdir}/${_realname}-${pkgver}"
   rm -f libavfilter/pathtools.{c,h} || true
-
-  patch -p1 -i "${srcdir}/0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch"
 }
 
 build() {
@@ -76,49 +39,40 @@ build() {
   local common_config
   common_config=(
     --disable-debug
-    --enable-amf
+    --disable-everything
     --enable-dxva2
     --enable-d3d11va
-    --enable-fontconfig
-    --enable-frei0r
-    --enable-gnutls
     --enable-gpl
-    --enable-libaom
-    --enable-libass
-    --enable-libbluray
-    --enable-libcaca
-    --enable-libcelt
-    --enable-libdav1d
-    --enable-libfreetype
-    --enable-libgsm
-    --enable-libmfx
-    --enable-libmodplug
-    --enable-libmp3lame
-    --enable-libopencore_amrnb
-    --enable-libopencore_amrwb
-    --enable-libopenjpeg
-    --enable-libopus
-    --enable-librtmp
-    --enable-libsoxr
-    --enable-libspeex
-    --enable-libsrt
-    --enable-libtheora
-    --enable-libvorbis
     --enable-libx264
     --enable-libx265
-    --enable-libxvid
     --enable-libvpx
-    --enable-libwebp
-    --enable-libxml2
-    --enable-nvenc
-    --enable-openal
     --enable-pic
-    --enable-postproc
     --enable-runtime-cpudetect
-    --enable-swresample
-    --enable-version3
-    --enable-vulkan
-    --enable-zlib
+    --enable-swscale
+    --enable-decoder=h264
+    --enable-decoder=mpeg4
+    --enable-decoder=vp8
+    --enable-decoder=vp9
+    --enable-decoder=hevc
+    --enable-encoder=libvpx_vp8
+    --enable-encoder=libvpx_vp9
+    --enable-encoder=mpeg4
+    --enable-muxer=mp4
+    --enable-muxer=webm
+    --enable-muxer=matroska
+    --enable-muxer=ogg
+    --disable-protocol=tcp
+    --disable-protocol=rtp
+    --disable-filter=aformat
+    --disable-filter=crop
+    --disable-filter=setpts
+    --disable-filter=anull
+    --disable-filter=format
+    --disable-filter=trim
+    --disable-filter=atrim
+    --disable-filter=null
+    --disable-programs
+    --disable-avfilter
     --disable-doc
   )
   for _variant in -static -shared; do

@totaam
Copy link
Collaborator Author

totaam commented Jun 30, 2021

Also removing libx265 using --disable-libx265 would get rid of a 19MB DLL!
Unfortunately, it's also used by gstreamer plugins via libgstriff so it still gets included.
(and rebuilding gstreamer modules is probably a step too far)

Perhaps we should explicitly disable more codecs just in case they end up being installed on the build system for other reasons as the ffmpeg build will then enable them?

Not ffmpeg related, but 024f8e3 trims more unnecessary test files.

The minimal client EXE installer is now just 50MB!
Not bad at all considering that the biggest client EXE installers are from the 3.1 branch: a whopping 140MB!

To ensure that upstream packages don't update this custom ffmpeg package, I have added to /etc/pacman.conf:

IgnorePkg = mingw-w64-x86_64-ffmpeg

Which means that the ffmpeg updates will need to be done manually with a rebuild...
(fortunately, those don't happen too often)

@totaam totaam closed this as completed Jun 30, 2021
@totaam
Copy link
Collaborator Author

totaam commented Aug 30, 2021

This seems to have caused the enc_ffmpeg encoder to fail to locate any valid formats..
I guess we would need a tool like gentoo's revdep-rebuild to figure out when libraries need a rebuild.

As a result, I tried a different patch. This one ends up enabling only mpeg+mp4, which is good because other formats would be redundant.

diff --git a/mingw-w64-ffmpeg/PKGBUILD b/mingw-w64-ffmpeg/PKGBUILD
index 6470964e4..12508bea6 100644
--- a/mingw-w64-ffmpeg/PKGBUILD
+++ b/mingw-w64-ffmpeg/PKGBUILD
@@ -7,7 +7,7 @@ _realname=ffmpeg
 pkgbase="mingw-w64-${_realname}"
 pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
 pkgver=4.4
-pkgrel=9
+pkgrel=10
 pkgdesc="Complete and free Internet live audio and video broadcasting solution (mingw-w64)"
 arch=('any')
 mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
@@ -56,14 +56,11 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-dlfcn"
              "${MINGW_PACKAGE_PREFIX}-nasm")
 source=(https://ffmpeg.org/releases/${_realname}-${pkgver}.tar.xz{,.asc}
         "pathtools.c"
-        "pathtools.h"
-        "0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch")
-validpgpkeys=('FCF986EA15E6E293A5644F10B4322F04D67658D8')
+        "pathtools.h")
 sha256sums=('06b10a183ce5371f915c6bb15b7b1fffbe046e8275099c96affc29e17645d909'
             'SKIP'
             '6f1016e6647b6340fdceefaf24ff391f4c0ea3c785ddf70c9794ca2356797888'
-            '6ce4dcf4ef6c4bce48dbcb6f1b5226baf79f74ac76719fb0c06419a0aadb37a3'
-            '63aa930515c10484a68cb8940f453cba01cf3f5d0d72c86b0bc03777acb704ba')
+            '6ce4dcf4ef6c4bce48dbcb6f1b5226baf79f74ac76719fb0c06419a0aadb37a3')
 
 prepare() {
   test ! -d "${startdir}/../mingw-w64-pathtools" || {
@@ -73,8 +70,6 @@ prepare() {
 
   cd "${srcdir}/${_realname}-${pkgver}"
   cp -fHv "${srcdir}"/pathtools.[ch] libavfilter/
-
-  patch -p1 -i "${srcdir}/0005-Win32-Add-path-relocation-to-frei0r-plugins-search.patch"
 }
 
 build() {
@@ -85,48 +80,73 @@ build() {
   local -a common_config
   common_config+=(
     --disable-debug
-    --enable-amf
-    --enable-dxva2
-    --enable-d3d11va
-    --enable-fontconfig
-    --enable-gnutls
+    --disable-amf
+    --disable-everything
+    --disable-dxva2
+    --disable-d3d11va
+    --disable-fontconfig
+    --disable-gnutls
     --enable-gpl
-    --enable-libaom
-    --enable-libass
-    --enable-libbluray
-    --enable-libcaca
-    --enable-libcelt
-    --enable-libdav1d
-    --enable-libfreetype
-    --enable-libgsm
-    --enable-libmfx
-    --enable-libmodplug
+    --disable-libaom
+    --disable-libass
+    --disable-libbluray
+    --disable-libcaca
+    --disable-libcelt
+    --disable-libdav1d
+    --disable-libfreetype
+    --disable-libgsm
+    --disable-libmfx
+    --disable-libmodplug
     --enable-libmp3lame
-    --enable-libopencore_amrnb
-    --enable-libopencore_amrwb
-    --enable-libopenjpeg
+    --disable-libopencore_amrnb
+    --disable-libopencore_amrwb
+    --disable-libopenjpeg
     --enable-libopus
-    --enable-librtmp
-    --enable-libsoxr
-    --enable-libspeex
-    --enable-libsrt
-    --enable-libtheora
+    --disable-librtmp
+    --disable-libsoxr
+    --disable-libspeex
+    --disable-libsrt
+    --disable-libtheora
     --enable-libvorbis
     --enable-libx264
-    --enable-libx265
-    --enable-libxvid
+    --disable-libx265
+    --disable-libxvid
     --enable-libvpx
-    --enable-libwebp
-    --enable-libxml2
-    --enable-nvenc
-    --enable-openal
+    --disable-libwebp
+    --disable-libxml2
+    --disable-nvenc
+    --disable-openal
     --enable-pic
-    --enable-postproc
+    --disable-postproc
     --enable-runtime-cpudetect
     --enable-swresample
     --enable-version3
-    --enable-vulkan
+    --disable-vulkan
     --enable-zlib
+    --enable-decoder=h264
+    --enable-decoder=mpeg4
+    --enable-decoder=vp8
+    --enable-decoder=vp9
+    --enable-decoder=hevc
+    --enable-encoder=libvpx_vp8
+    --enable-encoder=libvpx_vp9
+    --enable-encoder=mpeg4
+    --enable-muxer=mp4
+    --enable-muxer=webm
+    --enable-muxer=matroska
+    --enable-muxer=ogg
+    --disable-protocol=tcp
+    --disable-protocol=rtp
+    --disable-filter=aformat
+    --disable-filter=crop
+    --disable-filter=setpts
+    --disable-filter=anull
+    --disable-filter=format
+    --disable-filter=trim
+    --disable-filter=atrim
+    --disable-filter=null
+    --disable-programs
+    --disable-avfilter
     --disable-doc
   )
 

@totaam
Copy link
Collaborator Author

totaam commented Mar 6, 2024

Note: we went back to using upstream builds to avoid the breakage this causes when dependencies require a rebuild.

@totaam
Copy link
Collaborator Author

totaam commented Oct 19, 2024

FWIW we no longer use ffmpeg directly: 20bb5f0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant