[FFmpeg-devel] [PATCH] build: Allow libffmpeg to be built for Chromium-based browsers

James Le Cuirot chewi at gentoo.org
Fri Jul 28 13:07:16 EEST 2017

Google Chrome ships with support for proprietary codecs and Chromium
can be built with support for them, either using the bundled FFmpeg or
a system copy.

This leaves other browsers such as Opera and Vivaldi, which ship with
a libffmpeg that does not support proprietary codecs, presumably for
cost reasons. These projects actively encourage users to swap this
library with an alternative.

Official instructions say to download the very large Chromium tarball
and use its build system to configure and build libffmpeg. This
involves building a lot of extra baggage that simply isn't needed
because libffmpeg is literally just the main FFmpeg libraries
combined. Binary-based distributions can easily take this hit but for
source-based distributions, this hit is passed onto the end user.

This Makefile snippet allows libffmpeg to be created without the help
of Chromium's build system. It uses the CONFIG_SHARED variable to
decide whether to link the FFmpeg libraries statically or
dynamically. In the latter case, libffmpeg is just a wrapper with no
symbols of its own.

At this current time, recent Chromium versions support the 3.x ABI
with just one major exception. Unless built against the system copy,
-DFF_API_CONVERGENCE_DURATION=0 is used. This means that, other
factors notwithstanding, full compatibility will not be seen until
libavcodec hits 59. This is why I have provided the ability to link
FFmpeg statically.

This is how to build libffmpeg for a recent Chromium-based release:

 ./configure --disable-shared --enable-static --enable-pic --extra-cflags="-DFF_API_CONVERGENCE_DURATION=0"
 make libffmpeg
 make install-libffmpeg

I have tested this with FFmpeg 3.3.2 and latest master. I have tested
it against current Opera Stable, Opera Beta, Opera Developer, Vivaldi
Stable, and Vivaldi Snapshot.
 Makefile              |  1 +
 ffbuild/libffmpeg.mak | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 ffbuild/libffmpeg.mak

diff --git a/Makefile b/Makefile
index 29870d7..1e267e7 100644
--- a/Makefile
+++ b/Makefile
@@ -65,6 +65,7 @@ all: all-yes
 include $(SRC_PATH)/tools/Makefile
 include $(SRC_PATH)/ffbuild/common.mak
+include $(SRC_PATH)/ffbuild/libffmpeg.mak
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,21 @@
+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)
+libffmpeg-: libavcodec/$(LIBPREF)avcodec$(LIBSUF) libavformat/$(LIBPREF)avformat$(LIBSUF) libavutil/$(LIBPREF)avutil$(LIBSUF) libswresample/$(LIBPREF)swresample$(LIBSUF)
+	$(LIBFFMPEG_LINK) -Wl,--whole-archive $^ -Wl,--no-whole-archive $(FFEXTRALIBS)
+libffmpeg-yes: libavcodec/$(SLIBPREF)avcodec$(SLIBSUF) libavformat/$(SLIBPREF)avformat$(SLIBSUF) libavutil/$(SLIBPREF)avutil$(SLIBSUF)
+	$(LIBFFMPEG_LINK) -Wl,--no-as-needed -lavcodec -lavformat -lavutil
+libffmpeg: $(LIBFFMPEG)
+install-libffmpeg: $(LIBFFMPEG)
+	$(Q)mkdir -p "$(SHLIBDIR)/chromium"
+	$(INSTALL) -m 755 $< "$(SHLIBDIR)/chromium/$<"
+	$(STRIP) "$(SHLIBDIR)/chromium/$<"
+	$(RM) "$(SHLIBDIR)/chromium/$(LIBFFMPEG)"
+.PHONY: libffmpeg libffmpeg-* install-libffmpeg

More information about the ffmpeg-devel mailing list