Skip to content

Commit

Permalink
feat(build): make this a fullblown cmake project
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Oct 23, 2024
1 parent 0170afd commit 8840701
Show file tree
Hide file tree
Showing 42 changed files with 429 additions and 258 deletions.
150 changes: 5 additions & 145 deletions .github/workflows/build-ffmpeg.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Build ffmpeg
name: CI

on:
pull_request:
Expand All @@ -17,8 +17,8 @@ env:
MACOSX_DEPLOYMENT_TARGET: 13.0

jobs:
ffmpeg:
name: ffmpeg (${{ matrix.name }})
build:
name: Build (${{ matrix.name }})
# https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
# https://trac.ffmpeg.org/wiki/CompilationGuide/macOS
# https://trac.ffmpeg.org/wiki/CompilationGuide/MinGW
Expand Down Expand Up @@ -302,156 +302,16 @@ jobs:
echo "root_path=$PWD" >> $GITHUB_OUTPUT
mkdir -p ./bin ./ffmpeg_build ./ffmpeg_sources
- name: patch
working-directory: ffmpeg_sources/ffmpeg
run: |
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/01-amf-colorspace.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/02-idr-on-amf.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/03-amfenc-disable-buffering.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/04-mfenc-lowlatency.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/05-vaapi-customized-surface-alignment.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/06-amfenc-query-timeout.patch
git apply -v --ignore-whitespace ../../ffmpeg_patches/ffmpeg/07-vaapi-leak.patch
- name: Setup cross compilation
id: cross
if: ${{ matrix.arch != 'x86_64' }}
run: |
TOOLCHAIN_DIR=${{ steps.root.outputs.root_path }}/cmake/toolchain/${{ matrix.arch }}-${{ matrix.os_type }}
TOOLCHAIN_DIR=${{ steps.root.outputs.root_path }}/cmake/toolchains/${{ matrix.arch }}-${{ matrix.os_type }}
echo "CMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_DIR/crosscompile.cmake" >> $GITHUB_OUTPUT
if [[ ${{ matrix.os_type }} == 'linux' ]]; then
echo "CCPREFIX=/usr/bin/${{ matrix.host }}-" >> $GITHUB_OUTPUT
fi
- name: amf
if: ${{ matrix.os_type != 'macos' }}
# https://ffmpeg.org/general.html#AMD-AMF_002fVCE
run: |
mkdir -p ./ffmpeg_build/include/AMF
cp -av "./ffmpeg_sources/AMF/amf/public/include/." "./ffmpeg_build/include/AMF"
- name: av1
working-directory: ffmpeg_sources/SVT-AV1/Build
env:
root_path: ${{ steps.root.outputs.root_path }}
CCPREFIX: ${{ steps.cross.outputs.CCPREFIX }}
run: |
echo "::group::configure"
PATH="$root_path/bin:$PATH" cmake -G "${{ matrix.cmake_generator }}" \
-DCMAKE_TOOLCHAIN_FILE=${{ steps.cross.outputs.CMAKE_TOOLCHAIN_FILE }} \
-DCMAKE_INSTALL_PREFIX="$root_path/ffmpeg_build" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_APPS=OFF \
-DBUILD_DEC=OFF \
-DENABLE_AVX512=ON \
-DBUILD_SHARED_LIBS=OFF \
..
echo "::endgroup::"
echo "::group::make"
PATH="$root_path/bin:$PATH" make -j$(nproc || sysctl -n hw.logicalcpu)
echo "::endgroup::"
echo "::group::make install"
make install
echo "::endgroup::"
- name: libx264
env:
root_path: ${{ steps.root.outputs.root_path }}
CCPREFIX: ${{ steps.cross.outputs.CCPREFIX }}
working-directory: ffmpeg_sources/x264
run: |
echo "::group::configure options"
./configure --help || true # this command has a non zero exit status, but we should continue anyway
echo "::endgroup::"
echo "::group::configure extra flags for cross compilation"
extra_configure=""
if [[ ${{ matrix.os_type }} == "linux" && ${{ matrix.arch }} != "x86_64" ]]; then
extra_configure=$(cat <<- VAREOF
--host=${{ matrix.arch }}-${{ matrix.os_type }}
--cross-prefix=${CCPREFIX}
VAREOF
)
fi
echo "$extra_configure"
echo "::endgroup::"
echo "::group::configure"
PATH="$root_path/bin:$PATH" \
PKG_CONFIG_PATH="$root_path/ffmpeg_build/lib/pkgconfig" \
./configure \
$extra_configure \
--prefix="$root_path/ffmpeg_build" \
--bindir="$root_path/bin" \
--disable-cli \
--enable-static
echo "::endgroup::"
echo "::group::make"
PATH="$root_path/bin:$PATH" make -j$(nproc || sysctl -n hw.logicalcpu)
echo "::endgroup::"
echo "::group::make install"
make install
echo "::endgroup::"
- name: libx265
env:
root_path: ${{ steps.root.outputs.root_path }}
CCPREFIX: ${{ steps.cross.outputs.CCPREFIX }}
working-directory: ffmpeg_sources/x265_git
run: |
echo "::group::configure extra flags for cross compilation"
extra_configure=""
if [[ ${{ matrix.arch }} == "x86_64" ]]; then
# not currently supported in `aarch64`
extra_configure="-DENABLE_HDR10_PLUS=1"
fi
echo "$extra_configure"
echo "::endgroup::"
echo "::group::configure"
PATH="$root_path/bin:$PATH" cmake -G "${{ matrix.cmake_generator }}" \
$extra_configure \
-DCMAKE_TOOLCHAIN_FILE=${{ steps.cross.outputs.CMAKE_TOOLCHAIN_FILE }} \
-DCMAKE_INSTALL_PREFIX="$root_path/ffmpeg_build" \
-DENABLE_CLI=OFF \
-DENABLE_SHARED=OFF \
-DSTATIC_LINK_CRT=ON \
./source
echo "::endgroup::"
echo "::group::make"
PATH="$root_path/bin:$PATH" make -j$(nproc || sysctl -n hw.logicalcpu)
echo "::endgroup::"
echo "::group::make install"
make install
echo "::endgroup::"
- name: nvenc
id: nvenc
if: ${{ matrix.os_type != 'macos' }}
env:
root_path: ${{ steps.root.outputs.root_path }}
working-directory: ffmpeg_sources/nv-codec-headers
# https://trac.ffmpeg.org/wiki/HWAccelIntro#NVENC
run: |
echo "::group::patch Makefile"
# allow `PREFIX` to be overridden
sed -i 's/PREFIX =/PREFIX ?=/g' Makefile
echo "::endgroup::"
echo "::group::make"
PREFIX=$root_path/ffmpeg_build make -j$(nproc || sysctl -n hw.logicalcpu)
echo "::endgroup::"
echo "::group::make install"
PREFIX=$root_path/ffmpeg_build make install
echo "::endgroup::"
- name: ffmpeg
env:
root_path: ${{ steps.root.outputs.root_path }}
Expand Down Expand Up @@ -551,7 +411,7 @@ jobs:
PATH="$root_path/bin:$PATH" cmake -G "${{ matrix.cmake_generator }}" \
-DCMAKE_TOOLCHAIN_FILE=${{ steps.cross.outputs.CMAKE_TOOLCHAIN_FILE }} \
-DCMAKE_INSTALL_PREFIX="$root_path/ffmpeg_build" \
-DFFMPEG_CBS=ON \
-DBUILD_FFMPEG_CBS=ON \
..
echo "::endgroup::"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Distribution / packaging
build/
cmake-*/

