commit:     c806301a09f1ae51a5198f110af001400e88ebed
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  7 22:09:11 2021 +0000
Commit:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Thu Oct  7 22:22:47 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c806301a

media-video/ffmpeg-chromium: New package based on existing ffmpeg

Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>

 media-video/ffmpeg-chromium/Manifest               |   1 +
 .../ffmpeg-chromium/ffmpeg-chromium-94.ebuild      | 223 +++++++++++++++++++++
 media-video/ffmpeg-chromium/files/chromium.patch   |  41 ++++
 .../ffmpeg-chromium/files/ffmpeg-chromium-94.patch |  26 +++
 media-video/ffmpeg-chromium/metadata.xml           |  14 ++
 5 files changed, 305 insertions(+)

diff --git a/media-video/ffmpeg-chromium/Manifest 
b/media-video/ffmpeg-chromium/Manifest
new file mode 100644
index 00000000000..3e1116a6ede
--- /dev/null
+++ b/media-video/ffmpeg-chromium/Manifest
@@ -0,0 +1 @@
+DIST ffmpeg-chromium-94.tar.gz 14709687 BLAKE2B 
06dedbd86befd8caed4c6cb34755b52cf70630f8fbd712f89d42e5b63e498f9d2a77935fbd7c87194f6d56fb0f83ff26beba00357dd51b3ac3e2e4480ff4351e
 SHA512 
a6cf5404c892c878c50e3ba8369456db587e327bc3d77e857b9d34f3665ecfee7d3865b20e9871ccda570b30d9d34c03fd981cdc7f495809ea8f12cb8f15937e

