Compiling Chromium with H.264 and AAC Support via FFmpeg
By default, the open-source Chromium web browser lacks out-of-the-box support for proprietary media codecs like H.264 and AAC due to patent and licensing restrictions. However, users compiling the browser from source can manually enable these formats by altering the build configuration for Chromium's bundled FFmpeg library. This article details the exact build flags and compilation steps required to integrate H.264 video and AAC audio decoding into a custom Chromium build.
Prerequisites
Before modifying the media configuration, you must have a working
Chromium build environment. Ensure that you have
depot_tools installed in your system's PATH and that you
have already fetched the Chromium source code. All commands below must
be run from the src directory of your Chromium
checkout.
Understanding the GN Build Flags
Chromium uses the Generate Ninja (GN) meta-build system to configure
compilation parameters. While Chromium includes the full FFmpeg source
code in its third_party/ffmpeg directory, the default build
configuration strips out patent-encumbered code during compilation.
To include H.264 and AAC, you need to set two specific GN arguments:
proprietary_codecs = true: This flag alters the Chromium media pipeline, enabling the browser to recognize, demux, and process proprietary media containers and streams such as MP4.ffmpeg_branding = "Chrome": By default, this is set to"Chromium". Changing it to"Chrome"instructs the build system to compile the bundled FFmpeg library using the configuration profile meant for Google Chrome, which includes the actual H.264 and AAC decoders.
Configuring the Build
To apply these flags to your build, you need to edit the
args.gn file located in your specific build output
directory (commonly out/Default).
- Run the following command to open the configuration file in your default text editor:
gn args out/Default- In the editor that opens, append the following lines to the file:
proprietary_codecs = true
ffmpeg_branding = "Chrome"
- Save the file and close the text editor.
Upon closing the editor, GN will automatically parse the file, validate the arguments, and regenerate the necessary Ninja build files to include the new FFmpeg compilation targets.
Alternative: Command-Line Configuration
If you prefer not to use an interactive text editor, or if you are automating the build via a script, you can generate the build directory and pass the arguments directly via the command line:
gn gen out/Default --args='proprietary_codecs=true ffmpeg_branding="Chrome"'Compiling Chromium
With the build files updated, you can now compile the browser. The build system will compile the newly unlocked FFmpeg decoders and link them into the Chromium binary.
Run the following command to start the compilation process:
autoninja -C out/Default chromeIf you had already compiled Chromium in this directory prior to changing the flags, you do not need to do a clean build. Ninja will automatically detect the configuration changes and recompile only the affected FFmpeg and media targets, saving significant time.
Verifying Codec Support
Once the compilation finishes, run your new Chromium build:
./out/Default/chromeTo confirm that the codecs are active, attempt to play a standard MP4
video encoded with H.264 video and AAC audio. For a more technical
verification, open a new tab, navigate to
chrome://media-internals, and play a video. Expanding the
active player log on this page will confirm that
FFmpegVideoDecoder or a hardware-accelerated equivalent is
actively decoding the H.264 and AAC streams.