CefSharp and H264 support

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CefSharp and H264 support

Postby djst3rios2 » Sun Jun 17, 2018 3:57 pm

Hello, I want to use CefSharp with H264 support, and after searching the first step would be to build CEF. I've been trying all day with no luck. The first guide I tried was this one: https://bitbucket.org/chromiumembedded/cef/wiki/MasterBuildQuickStart.md#markdown-header-windows-setup

I added in GYP_DEFINES these: proprietary_codecs=1 ffmpeg_branding=Chrome
However, I am stuck in Step 7, I cannot create a solution file, it tries to use a file gn.exe which doesn't exist for some reason. There's only a gn.exe.sha1 file in that "buildtools" folder.
I've been watching threads and threads on this matter and I still haven't been able to compile it successfully! Let alone use it with CefSharp. Does anyone know an up-to-date guide that will work? The wiki isn't much of help in my case.
One thing I should mention is that my VS2017 is not installed in C: which is the default location, but in L: instead. Any help would be great. :?
djst3rios2
Techie
 
Posts: 18
Joined: Mon Jun 11, 2018 4:22 am

Re: CefSharp and H264 support

Postby ndesktop » Sun Jun 17, 2018 11:49 pm

djst3rios2 wrote:I added in GYP_DEFINES these: proprietary_codecs=1 ffmpeg_branding=Chrome

Looks ok. Maybe "GN_DEFINED=is_official_build=true proprietary_codecs=true ffmpeg_branding=Chrome" will help, although.
Check also this thread.

djst3rios2 wrote:However, I am stuck in Step 7, I cannot create a solution file, it tries to use a file gn.exe which doesn't exist for some reason. There's only a gn.exe.sha1 file in that "buildtools" folder.
I've been watching threads and threads on this matter and I still haven't been able to compile it successfully! Let alone use it with CefSharp. Does anyone know an up-to-date guide that will work? The wiki isn't much of help in my case.
One thing I should mention is that my VS2017 is not installed in C: which is the default location, but in L: instead. Any help would be great. :?

I'm not sure what step 7 means.
However, the build scripts should detect the location of VS if is installed normally (i.e. is not a copied content from another installation).
Check if you have also DEPOT_TOOLS_WIN_TOOLCHAIN=0 variable set.

If you want to specify a custom location for VS, you can specify it as (my custom location):
SET GYP_MSVS_OVERRIDE_PATH=G:\bin\vs\2017\enterprise
where the location is the root dir of VS2017 installation (the directory contains Common7, SDK, VC etc. directories).
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: CefSharp and H264 support

Postby djst3rios2 » Tue Jun 19, 2018 5:00 am

ndesktop wrote:
djst3rios2 wrote:I added in GYP_DEFINES these: proprietary_codecs=1 ffmpeg_branding=Chrome

Looks ok. Maybe "GN_DEFINED=is_official_build=true proprietary_codecs=true ffmpeg_branding=Chrome" will help, although.
Check also this thread.

djst3rios2 wrote:However, I am stuck in Step 7, I cannot create a solution file, it tries to use a file gn.exe which doesn't exist for some reason. There's only a gn.exe.sha1 file in that "buildtools" folder.
I've been watching threads and threads on this matter and I still haven't been able to compile it successfully! Let alone use it with CefSharp. Does anyone know an up-to-date guide that will work? The wiki isn't much of help in my case.
One thing I should mention is that my VS2017 is not installed in C: which is the default location, but in L: instead. Any help would be great. :?

I'm not sure what step 7 means.
However, the build scripts should detect the location of VS if is installed normally (i.e. is not a copied content from another installation).
Check if you have also DEPOT_TOOLS_WIN_TOOLCHAIN=0 variable set.

If you want to specify a custom location for VS, you can specify it as (my custom location):
SET GYP_MSVS_OVERRIDE_PATH=G:\bin\vs\2017\enterprise
where the location is the root dir of VS2017 installation (the directory contains Common7, SDK, VC etc. directories).


Thanks for the response, I got an error because the SDK was installed in C drive but visual studio in L drive.
now I updated the MSVS override path, but if I run update.bat again, it doesn't seem to try and copy files from the SDK folder anymore. It only does some git checks and that's it. I usually delete all folders and restart the whole thing, is there a way to avoid wasting another 2 hours to restart the entire process?
djst3rios2
Techie
 