# JetBrains project folder
.idea/
Expand Down
30 changes: 15 additions & 15 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[submodule "ffmpeg_sources/AMF"]
path = ffmpeg_sources/AMF
url = https://github.com/GPUOpen-LibrariesAndSDKs/AMF
[submodule "third-party/FFmpeg/AMF"]
path = third-party/FFmpeg/AMF
url = https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git
branch = master
[submodule "ffmpeg_sources/x264"]
path = ffmpeg_sources/x264
[submodule "third-party/FFmpeg/x264"]
path = third-party/FFmpeg/x264
url = https://code.videolan.org/videolan/x264.git
branch = stable
[submodule "ffmpeg_sources/x265_git"]
path = ffmpeg_sources/x265_git
[submodule "third-party/FFmpeg/x265_git"]
path = third-party/FFmpeg/x265_git
url = https://bitbucket.org/multicoreware/x265_git.git
branch = Release_3.5
[submodule "ffmpeg_sources/nv-codec-headers"]
path = ffmpeg_sources/nv-codec-headers
url = https://github.com/FFmpeg/nv-codec-headers
[submodule "third-party/FFmpeg/nv-codec-headers"]
path = third-party/FFmpeg/nv-codec-headers
url = https://github.com/FFmpeg/nv-codec-headers.git
branch = sdk/12.0
[submodule "ffmpeg_sources/ffmpeg"]
path = ffmpeg_sources/ffmpeg
url = https://github.com/FFmpeg/FFmpeg
[submodule "third-party/FFmpeg/FFmpeg"]
path = third-party/FFmpeg/FFmpeg
url = https://github.com/FFmpeg/FFmpeg.git
branch = release/7.1
[submodule "ffmpeg_sources/SVT-AV1"]
path = ffmpeg_sources/SVT-AV1
[submodule "third-party/FFmpeg/SVT-AV1"]
path = third-party/FFmpeg/SVT-AV1
url = https://gitlab.com/AOMediaCodec/SVT-AV1.git
branch = v1.6.0
65 changes: 60 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,65 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.25)

