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 20, 2024
1 parent 0170afd commit 1834e9b
Show file tree
Hide file tree
Showing 37 changed files with 200 additions and 144 deletions.
75 changes: 5 additions & 70 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,60 +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 }}
Expand Down Expand Up @@ -431,27 +387,6 @@ jobs:
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 +486,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
41 changes: 37 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
cmake_minimum_required(VERSION 3.2)

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)
# 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_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})

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

# Explicit shell otherwise Windows runs outside the mingw environment
# TODO: is this true when using `${CMAKE_COMMAND} -E`?
if(WIN32)
set(SHELL_COMMAND sh)
endif()

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

if(BUILD_ALL OR BUILD_ALL_SUNSHINE OR BUILD_FFMPEG)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/_main.cmake)
endif()
3 changes: 1 addition & 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 Down
34 changes: 34 additions & 0 deletions cmake/ffmpeg/_main.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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)

if(NOT APPLE)
if(BUILD_FFMPEG_AMF)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ffmpeg/amf.cmake)
endif()
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()
14 changes: 14 additions & 0 deletions cmake/ffmpeg/amf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if(BUILD_FFMPEG_ALL_PATCHES OR BUILD_FFMPEG_AMF_PATCHES)
file(GLOB FFMPEG_AMF_PATCH_FILES ${CMAKE_CURRENT_SOURCE_DIR}/patches/FFmpeg/AMF/*.patch)

foreach(patch_file ${FFMPEG_AMF_PATCH_FILES})
APPLY_GIT_PATCH(${FFMPEG_GENERATED_SRC_PATH} ${patch_file})
endforeach()
endif()

add_custom_target(amf ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/third-party/FFmpeg/AMF/amf/public/include"
"${CMAKE_GENERATED_SRC_PATH}/include/AMF"
COMMENT "Copying AMF headers"
)
Loading

0 comments on commit 1834e9b

Please sign in to comment.