diff --git a/media-video/ffmpeg-chromium/ffmpeg-chromium-94.ebuild 
b/media-video/ffmpeg-chromium/ffmpeg-chromium-94.ebuild
new file mode 100644
index 00000000000..ccadc52a33d
--- /dev/null
+++ b/media-video/ffmpeg-chromium/ffmpeg-chromium-94.ebuild
@@ -0,0 +1,223 @@
+# Copyright 1999-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit flag-o-matic toolchain-funcs
+
+COMMIT="2d6591aa0835768c437c221c88840ac0c99a50dc"
+DESCRIPTION="FFmpeg built specifically for codec support in Chromium-based 
browsers"
+HOMEPAGE="https://ffmpeg.org/";
+SRC_URI="https://dev.gentoo.org/~chewi/distfiles/${P}.tar.gz";
+
+SLOT="${PV}"
+LICENSE="
+       !gpl? ( LGPL-2.1 )
+       gpl? ( GPL-2 )
+"
+
+KEYWORDS="~amd64 ~arm ~arm64"
+
+# Options to use as use_enable in the foo[:bar] form.
+# This will feed configure with $(use_enable foo bar)
+# or $(use_enable foo foo) if no :bar is set.
+# foo is added to IUSE.
+FFMPEG_FLAG_MAP=(
+               cpudetection:runtime-cpudetect debug
+               +gpl
+               vaapi vdpau vulkan
+               # decoders
+               mmal +opus:libopus
+               video_cards_nvidia:ffnvcodec
+               # Threads; we only support pthread for now but ffmpeg supports 
more
+               +threads:pthreads
+)
+
+IUSE="
+       ${FFMPEG_FLAG_MAP[@]%:*}
+"
+
+# Strings for CPU features in the useflag[:configure_option] form
+# if :configure_option isn't set, it will use 'useflag' as configure option
+ARM_CPU_FEATURES=(
+       cpu_flags_arm_thumb:armv5te
+       cpu_flags_arm_v6:armv6
+       cpu_flags_arm_thumb2:armv6t2
+       cpu_flags_arm_neon:neon
+       cpu_flags_arm_vfp:vfp
+       cpu_flags_arm_vfpv3:vfpv3
+       cpu_flags_arm_v8:armv8
+)
+ARM_CPU_REQUIRED_USE="
+       arm64? ( cpu_flags_arm_v8 )
+       cpu_flags_arm_v8? (  cpu_flags_arm_vfpv3 cpu_flags_arm_neon )
+       cpu_flags_arm_neon? ( cpu_flags_arm_thumb2 cpu_flags_arm_vfp )
+       cpu_flags_arm_vfpv3? ( cpu_flags_arm_vfp )
+       cpu_flags_arm_thumb2? ( cpu_flags_arm_v6 )
+       cpu_flags_arm_v6? ( cpu_flags_arm_thumb )
+"
+X86_CPU_FEATURES_RAW=( 3dnow:amd3dnow 3dnowext:amd3dnowext aes:aesni avx:avx 
avx2:avx2 fma3:fma3 fma4:fma4 mmx:mmx mmxext:mmxext sse:sse sse2:sse2 sse3:sse3 
ssse3:ssse3 sse4_1:sse4 sse4_2:sse42 xop:xop )
+X86_CPU_FEATURES=( ${X86_CPU_FEATURES_RAW[@]/#/cpu_flags_x86_} )
+X86_CPU_REQUIRED_USE="
+       cpu_flags_x86_avx2? ( cpu_flags_x86_avx )
+       cpu_flags_x86_fma4? ( cpu_flags_x86_avx )
+       cpu_flags_x86_fma3? ( cpu_flags_x86_avx )
+       cpu_flags_x86_xop?  ( cpu_flags_x86_avx )
+       cpu_flags_x86_avx?  ( cpu_flags_x86_sse4_2 )
+       cpu_flags_x86_aes? ( cpu_flags_x86_sse4_2 )
+       cpu_flags_x86_sse4_2?  ( cpu_flags_x86_sse4_1 )
+       cpu_flags_x86_sse4_1?  ( cpu_flags_x86_ssse3 )
+       cpu_flags_x86_ssse3?  ( cpu_flags_x86_sse3 )
+       cpu_flags_x86_sse3?  ( cpu_flags_x86_sse2 )
+       cpu_flags_x86_sse2?  ( cpu_flags_x86_sse )
+       cpu_flags_x86_sse?  ( cpu_flags_x86_mmxext )
+       cpu_flags_x86_mmxext?  ( cpu_flags_x86_mmx )
+       cpu_flags_x86_3dnowext?  ( cpu_flags_x86_3dnow )
+       cpu_flags_x86_3dnow?  ( cpu_flags_x86_mmx )
+"
+
+CPU_FEATURES_MAP=(
+       ${ARM_CPU_FEATURES[@]}
+       ${X86_CPU_FEATURES[@]}
+)
+IUSE="${IUSE}
+       ${CPU_FEATURES_MAP[@]%:*}"
+
+CPU_REQUIRED_USE="
+       ${ARM_CPU_REQUIRED_USE}
+       ${X86_CPU_REQUIRED_USE}
+"
+
+RDEPEND="
+       mmal? ( media-libs/raspberrypi-userland )
+       opus? ( >=media-libs/opus-1.0.2-r2 )
+       vaapi? ( >=x11-libs/libva-1.2.1-r1:0= )
+       video_cards_nvidia? ( >=media-libs/nv-codec-headers-9.1.23.1 )
+       vdpau? ( >=x11-libs/libvdpau-0.7 )
+       vulkan? ( >=media-libs/vulkan-loader-1.1.97:= )
+"
+
+DEPEND="${RDEPEND}
+"
+BDEPEND="
+       >=sys-devel/make-3.81
+       virtual/pkgconfig
+       cpu_flags_x86_mmx? ( || ( >=dev-lang/nasm-2.13 >=dev-lang/yasm-1.3 ) )
+"
+
+REQUIRED_USE="
+       ${CPU_REQUIRED_USE}"
+RESTRICT="
+       test
+"
+
+S="${WORKDIR}"
+
+PATCHES=(
+       "${FILESDIR}"/${P}.patch
+       "${FILESDIR}"/chromium.patch
+)
+
+src_prepare() {
+       export revision=git-N-g${COMMIT:0:10}
+       default
+       echo 'include $(SRC_PATH)/ffbuild/libffmpeg.mak' >> Makefile || die
+}
+
+src_configure() {
+       local myconf=( )
+
+       local ffuse=( "${FFMPEG_FLAG_MAP[@]}" )
+
+       for i in "${ffuse[@]#+}" ; do
+               myconf+=( $(use_enable ${i%:*} ${i#*:}) )
+       done
+
+       # CPU features
+       for i in "${CPU_FEATURES_MAP[@]}" ; do
+               use ${i%:*} || myconf+=( --disable-${i#*:} )
+       done
+
+       # Try to get cpu type based on CFLAGS.
+       # Bug #172723
+       # We need to do this so that features of that CPU will be better used
+       # If they contain an unknown CPU it will not hurt since ffmpeg's 
configure
+       # will just ignore it.
+       for i in $(get-flag mcpu) $(get-flag march) ; do
+               [[ ${i} = native ]] && i="host" # bug #273421
+               myconf+=( --cpu=${i} )
+               break
+       done
+
+       # LTO support, bug #566282, bug #754654
+       is-flagq "-flto*" && myconf+=( "--enable-lto" )
+       filter-flags "-flto*"
+
+       # Mandatory configuration
+       myconf=(
+               --disable-stripping
+               # This is only for hardcoded cflags; those are used in 
configure checks that may
+               # interfere with proper detections, bug #671746 and bug #645778
+               # We use optflags, so that overrides them anyway.
+               --disable-optimizations
+               --disable-libcelt # bug #664158
+               "${myconf[@]}"
+       )
+
+       # cross compile support
+       if tc-is-cross-compiler ; then
+               myconf+=( --enable-cross-compile --arch=$(tc-arch-kernel) 
--cross-prefix=${CHOST}- --host-cc="$(tc-getBUILD_CC)" )
+               case ${CHOST} in
+                       *freebsd*)
+                               myconf+=( --target-os=freebsd )
+                               ;;
+                       *mingw32*)
+                               myconf+=( --target-os=mingw32 )
+                               ;;
+                       *linux*)
+                               myconf+=( --target-os=linux )
+                               ;;
+               esac
+       fi
+
+       set -- "${S}/configure" \
+               --prefix="${EPREFIX}/usr" \
+               --libdir="${EPREFIX}/usr/$(get_libdir)" \
+               --shlibdir="${EPREFIX}/usr/$(get_libdir)" \
+               --cc="$(tc-getCC)" \
+               --cxx="$(tc-getCXX)" \
+               --ar="$(tc-getAR)" \
+               --nm="$(tc-getNM)" \
+               --ranlib="$(tc-getRANLIB)" \
+               --pkg-config="$(tc-getPKG_CONFIG)" \
+               --optflags="${CFLAGS}" \
+               --disable-all \
+               --disable-autodetect \
+               --disable-error-resilience \
+               --disable-everything \
+               --disable-faan \
+               --disable-iconv \
+               --disable-lzo \
+               --disable-network \
+               --enable-avcodec \
+               --enable-avformat \
+               --enable-avutil \
+               
--enable-decoder=aac,flac,h264,libopus,mp3,pcm_alaw,pcm_f32le,pcm_mulaw,pcm_s16be,pcm_s16le,pcm_s24be,pcm_s24le,pcm_s32le,pcm_u8,theora,vorbis,vp8
 \
+               --enable-demuxer=aac,flac,matroska,mov,mp3,ogg,wav \
+               --enable-parser=aac,flac,h264,mpegaudio,opus,vorbis,vp3,vp8,vp9 
\
+               --enable-pic \
+               --enable-static \
+               "${myconf[@]}" \
+               ${EXTRA_FFMPEG_CONF}
+
+       echo "${@}"
+       "${@}" || die
+}
+
+src_compile() {
+       emake V=1 libffmpeg
+}
+
+src_install() {
+       emake V=1 DESTDIR="${D}" install-libffmpeg
+}

diff --git a/media-video/ffmpeg-chromium/files/chromium.patch 
b/media-video/ffmpeg-chromium/files/chromium.patch
new file mode 100644
index 00000000000..e24ea84b3df
--- /dev/null
+++ b/media-video/ffmpeg-chromium/files/chromium.patch
@@ -0,0 +1,41 @@
+Allow libffmpeg to be built for Chromium-based browsers
+https://patchwork.ffmpeg.org/patch/4500/
+
+NOTE: This patch lacks the Makefile include line. We append it
+manually instead to make patching across different versions easier.
+
+diff --git a/ffbuild/libffmpeg.mak b/ffbuild/libffmpeg.mak
+new file mode 100644
+index 0000000..992cf3c
+--- /dev/null
++++ b/ffbuild/libffmpeg.mak
+@@ -0,0 +1,27 @@
++LIBFFMPEG = $(SLIBPREF)ffmpeg$(SLIBSUF)
++LIBFFMPEG_LINK = $(LD) -shared -Wl,-soname,$(LIBFFMPEG) -Wl,-Bsymbolic 
-Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--gc-sections $(LDFLAGS) $(LDLIBFLAGS) 
-o $(LIBFFMPEG)
++
++ifeq ($(CONFIG_SHARED),yes)
++LIBFFMPEG_DEPS = libavcodec/$(SLIBPREF)avcodec$(SLIBSUF) 
libavformat/$(SLIBPREF)avformat$(SLIBSUF) libavutil/$(SLIBPREF)avutil$(SLIBSUF)
++else
++LIBFFMPEG_DEPS = libavcodec/$(LIBPREF)avcodec$(LIBSUF) 
libavformat/$(LIBPREF)avformat$(LIBSUF) libavutil/$(LIBPREF)avutil$(LIBSUF)
++endif
++
++$(LIBFFMPEG): $(LIBFFMPEG_DEPS)
++ifeq ($(CONFIG_SHARED),yes)
++      $(LIBFFMPEG_LINK) -Wl,--no-as-needed -lavcodec -lavformat -lavutil
++else
++      $(LIBFFMPEG_LINK) -Wl,--whole-archive $^ -Wl,--no-whole-archive 
$(EXTRALIBS-avcodec) $(EXTRALIBS-avformat) $(EXTRALIBS-avutil)
++endif
++
++libffmpeg: $(LIBFFMPEG)
++
++install-libffmpeg: $(LIBFFMPEG)
++      $(Q)mkdir -p "$(SHLIBDIR)/chromium"
++      $(INSTALL) -m 755 $< "$(SHLIBDIR)/chromium/$<.$(SLOT)"
++      $(STRIP) "$(SHLIBDIR)/chromium/$<.$(SLOT)"
++
++uninstall-libffmpeg:
++      $(RM) "$(SHLIBDIR)/chromium/$(LIBFFMPEG).$(SLOT)"
++
++.PHONY: libffmpeg install-libffmpeg uninstall-libffmpeg
+--
+2.13.1

diff --git a/media-video/ffmpeg-chromium/files/ffmpeg-chromium-94.patch 
b/media-video/ffmpeg-chromium/files/ffmpeg-chromium-94.patch
new file mode 100644
index 00000000000..ba1dfd2c051
--- /dev/null
+++ b/media-video/ffmpeg-chromium/files/ffmpeg-chromium-94.patch
@@ -0,0 +1,26 @@
+--- FFmpeg-chromium/configure  2021-10-07 22:32:34.230130424 +0100
++++ FFmpeg/configure   2021-10-07 22:34:30.978861042 +0100
+@@ -6474,15 +6464,14 @@
+                                { require_pkg_config libopenjpeg "libopenjp2 
>= 2.1.0" openjpeg.h opj_version -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } }
+ enabled libopenmpt        && require_pkg_config libopenmpt "libopenmpt >= 
0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create -lstdc++ && append 
libopenmpt_extralibs "-lstdc++"
+ enabled libopenvino       && require libopenvino c_api/ie_c_api.h 
ie_c_api_version -linference_engine_c_api
+-# Chromium uses a built in copy of libopus that is not visible to pkg-config.
+-# enabled libopus           && {
+-#    enabled libopus_decoder && {
+-#        require_pkg_config libopus opus opus_multistream.h 
opus_multistream_decoder_create
+-#    }
+-#    enabled libopus_encoder && {
+-#        require_pkg_config libopus opus opus_multistream.h 
opus_multistream_surround_encoder_create
+-#    }
+-# }
++enabled libopus           && {
++    enabled libopus_decoder && {
++        require_pkg_config libopus opus opus_multistream.h 
opus_multistream_decoder_create
++    }
++    enabled libopus_encoder && {
++        require_pkg_config libopus opus opus_multistream.h 
opus_multistream_surround_encoder_create
++    }
++}
+ enabled libpulse          && require_pkg_config libpulse libpulse 
pulse/pulseaudio.h pa_context_new
+ enabled librabbitmq       && require_pkg_config librabbitmq "librabbitmq >= 
0.7.1" amqp.h amqp_new_connection
+ enabled librav1e          && require_pkg_config librav1e "rav1e >= 0.4.0" 
rav1e.h rav1e_context_new

diff --git a/media-video/ffmpeg-chromium/metadata.xml 
b/media-video/ffmpeg-chromium/metadata.xml
new file mode 100644
index 00000000000..5e0aeba3b15
--- /dev/null
+++ b/media-video/ffmpeg-chromium/metadata.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+<maintainer type="person">
+       <email>[email protected]</email>
+       <name>James Le Cuirot</name>
+</maintainer>
+<use>
+       <flag name="cpudetection">Enables runtime CPU detection (useful for 
bindist, compatibility on other CPUs)</flag>
+       <flag name="gpl">Build GPL code. Should be enabled unless you require 
LGPL binaries.</flag>
+       <flag name="mmal">Enables Multi-Media Abstraction Layer (MMAL) decoding 
support: Available e.g. on the Raspberry Pi.</flag>
+       <flag name="vulkan">Enables support for the vulkan API for GPU 
offload.</flag>
+</use>
+</pkgmetadata>

Reply via email to