project(build-deps
DESCRIPTION "Pre-build dependencies for LizardByte projects")
DESCRIPTION "Pre-build dependencies for LizardByte projects.")

option(FFMPEG_CBS "Enable CBS library configuration" ON)
option(BUILD_ALL "Build all dependencies" ON)
option(BUILD_ALL_SUNSHINE "Build all Sunshine dependencies" ON)

if(FFMPEG_CBS)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg_cbs.cmake)
# The shell command and prefix to use for running extra commands.
if(NOT DEFINED SHELL_CMD)
if(WIN32)
set(SHELL_CMD "C:\\msys64\\usr\\bin\\bash.exe" CACHE STRING "Shell to use" FORCE)
else()
set(SHELL_CMD "bash" CACHE STRING "Shell to use" FORCE)
endif()
endif()
if(NOT DEFINED SHELL_CMD_PREFIX)
if(WIN32)
set(SHELL_CMD_PREFIX -l -c CACHE STRING "Shell command prefix" FORCE)
set(MSYSTEM "UCRT64" CACHE STRING "MSYSTEM to use" FORCE)
set(ENV{MSYSTEM} ${MSYSTEM})
else()
set(SHELL_CMD_PREFIX -c CACHE STRING "Shell command prefix" FORCE)
endif()
endif()
message(STATUS "Using shell command: ${SHELL_CMD}")
message(STATUS "Using shell command prefix: ${SHELL_CMD_PREFIX}")

# FFmpeg
option(BUILD_FFMPEG "Build FFmpeg" ON)
option(BUILD_FFMPEG_ALL_PATCHES "Apply FFmpeg patches" ON)
option(BUILD_FFMPEG_AMF "Build FFmpeg AMF" ON)
option(BUILD_FFMPEG_AMF_PATCHES "Apply FFmpeg AMF patches" ON)
option(BUILD_FFMPEG_CBS "Build FFmpeg CBS" ON)
option(BUILD_FFMPEG_CBS_PATCHES "Apply FFmpeg CBS patches" ON)
option(BUILD_FFMPEG_MF "Build FFmpeg Media Foundation" ON)
option(BUILD_FFMPEG_MF_PATCHES "Apply FFmpeg Media Foundation patches" ON)
option(BUILD_FFMPEG_NV_CODEC_HEADERS "Build FFmpeg NV Codec Headers" ON)
option(BUILD_FFMPEG_NV_CODEC_HEADERS_PATCHES "Apply FFmpeg NV Codec Headers patches" ON)
option(BUILD_FFMPEG_SVT_AV1 "Build FFmpeg SVT-AV1" ON)
option(BUILD_FFMPEG_SVT_AV1_PATCHES "Apply FFmpeg SVT-AV1 patches" ON)
option(BUILD_FFMPEG_VAAPI "Build FFmpeg with VAAPI support" ON)
option(BUILD_FFMPEG_VAAPI_PATCHES "Apply FFmpeg VAAPI patches" ON)
option(BUILD_FFMPEG_X264 "Build FFmpeg x264" ON)
option(BUILD_FFMPEG_X264_PATCHES "Apply FFmpeg x264 patches" ON)
option(BUILD_FFMPEG_X265 "Build FFmpeg x265" ON)
option(BUILD_FFMPEG_X265_PATCHES "Apply FFmpeg x265 patches" ON)

