Skip to content

5rahim/electron-media-patch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Electron Media Patch

Version-specific Electron/Chromium patches for enabling additional media codec support, including:

  • HEVC / H.265
  • AC3
  • E-AC3
  • AC4
  • DTS
  • Dolby Vision-related platform flags

These patches are intended for building custom Electron binaries.

Caution

These patches only modify source/build behavior. They do not grant any codec, patent, distribution, or platform licenses. Make sure you understand the legal/licensing requirements before distributing binaries with proprietary codec support.


Supported versions

  • v42.4.0
  • v36.2.1+

Prerequisites

Source: Electron GN build instructions

All platforms

Install:

  • Git
  • Python 3
  • Node.js
  • Yarn/Corepack
  • depot_tools
  • Ninja / autoninja
  • A C/C++ toolchain for your platform

Install depot_tools separately, outside the Chromium checkout:

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git depot_tools

Add it to your PATH.

On macOS/Linux:

export PATH="$PWD/depot_tools:$PATH"

On Windows cmd:

set PATH=C:\src\electron\depot_tools;%PATH%

Important

On Windows, use a standalone depot_tools checkout. Do not rely on src\third_party\depot_tools as your user-facing depot_tools install. The vendored checkout can be incomplete for command-line use.


Windows-specific prerequisites

Install:

  • Visual Studio 2022 Build Tools
  • Desktop development with C++
  • Windows 10/11 SDK
  • Debugging Tools for Windows

The Debugging Tools are required because Chromium expects:

C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll

Set:

set DEPOT_TOOLS_WIN_TOOLCHAIN=0

This tells Chromium/depot_tools to use your locally installed Visual Studio instead of trying to use Google’s internal toolchain.

If Python resolves to the Microsoft Store alias, disable:

Settings -> Apps -> Advanced app settings -> App execution aliases

Turn off:

python.exe
python3.exe

Linux-specific prerequisites

From the Chromium source root after sync:

cd /home/$USER/src/electron/src
sudo ./build/install-build-deps.sh --no-prompt

If using @electron/build-tools, install Node through a version manager such as nvm. Do not install @electron/build-tools with sudo.


Getting the source

Example checkout path:

~/src/electron

On Windows, use something short like:

C:\src\electron

macOS/Linux

Run from the directory where you want the checkout:

mkdir -p ~/src/electron
cd ~/src/electron

gclient config --name "src/electron" --unmanaged https://github.com/electron/electron
gclient sync --with_branch_heads --with_tags

Windows

Run from cmd or x64 Native Tools Command Prompt:

mkdir C:\src\electron
cd /d C:\src\electron

gclient config --name "src/electron" --unmanaged https://github.com/electron/electron
gclient sync --with_branch_heads --with_tags

This will take a while.


Check out the target Electron version

Run from:

<checkout>/src/electron

Example for v42.4.0:

cd src/electron
git fetch origin --tags
git checkout v42.4.0
git describe --tags --exact-match

Expected output:

v42.4.0

Then re-sync dependencies for that tag.

Run from:

<checkout>
cd ../..
gclient sync --with_branch_heads --with_tags -f

Important

Do not apply patches to main unless the patches were made for main. Most patch failures happen because the Electron tag does not match the patch version.


Apply patches

Copy the patch files into:

<checkout>/patches

Example:

~/src/electron/patches

or on Windows:

C:\src\electron\patches

Run from the Chromium source root:

<checkout>/src

macOS/Linux

cd ~/src/electron/src

for p in ../patches/electron-v42.4.0-*.patch; do
  echo "Checking $p"
  git apply --check "$p" || exit 1
done

for p in ../patches/electron-v42.4.0-*.patch; do
  echo "Applying $p"
  git apply "$p" || exit 1
done

Windows cmd

Run from:

C:\src\electron\src
cd /d C:\src\electron\src

for %p in (..\patches\electron-v42.4.0-*.patch) do git apply --check "%p"
for %p in (..\patches\electron-v42.4.0-*.patch) do git apply "%p"

If running inside a .bat file, use %%p instead of %p.

Verify:

git status --short
git diff --check

git diff --check should ideally print nothing.


Check whether patches are already applied

From:

<checkout>/src
for p in ../patches/electron-v42.4.0-*.patch; do
  echo ""
  echo "Patch: $p"

  if git apply --reverse --check "$p" >/dev/null 2>&1; then
    echo "already applied"
  elif git apply --check "$p" >/dev/null 2>&1; then
    echo "not applied"
  else
    echo "not cleanly applicable; possibly partially applied or wrong Electron version"
  fi
done

Required GN args

These builds require proprietary codec flags.

Base args:

import("//electron/build/args/release.gn")
target_cpu="x64"

proprietary_codecs=true
ffmpeg_branding="Chrome"

enable_platform_ac3_eac3_audio=true
enable_platform_ac4_audio=true
enable_platform_dts_audio=true
enable_platform_dolby_vision=true
enable_platform_hevc=true
enable_hevc_parser_and_hw_decoder=true

use_remoteexec=false
use_reclient=false
use_siso=false

For v42.4.0, adding this may be necessary to avoid version detection failures during generated TypeScript/API steps:

override_electron_version="42.4.0"

If a GN arg is unknown for your target Electron/Chromium version, remove that arg or update the patch set for that version.


Generate build files

Run from:

<checkout>/src

macOS/Linux

gn gen out/Release-x64 --args='import("//electron/build/args/release.gn") target_cpu="x64" proprietary_codecs=true ffmpeg_branding="Chrome" enable_platform_ac3_eac3_audio=true enable_platform_ac4_audio=true enable_platform_dts_audio=true enable_platform_dolby_vision=true enable_platform_hevc=true enable_hevc_parser_and_hw_decoder=true use_remoteexec=false use_reclient=false use_siso=false override_electron_version="42.4.0"'

For Linux, you can use a Linux-specific output directory:

gn gen out/Release-linux-x64 --args='import("//electron/build/args/release.gn") target_os="linux" target_cpu="x64" proprietary_codecs=true ffmpeg_branding="Chrome" enable_platform_ac3_eac3_audio=true enable_platform_ac4_audio=true enable_platform_dts_audio=true enable_platform_dolby_vision=true enable_platform_hevc=true enable_hevc_parser_and_hw_decoder=true use_remoteexec=false use_reclient=false use_siso=false override_electron_version="42.4.0"'

Windows cmd

Run from:

C:\src\electron\src
gn gen out\Release-win-x64 --args="import(\"//electron/build/args/release.gn\") target_os=\"win\" target_cpu=\"x64\" proprietary_codecs=true ffmpeg_branding=\"Chrome\" enable_platform_ac3_eac3_audio=true enable_platform_ac4_audio=true enable_platform_dts_audio=true enable_platform_dolby_vision=true enable_platform_hevc=true enable_hevc_parser_and_hw_decoder=true use_remoteexec=false use_reclient=false use_siso=false override_electron_version=\"42.4.0\""

If gn is not found on Windows, make sure standalone depot_tools is first in PATH.


Build ffmpeg first

Build ffmpeg before the full Electron target. This catches codec patch issues early.

Run from:

<checkout>/src

macOS/Linux

autoninja -C out/Release-linux-x64 third_party/ffmpeg:ffmpeg

or, if you used out/Release-x64:

autoninja -C out/Release-x64 third_party/ffmpeg:ffmpeg

Windows

Run from:

C:\src\electron\src
autoninja -C out\Release-win-x64 third_party/ffmpeg:ffmpeg

If autoninja is unavailable, use ninja directly:

ninja -C out/Release-linux-x64 third_party/ffmpeg:ffmpeg

Build Electron

Run from:

<checkout>/src

macOS/Linux

autoninja -C out/Release-linux-x64 electron electron:electron_dist_zip

or:

autoninja -C out/Release-x64 electron electron:electron_dist_zip

Windows

Run from:

C:\src\electron\src
autoninja -C out\Release-win-x64 electron electron:electron_dist_zip

The final link step can take a long time, especially on Windows. It may appear quiet while linking electron.exe and generating .pdb files.


Packaging output

The distributable zip is produced by:

electron:electron_dist_zip

Search for artifacts:

macOS/Linux

find out -maxdepth 3 -name "*.zip" -o -name "dist*"

Windows

dir out\Release-win-x64\*.zip
dir out\Release-win-x64\dist*

Linux stripping

On Linux, if needed, strip debug/symbol information before packaging:

cd <checkout>/src
electron/script/strip-binaries.py -d out/Release-linux-x64

Then build the dist zip:

autoninja -C out/Release-linux-x64 electron:electron_dist_zip

Troubleshooting

Patch fails to apply

Most common causes:

  • Wrong Electron tag
  • gclient sync was not rerun after checking out the tag
  • Patch set is incomplete
  • Patch was already partially applied

Check:

cd <checkout>/src/electron
git describe --tags --exact-match

Then rerun from:

<checkout>
gclient sync --with_branch_heads --with_tags -f

Build asks for RBE/reclient authentication

You are trying to use remote build settings. Disable them:

use_remoteexec=false
use_reclient=false
use_siso=false

If using @electron/build-tools, also set:

"remoteBuild": "none"

Windows: python3_bin_reldir.txt not found

You are probably using vendored depot_tools from:

src\third_party\depot_tools

Use a standalone depot_tools checkout instead:

C:\src\electron\depot_tools

and put it first in PATH.

Windows: dbghelp.dll not found

Install Debugging Tools for Windows through the Windows SDK installer.

Verify:

dir "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll"

Windows: Failed to get git tag

Add:

override_electron_version="42.4.0"

to your GN args.

Also verify:

cd /d C:\src\electron\src\electron
git describe --tags --exact-match

electron_dist_zip missing

You probably built only:

electron

Build the dist target too:

autoninja -C out/Release-linux-x64 electron:electron_dist_zip

or build both at once:

autoninja -C out/Release-linux-x64 electron electron:electron_dist_zip

About

Electron patches for HEVC, AC3 and E-AC3 codec support on Windows, macOS and Linux.

Topics

Resources

Stars

8 stars

Watchers

2 watching

Forks

Contributors