Posts: 18
Joined: Mon Jun 11, 2018 4:22 am

Re: CefSharp and H264 support

Postby ndesktop » Tue Jun 19, 2018 5:53 am

I don't know if the script copies SDK files somewhere in the out/ land.

Most likely gn generated already the paths incorrectly; I would check inside the out\build_platform_type the content of environment.x86 and environment.x64.
If the path to SDK is compromised, I'd say you cannot escape without a rebuild, only the download and (partially) the configure part.

Normally a delete of out\build_platform_type and rerun of automate will do it (or you can run rerun tools\gclient_hooks.py then ninja -C out\... manually).

If you cannot do that, you have two more choices (suppose you're building x86, for x64 the same).

Regenerate configuration
This in case (like me) you have multiple custom modifications of CEF and do not/cannot run again the cef patching.
If you do not have customizations, skip to end.

For this, you may modify manually inside cef/ the following files:
tools/gclient_hook.py
Code: Select all
# Copyright (c) 2011 The Chromium Embedded Framework Authors.
# Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gclient_util import *
from gn_args import GetAllPlatformConfigs, GetConfigFileContents
from file_util import make_dir, write_file
import os, sys
import issue_1999

regenerate_projects = False
if len(sys.argv) > 1:
  for i in range(1, len(sys.argv)):
    if sys.argv[i] == '--regenerate':
      regenerate_projects = True
      break

# The CEF directory is the parent directory of _this_ script.
cef_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
# The src directory is the parent directory of the CEF directory.
src_dir = os.path.abspath(os.path.join(cef_dir, os.pardir))

# Determine the platform.
if sys.platform == 'win32':
  platform = 'windows'
elif sys.platform == 'darwin':
  platform = 'macosx'
elif sys.platform.startswith('linux'):
  platform = 'linux'
else:
  print 'Unknown operating system platform'
  sys.exit()

if not regenerate_projects:
  print "\nGenerating CEF version header file..."
  cmd = [
      'python', 'tools/make_version_header.py', '--header',
      'include/cef_version.h', '--cef_version', 'VERSION', '--chrome_version',
      '../chrome/VERSION', '--cpp_header_dir', 'include'
  ]
  RunAction(cef_dir, cmd)
else:
  print "\nRegenerating CEF projects, skipping version header file."
 
if not regenerate_projects:
  print "\nPatching build configuration and source files for CEF..."
  cmd = ['python', 'tools/patcher.py']
  RunAction(cef_dir, cmd)
else:
  print "\nRegenerate projects, skip patching build configuration and source files for CEF."

if not regenerate_projects:
  print "\nGenerating CEF project files..."
else:
  print "\nRegenerating CEF project files..."

gn_args = {}

if platform == 'windows':
  # Force use of the locally installed version of Visual Studio.
  if not 'DEPOT_TOOLS_WIN_TOOLCHAIN' in os.environ:
    os.environ['DEPOT_TOOLS_WIN_TOOLCHAIN'] = '0'

  # By default GN+Ninja on Windows expects Visual Studio to be installed on
  # the local machine. To build when Visual Studio is extracted to a directory
  # but not installed (e.g. via a custom toolchain) set the following
  # environment variables:
  #
  # o Enable use of a custom toolchain on Windows.
  #
  #   set WIN_CUSTOM_TOOLCHAIN=1
  #
  # o Used by tools/msvs_env.bat to configure the MSVS tools environment.
  #   Should be set to "none" because VC variables for CEF will be set via
  #   INCLUDE/LIB/PATH.
  #
  #   set CEF_VCVARS=none
  #
  # o Used by the following scripts:
  #   (a) build/vs_toolchain.py SetEnvironmentAndGetRuntimeDllDirs when
  #   determining whether to copy VS runtime binaries to the output directory.
  #   If GYP_MSVS_OVERRIDE_PATH exists then binaries will not be copied and
  #   should instead be discoverable via the PATH env variable.
  #   (b) build/toolchain/win/setup_toolchain.py _LoadToolchainEnv when
  #   writing environment.* files that specify INCLUDE/LIB/PATH values. If
  #   "%GYP_MSVS_OVERRIDE_PATH%\VC\vcvarsall.bat" exists then environment
  #   variables will be derived from there and the specified INCLUDE/LIB/PATH
  #   values will be ignored by Chromium. If this file does not exist then the
  #   INCLUDE/LIB/PATH values are also required by Chromium.
  #   TODO(cef): Rename to VS_ROOT and VS_VERSION after Chromium cleans up GYP
  #   dependencies.
  #
  #   set GYP_MSVS_OVERRIDE_PATH=<VS root directory>
  #   set GYP_MSVS_VERSION=<VS version>
  #
  # o Used to configure GN arguments in this script.
  #
  #   set VS_CRT_ROOT=<VS CRT root directory>
  #   set SDK_ROOT=<Platform SDK root directory>
  #
  # o Used by various scripts as described above.
  #   TODO(cef): Make these values optional when
  #   "%GYP_MSVS_OVERRIDE_PATH%\VC\vcvarsall.bat" exists (use values from that
  #   script instead).
  #
  #   set INCLUDE=<VS include paths>
  #   set LIB=<VS library paths>
  #   set PATH=<VS executable paths>
  #
  # See tools/depot_tools/win_toolchain/package_from_installed.py for an example
  # packaging script along with required directory contents and INCLUDE/LIB/PATH
  # values.
  #
  if bool(int(os.environ.get('WIN_CUSTOM_TOOLCHAIN', '0'))):
    required_vars = [
        'CEF_VCVARS',
        'GYP_MSVS_OVERRIDE_PATH',
        'GYP_MSVS_VERSION',
        'VS_CRT_ROOT',
        'SDK_ROOT',
        'INCLUDE',
        'LIB',
        'PATH',
    ]
    for var in required_vars:
      if not var in os.environ.keys():
        raise Exception('%s environment variable must be set' % var)

    # Windows custom toolchain requirements. See comments in gn_args.py.
    gn_args['visual_studio_path'] = os.environ['GYP_MSVS_OVERRIDE_PATH']
    gn_args['visual_studio_version'] = os.environ['GYP_MSVS_VERSION']
    gn_args['visual_studio_runtime_dirs'] = os.environ['VS_CRT_ROOT']
    gn_args['windows_sdk_path'] = os.environ['SDK_ROOT']

configs = GetAllPlatformConfigs(gn_args)
for dir, config in configs.items():
  # Create out directories and write the args.gn file.
  out_path = os.path.join(src_dir, 'out', dir)
  make_dir(out_path, False)
  args_gn_path = os.path.join(out_path, 'args.gn')
  args_gn_contents = GetConfigFileContents(config)
  write_file(args_gn_path, args_gn_contents)

  # Generate the Ninja config.
  cmd = ['gn', 'gen', os.path.join('out', dir)]
  if 'GN_ARGUMENTS' in os.environ.keys():
    cmd.extend(os.environ['GN_ARGUMENTS'].split(' '))
  RunAction(src_dir, cmd)
  if platform == 'windows':
    issue_1999.apply(out_path)

This (crudely) adds --regenerate argument to gclient_hook.py. (It is a derivation of 3282 branch file, so adapt accordingly if changed since 3282).

And then cef_create_projects.bat:
Code: Select all
@echo off
if [%1%] EQU [regenerate] goto l_regenerate
goto l_default

:l_default
python.bat tools\gclient_hook.py
goto l_end

:l_regenerate
python.bat tools\gclient_hook.py --regenerate
goto l_end

:l_end

This allows you to pass --regenerate to cef_create_projects.

Now you can run cef_create_projects --regenerate which will not clobber version and already patched files, and will just run gn gen for all platforms.

end:
Rename/delete out\Release_x86, rerun cef_create_projects.bat, then ninja -C out\Release_x86.

Hardcore
Edit manually environment.x86 (possibly also environment.winrt_x86) and fix inside the INCLUDE and LIB (possibly also PATH) the SDK path
Pitfall: environment files contains NUL characters. Programmer's Notepad, for example, knows to handle them correctly. I don't know about others.
Backup the files first to avoid editor surprises.

Then ninja -t clean to clean the files, and ninja -C to (re)build. This may or may not work, and is definitely not somehing to do first.
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: CefSharp and H264 support

Postby djst3rios2 » Tue Jun 19, 2018 6:27 am

ndesktop wrote:I don't know if the script copies SDK files somewhere in the out/ land.

Most likely gn generated already the paths incorrectly; I would check inside the out\build_platform_type the content of environment.x86 and environment.x64.
If the path to SDK is compromised, I'd say you cannot escape without a rebuild, only the download and (partially) the configure part.

Normally a delete of out\build_platform_type and rerun of automate will do it (or you can run rerun tools\gclient_hooks.py then ninja -C out\... manually).

If you cannot do that, you have two more choices (suppose you're building x86, for x64 the same).

Regenerate configuration
This in case (like me) you have multiple custom modifications of CEF and do not/cannot run again the cef patching.
If you do not have customizations, skip to end.

For this, you may modify manually inside cef/ the following files:
tools/gclient_hook.py
Code: Select all
# Copyright (c) 2011 The Chromium Embedded Framework Authors.
# Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from gclient_util import *
from gn_args import GetAllPlatformConfigs, GetConfigFileContents
from file_util import make_dir, write_file
import os, sys
import issue_1999

regenerate_projects = False
if len(sys.argv) > 1:
  for i in range(1, len(sys.argv)):
    if sys.argv[i] == '--regenerate':
      regenerate_projects = True
      break

# The CEF directory is the parent directory of _this_ script.
cef_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
# The src directory is the parent directory of the CEF directory.
src_dir = os.path.abspath(os.path.join(cef_dir, os.pardir))

# Determine the platform.
if sys.platform == 'win32':
  platform = 'windows'
elif sys.platform == 'darwin':
  platform = 'macosx'
elif sys.platform.startswith('linux'):
  platform = 'linux'
else:
  print 'Unknown operating system platform'
  sys.exit()

if not regenerate_projects:
  print "\nGenerating CEF version header file..."
  cmd = [
      'python', 'tools/make_version_header.py', '--header',
      'include/cef_version.h', '--cef_version', 'VERSION', '--chrome_version',
      '../chrome/VERSION', '--cpp_header_dir', 'include'
  ]
  RunAction(cef_dir, cmd)
else:
  print "\nRegenerating CEF projects, skipping version header file."
 
if not regenerate_projects:
  print "\nPatching build configuration and source files for CEF..."
  cmd = ['python', 'tools/patcher.py']
  RunAction(cef_dir, cmd)
else:
  print "\nRegenerate projects, skip patching build configuration and source files for CEF."

if not regenerate_projects:
  print "\nGenerating CEF project files..."
else:
  print "\nRegenerating CEF project files..."

gn_args = {}

if platform == 'windows':
  # Force use of the locally installed version of Visual Studio.
  if not 'DEPOT_TOOLS_WIN_TOOLCHAIN' in os.environ:
    os.environ['DEPOT_TOOLS_WIN_TOOLCHAIN'] = '0'

  # By default GN+Ninja on Windows expects Visual Studio to be installed on
  # the local machine. To build when Visual Studio is extracted to a directory
  # but not installed (e.g. via a custom toolchain) set the following
  # environment variables:
  #
  # o Enable use of a custom toolchain on Windows.
  #
  #   set WIN_CUSTOM_TOOLCHAIN=1
  #
  # o Used by tools/msvs_env.bat to configure the MSVS tools environment.
  #   Should be set to "none" because VC variables for CEF will be set via
  #   INCLUDE/LIB/PATH.
  #
  #   set CEF_VCVARS=none
  #
  # o Used by the following scripts:
  #   (a) build/vs_toolchain.py SetEnvironmentAndGetRuntimeDllDirs when
  #   determining whether to copy VS runtime binaries to the output directory.
  #   If GYP_MSVS_OVERRIDE_PATH exists then binaries will not be copied and
  #   should instead be discoverable via the PATH env variable.
  #   (b) build/toolchain/win/setup_toolchain.py _LoadToolchainEnv when
  #   writing environment.* files that specify INCLUDE/LIB/PATH values. If
  #   "%GYP_MSVS_OVERRIDE_PATH%\VC\vcvarsall.bat" exists then environment
  #   variables will be derived from there and the specified INCLUDE/LIB/PATH
  #   values will be ignored by Chromium. If this file does not exist then the
  #   INCLUDE/LIB/PATH values are also required by Chromium.
  #   TODO(cef): Rename to VS_ROOT and VS_VERSION after Chromium cleans up GYP
  #   dependencies.
  #
  #   set GYP_MSVS_OVERRIDE_PATH=<VS root directory>
  #   set GYP_MSVS_VERSION=<VS version>
  #
  # o Used to configure GN arguments in this script.
  #
  #   set VS_CRT_ROOT=<VS CRT root directory>
  #   set SDK_ROOT=<Platform SDK root directory>
  #
  # o Used by various scripts as described above.
  #   TODO(cef): Make these values optional when
  #   "%GYP_MSVS_OVERRIDE_PATH%\VC\vcvarsall.bat" exists (use values from that
  #   script instead).
  #
  #   set INCLUDE=<VS include paths>
  #   set LIB=<VS library paths>
  #   set PATH=<VS executable paths>
  #
  # See tools/depot_tools/win_toolchain/package_from_installed.py for an example
  # packaging script along with required directory contents and INCLUDE/LIB/PATH
  # values.
  #
  if bool(int(os.environ.get('WIN_CUSTOM_TOOLCHAIN', '0'))):
    required_vars = [
        'CEF_VCVARS',
        'GYP_MSVS_OVERRIDE_PATH',
        'GYP_MSVS_VERSION',
        'VS_CRT_ROOT',
        'SDK_ROOT',
        'INCLUDE',
        'LIB',
        'PATH',
    ]
    for var in required_vars:
      if not var in os.environ.keys():
        raise Exception('%s environment variable must be set' % var)

    # Windows custom toolchain requirements. See comments in gn_args.py.
    gn_args['visual_studio_path'] = os.environ['GYP_MSVS_OVERRIDE_PATH']
    gn_args['visual_studio_version'] = os.environ['GYP_MSVS_VERSION']
    gn_args['visual_studio_runtime_dirs'] = os.environ['VS_CRT_ROOT']
    gn_args['windows_sdk_path'] = os.environ['SDK_ROOT']

configs = GetAllPlatformConfigs(gn_args)
for dir, config in configs.items():
  # Create out directories and write the args.gn file.
  out_path = os.path.join(src_dir, 'out', dir)
  make_dir(out_path, False)
  args_gn_path = os.path.join(out_path, 'args.gn')
  args_gn_contents = GetConfigFileContents(config)
  write_file(args_gn_path, args_gn_contents)

  # Generate the Ninja config.
  cmd = ['gn', 'gen', os.path.join('out', dir)]
  if 'GN_ARGUMENTS' in os.environ.keys():
    cmd.extend(os.environ['GN_ARGUMENTS'].split(' '))
  RunAction(src_dir, cmd)
  if platform == 'windows':
    issue_1999.apply(out_path)

This (crudely) adds --regenerate argument to gclient_hook.py. (It is a derivation of 3282 branch file, so adapt accordingly if changed since 3282).

And then cef_create_projects.bat:
Code: Select all
@echo off
if [%1%] EQU [regenerate] goto l_regenerate
goto l_default

:l_default
python.bat tools\gclient_hook.py
goto l_end

:l_regenerate
python.bat tools\gclient_hook.py --regenerate
goto l_end

:l_end

This allows you to pass --regenerate to cef_create_projects.

Now you can run cef_create_projects --regenerate which will not clobber version and already patched files, and will just run gn gen for all platforms.

end:
Rename/delete out\Release_x86, rerun cef_create_projects.bat, then ninja -C out\Release_x86.

Hardcore
Edit manually environment.x86 (possibly also environment.winrt_x86) and fix inside the INCLUDE and LIB (possibly also PATH) the SDK path
Pitfall: environment files contains NUL characters. Programmer's Notepad, for example, knows to handle them correctly. I don't know about others.
Backup the files first to avoid editor surprises.

Then ninja -t clean to clean the files, and ninja -C to (re)build. This may or may not work, and is definitely not somehing to do first.


Thanks for the tip, however the only thing I have in out folder is a "cef.branch" file. I am still missing the gn.exe file, I searched the entire folder for it, but it doesn't exist anywhere! since it doesn't exist, the solution can't be created :cry:

At this moment I'd pay someone to get me a cef build with H264 codecs, I've tried it 6 times already, my HDD will die soon after all this writing/deleting.
djst3rios2
Techie
 
Posts: 18
Joined: Mon Jun 11, 2018 4:22 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 33 guests