add_custom_target(${CMAKE_PROJECT_NAME}
COMMENT "Completed build-deps"
)

# set architecture
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} arch)

# set generated source path
set(CMAKE_GENERATED_SRC_PATH ${CMAKE_CURRENT_BINARY_DIR}/generated-src)

# common includes
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/apply_git_patch.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/unix_path.cmake)

if(BUILD_ALL OR BUILD_ALL_SUNSHINE OR BUILD_FFMPEG)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/_main.cmake)
endif()
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GitHub Workflow Status (FFmpeg)](https://img.shields.io/github/actions/workflow/status/lizardbyte/build-deps/build-ffmpeg.yml.svg?branch=master&label=ffmpeg%20build&logo=github&style=for-the-badge)](https://github.com/LizardByte/build-deps/actions/workflows/build-ffmpeg.yml?query=branch%3Amaster)

This is a common set of pre-compiled dependencies for LizardByte/Sunshine.
This is a common set of pre-compiled dependencies for [LizardByte/Sunshine](https://github.com/LizardByte/Sunshine).

- [FFmpeg](https://ffmpeg.org)

Expand All @@ -19,7 +19,6 @@ This is a common set of pre-compiled dependencies for LizardByte/Sunshine.

## Plans

- [ ] Convert to a cmake project
- [ ] Add more dependencies
- [ ] boost
- [ ] cuda (developer toolkit)
Expand All @@ -29,3 +28,15 @@ This is a common set of pre-compiled dependencies for LizardByte/Sunshine.

This repo is licensed under the MIT License, but this does not cover submodules or patches.
Please see the individual projects for their respective licenses.


## Build

On Windows, you must copy the `.gitattributes` file to `.git/modules/third-party/FFmpeg/x264/info/attributes`,
see https://stackoverflow.com/a/23671157/11214013 for more info.

Then
```bash
cd third-party/FFmpeg/x264
git checkout HEAD -- .
```
2 changes: 2 additions & 0 deletions attributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# unix line endings
* text eol=lf
45 changes: 45 additions & 0 deletions cmake/ffmpeg/_main.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third-party/FFmpeg/FFmpeg DESTINATION ${CMAKE_GENERATED_SRC_PATH})

set(FFMPEG_GENERATED_SRC_PATH ${CMAKE_GENERATED_SRC_PATH}/FFmpeg)
set(AVCODEC_GENERATED_SRC_PATH ${CMAKE_GENERATED_SRC_PATH}/FFmpeg/libavcodec)

# TODO: install these files
set(FFMPEG_HEADER_DIRECTORIES "")
set(FFMPEG_HEADER_FILES "")
set(FFMPEG_STATIC_LIBRARIES "")

if(APPLE)
set(BUILD_FFMPEG_AMF OFF)
endif()

if(BUILD_FFMPEG_AMF)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/amf.cmake)
endif()

if(BUILD_FFMPEG_MF)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/mf.cmake)
endif()

if(BUILD_FFMPEG_NV_CODEC_HEADERS)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/nv_codec_headers.cmake)
endif()

if(BUILD_FFMPEG_SVT_AV1)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/svt_av1.cmake)
endif()

if(BUILD_FFMPEG_VAAPI)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/vaapi.cmake)
endif()

if(BUILD_FFMPEG_X264)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/x264.cmake)
endif()

if(BUILD_FFMPEG_X265)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/x265.cmake)
endif()

if(BUILD_FFMPEG_CBS)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/cbs.cmake)
endif()
Loading

0 comments on commit 8840701

Please sign in to comment.