diff --git a/.github/workflows/build-ffmpeg.yml b/.github/workflows/ci.yml similarity index 86% rename from .github/workflows/build-ffmpeg.yml rename to .github/workflows/ci.yml index 4568a566..0b82ef09 100644 --- a/.github/workflows/build-ffmpeg.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ --- -name: Build ffmpeg +name: CI on: pull_request: @@ -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 @@ -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 }} @@ -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 }} @@ -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::" diff --git a/.gitignore b/.gitignore index 81ec4ba5..4c59bc5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Distribution / packaging build/ +cmake-*/ # JetBrains project folder .idea/ diff --git a/.gitmodules b/.gitmodules index dbe2806c..9d1b313e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 45ea850c..f1aff566 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/README.md b/README.md index 953e5e89..3ea7ffb1 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) diff --git a/cmake/ffmpeg/_main.cmake b/cmake/ffmpeg/_main.cmake new file mode 100644 index 00000000..b48672e7 --- /dev/null +++ b/cmake/ffmpeg/_main.cmake @@ -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() diff --git a/cmake/ffmpeg/amf.cmake b/cmake/ffmpeg/amf.cmake new file mode 100644 index 00000000..f0bdb585 --- /dev/null +++ b/cmake/ffmpeg/amf.cmake @@ -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" +) diff --git a/cmake/ffmpeg_cbs.cmake b/cmake/ffmpeg/cbs.cmake similarity index 70% rename from cmake/ffmpeg_cbs.cmake rename to cmake/ffmpeg/cbs.cmake index 5276f5a2..39c2b5f8 100644 --- a/cmake/ffmpeg_cbs.cmake +++ b/cmake/ffmpeg/cbs.cmake @@ -1,54 +1,34 @@ -cmake_minimum_required(VERSION 3.2) +if(BUILD_FFMPEG_ALL_PATCHES OR BUILD_FFMPEG_CBS_PATCHES) + file(GLOB FFMPEG_CBS_PATCH_FILES ${CMAKE_CURRENT_SOURCE_DIR}/patches/FFmpeg/cbs/*.patch) -project(cbs - DESCRIPTION "FFmpeg code subset to expose coded bitstream (CBS) internal APIs for Sunshine" - VERSION 0.1) - -set(CMAKE_GENERATED_SRC_PATH ${CMAKE_BINARY_DIR}/generated-src) - -# Apply patches -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/apply_git_patch.cmake) -APPLY_GIT_PATCH(${CMAKE_SOURCE_DIR}/ffmpeg_sources/ffmpeg - ${CMAKE_SOURCE_DIR}/ffmpeg_patches/cbs/01-explicit-intmath.patch) -APPLY_GIT_PATCH(${CMAKE_SOURCE_DIR}/ffmpeg_sources/ffmpeg - ${CMAKE_SOURCE_DIR}/ffmpeg_patches/cbs/02-include-cbs-config.patch) -APPLY_GIT_PATCH(${CMAKE_SOURCE_DIR}/ffmpeg_sources/ffmpeg - ${CMAKE_SOURCE_DIR}/ffmpeg_patches/cbs/03-remove-register.patch) -APPLY_GIT_PATCH(${CMAKE_SOURCE_DIR}/ffmpeg_sources/ffmpeg - ${CMAKE_SOURCE_DIR}/ffmpeg_patches/cbs/04-size-specifier.patch) - -file(COPY ${CMAKE_SOURCE_DIR}/ffmpeg_sources/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) -set(CBS_INCLUDE_PATH ${CMAKE_BINARY_DIR}/include/cbs) - -message("Running FFmpeg configure to generate platform config") + foreach(patch_file ${FFMPEG_CBS_PATCH_FILES}) + APPLY_GIT_PATCH(${FFMPEG_GENERATED_SRC_PATH} ${patch_file}) + endforeach() +endif() -# Explicit shell otherwise Windows runs outside the mingw environment -if (WIN32) - set(LEADING_SH_COMMAND sh) -endif () +set(CBS_INCLUDE_PATH ${CMAKE_CURRENT_BINARY_DIR}/include/cbs) string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} arch) -if (${arch} STREQUAL "aarch64" OR ${arch} STREQUAL "arm64") +if(${arch} STREQUAL "aarch64" OR ${arch} STREQUAL "arm64") set(CBS_ARCH_PATH arm) elseif (${arch} STREQUAL "ppc64le") set(CBS_ARCH_PATH ppc) elseif (${arch} STREQUAL "amd64" OR ${arch} STREQUAL "x86_64") set(CBS_ARCH_PATH x86) -else () +elseif (${arch} STREQUAL "mips") + set(CBS_ARCH_PATH mips) +else() message(FATAL_ERROR "Unsupported system processor:" ${CMAKE_SYSTEM_PROCESSOR}) -endif () +endif() if (CMAKE_CROSSCOMPILING) set(FFMPEG_EXTRA_CONFIGURE --arch=${arch} --enable-cross-compile) endif () -# The generated config.h needs to have `CONFIG_CBS_` flags enabled (from `--enable-bsfs`) -execute_process( - COMMAND ${LEADING_SH_COMMAND} ./configure +add_custom_target(cbs_configure + # run `sed -i 's/PREFIX =/PREFIX ?=/g' Makefile` + COMMAND ${CMAKE_COMMAND} -E ./configure --cc=${CMAKE_C_COMPILER} --cxx=${CMAKE_CXX_COMPILER} --ar=${CMAKE_AR} @@ -59,13 +39,13 @@ execute_process( --disable-iconv --enable-avcodec --enable-avutil - --enable-bsfs + --enable-bsfs # ensure config.h will have CONFIG_CBS_ flags --enable-gpl --enable-static ${FFMPEG_EXTRA_CONFIGURE} WORKING_DIRECTORY ${FFMPEG_GENERATED_SRC_PATH} - COMMAND_ECHO STDOUT - COMMAND_ERROR_IS_FATAL ANY) +) +add_dependencies(${CMAKE_PROJECT_NAME} cbs_configure) # Headers needed to link for Sunshine configure_file(${AVCODEC_GENERATED_SRC_PATH}/av1.h ${CBS_INCLUDE_PATH}/av1.h COPYONLY) @@ -94,13 +74,13 @@ configure_file(${AVCODEC_GENERATED_SRC_PATH}/packet.h ${CBS_INCLUDE_PATH}/packet configure_file(${AVCODEC_GENERATED_SRC_PATH}/sei.h ${CBS_INCLUDE_PATH}/sei.h COPYONLY) configure_file(${AVCODEC_GENERATED_SRC_PATH}/version_major.h ${CBS_INCLUDE_PATH}/version_major.h COPYONLY) configure_file(${AVCODEC_GENERATED_SRC_PATH}/vlc.h ${CBS_INCLUDE_PATH}/vlc.h COPYONLY) -configure_file(${FFMPEG_GENERATED_SRC_PATH}/config.h ${CBS_INCLUDE_PATH}/config.h COPYONLY) +#configure_file(${FFMPEG_GENERATED_SRC_PATH}/config.h ${CBS_INCLUDE_PATH}/config.h COPYONLY) configure_file(${FFMPEG_GENERATED_SRC_PATH}/libavutil/attributes.h - ${CMAKE_BINARY_DIR}/include/libavutil/attributes.h COPYONLY) + ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/attributes.h COPYONLY) configure_file(${FFMPEG_GENERATED_SRC_PATH}/libavutil/attributes_internal.h - ${CMAKE_BINARY_DIR}/include/libavutil/attributes_internal.h COPYONLY) + ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/attributes_internal.h COPYONLY) configure_file(${FFMPEG_GENERATED_SRC_PATH}/libavutil/intmath.h - ${CMAKE_BINARY_DIR}/include/libavutil/intmath.h COPYONLY) + ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/intmath.h COPYONLY) set(CBS_SOURCE_FILES ${CBS_INCLUDE_PATH}/av1.h @@ -129,8 +109,8 @@ set(CBS_SOURCE_FILES ${CBS_INCLUDE_PATH}/sei.h ${CBS_INCLUDE_PATH}/version_major.h ${CBS_INCLUDE_PATH}/vlc.h - ${CMAKE_BINARY_DIR}/include/libavutil/intmath.h - ${CBS_INCLUDE_PATH}/config.h + ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/intmath.h + # ${CBS_INCLUDE_PATH}/config.h ${AVCODEC_GENERATED_SRC_PATH}/cbs.c ${AVCODEC_GENERATED_SRC_PATH}/cbs_h2645.c @@ -153,27 +133,29 @@ if (EXISTS ${AVCODEC_GENERATED_SRC_PATH}/${CBS_ARCH_PATH}/mathops.h) endif() if (EXISTS ${FFMPEG_GENERATED_SRC_PATH}/libavutil/${CBS_ARCH_PATH}/asm.h) configure_file(${FFMPEG_GENERATED_SRC_PATH}/libavutil/${CBS_ARCH_PATH}/asm.h - ${CMAKE_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/asm.h COPYONLY) - list(APPEND CBS_SOURCE_FILES ${CMAKE_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/asm.h) + ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/asm.h COPYONLY) + list(APPEND CBS_SOURCE_FILES ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/asm.h) endif() if (EXISTS ${FFMPEG_GENERATED_SRC_PATH}/libavutil/${CBS_ARCH_PATH}/intmath.h) configure_file(${FFMPEG_GENERATED_SRC_PATH}/libavutil/${CBS_ARCH_PATH}/intmath.h - ${CMAKE_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/intmath.h COPYONLY) - list(APPEND CBS_SOURCE_FILES ${CMAKE_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/intmath.h) + ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/intmath.h COPYONLY) + list(APPEND CBS_SOURCE_FILES ${CMAKE_CURRENT_BINARY_DIR}/include/libavutil/${CBS_ARCH_PATH}/intmath.h) endif() include_directories( - ${CMAKE_BINARY_DIR}/include + ${CMAKE_CURRENT_BINARY_DIR}/include ${FFMPEG_GENERATED_SRC_PATH}) add_library(cbs ${CBS_SOURCE_FILES}) target_compile_options(cbs PRIVATE -Wall -Wno-incompatible-pointer-types -Wno-format -Wno-format-extra-args) +add_dependencies(cbs cbs_configure) +add_dependencies(${CMAKE_PROJECT_NAME} cbs) -install(DIRECTORY ${CMAKE_BINARY_DIR}/include +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX}) -install(FILES ${CMAKE_BINARY_DIR}/libcbs.a +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcbs.a DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libcbs.pc.in - ${CMAKE_BINARY_DIR}/libcbs.pc @ONLY) -install(FILES ${CMAKE_BINARY_DIR}/libcbs.pc + ${CMAKE_CURRENT_BINARY_DIR}/libcbs.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcbs.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) diff --git a/cmake/ffmpeg/nv_codec_headers.cmake b/cmake/ffmpeg/nv_codec_headers.cmake new file mode 100644 index 00000000..7398cd7c --- /dev/null +++ b/cmake/ffmpeg/nv_codec_headers.cmake @@ -0,0 +1,20 @@ +if(BUILD_FFMPEG_ALL_PATCHES OR BUILD_FFMPEG_NV_CODEC_HEADERS_PATCHES) + file(GLOB FFMPEG_NV_CODEC_HEADER_PATCH_FILES ${CMAKE_CURRENT_SOURCE_DIR}/patches/FFmpeg/nv-codec-headers/*.patch) + + foreach(patch_file ${FFMPEG_NV_CODEC_HEADER_PATCH_FILES}) + APPLY_GIT_PATCH(${FFMPEG_GENERATED_SRC_PATH} ${patch_file}) + endforeach() +endif() + +# copy the source since we will patch the Makefile +file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/third-party/FFmpeg/nv-codec-headers" + DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + +add_custom_target(nv_codec_headers + # run `sed -i 's/PREFIX =/PREFIX ?=/g' Makefile` + COMMAND ${CMAKE_COMMAND} -E "sed -i 's/PREFIX =/PREFIX ?=/g' Makefile" + COMMAND ${CMAKE_COMMAND} -E PREFIX=${CMAKE_CURRENT_BINARY_DIR} make + COMMAND ${CMAKE_COMMAND} -E PREFIX=${CMAKE_CURRENT_BINARY_DIR} make install + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/nv-codec-headers +) +add_dependencies(${CMAKE_PROJECT_NAME} nv_codec_headers) diff --git a/cmake/ffmpeg/svt_av1.cmake b/cmake/ffmpeg/svt_av1.cmake new file mode 100644 index 00000000..dd072319 --- /dev/null +++ b/cmake/ffmpeg/svt_av1.cmake @@ -0,0 +1,17 @@ +if(BUILD_FFMPEG_ALL_PATCHES OR BUILD_FFMPEG_SVT_AV1_PATCHES) + file(GLOB FFMPEG_SVT_AV1_PATCH_FILES ${CMAKE_CURRENT_SOURCE_DIR}/patches/FFmpeg/SVT-AV1/*.patch) + + foreach(patch_file ${FFMPEG_SVT_AV1_PATCH_FILES}) + APPLY_GIT_PATCH(${FFMPEG_GENERATED_SRC_PATH} ${patch_file}) + endforeach() +endif() + +# options for SVT-AV1 +set(BUILD_APPS OFF CACHE BOOL "Build applications") +set(BUILD_DEC OFF CACHE BOOL "Build decoders") +set(ENABLE_AVX512 ON CACHE BOOL "Enable AVX512") +set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries") + +# build SVT-AV1 +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third-party/FFmpeg/SVT-AV1 SVT-AV1 SYSTEM) +add_dependencies(${CMAKE_PROJECT_NAME} SvtAv1Enc) diff --git a/cmake/ffmpeg/vaapi.cmake b/cmake/ffmpeg/vaapi.cmake new file mode 100644 index 00000000..5232ad54 --- /dev/null +++ b/cmake/ffmpeg/vaapi.cmake @@ -0,0 +1,7 @@ +if(BUILD_FFMPEG_ALL_PATCHES OR BUILD_FFMPEG_VAAPI_PATCHES) + file(GLOB FFMPEG_VAAPI_FILES ${CMAKE_CURRENT_SOURCE_DIR}/patches/FFmpeg/VAAPI/*.patch) + + foreach(patch_file ${FFMPEG_VAAPI_FILES}) + APPLY_GIT_PATCH(${FFMPEG_GENERATED_SRC_PATH} ${patch_file}) + endforeach() +endif() diff --git a/cmake/ffmpeg/x264.cmake b/cmake/ffmpeg/x264.cmake new file mode 100644 index 00000000..00cdbba9 --- /dev/null +++ b/cmake/ffmpeg/x264.cmake @@ -0,0 +1,7 @@ +if(BUILD_FFMPEG_ALL_PATCHES OR BUILD_FFMPEG_X264_PATCHES) + file(GLOB FFMPEG_X264_FILES ${CMAKE_CURRENT_SOURCE_DIR}/patches/FFmpeg/x264/*.patch) + + foreach(patch_file ${FFMPEG_SVT_X264_FILES}) + APPLY_GIT_PATCH(${FFMPEG_GENERATED_SRC_PATH} ${patch_file}) + endforeach() +endif() diff --git a/cmake/ffmpeg/x265.cmake b/cmake/ffmpeg/x265.cmake new file mode 100644 index 00000000..9e30290c --- /dev/null +++ b/cmake/ffmpeg/x265.cmake @@ -0,0 +1,7 @@ +if(BUILD_FFMPEG_ALL_PATCHES OR BUILD_FFMPEG_X265_PATCHES) + file(GLOB FFMPEG_X265_FILES ${CMAKE_CURRENT_SOURCE_DIR}/patches/FFmpeg/x265/*.patch) + + foreach(patch_file ${FFMPEG_SVT_X265_FILES}) + APPLY_GIT_PATCH(${FFMPEG_GENERATED_SRC_PATH} ${patch_file}) + endforeach() +endif() diff --git a/cmake/toolchain/aarch64-linux/crosscompile.cmake b/cmake/toolchains/aarch64-linux/crosscompile.cmake similarity index 100% rename from cmake/toolchain/aarch64-linux/crosscompile.cmake rename to cmake/toolchains/aarch64-linux/crosscompile.cmake diff --git a/cmake/toolchain/aarch64-macos/crosscompile.cmake b/cmake/toolchains/aarch64-macos/crosscompile.cmake similarity index 100% rename from cmake/toolchain/aarch64-macos/crosscompile.cmake rename to cmake/toolchains/aarch64-macos/crosscompile.cmake diff --git a/cmake/toolchain/powerpc64le-linux/crosscompile.cmake b/cmake/toolchains/powerpc64le-linux/crosscompile.cmake similarity index 100% rename from cmake/toolchain/powerpc64le-linux/crosscompile.cmake rename to cmake/toolchains/powerpc64le-linux/crosscompile.cmake diff --git a/ffmpeg_patches/ffmpeg/01-amf-colorspace.patch b/patches/FFmpeg/AMF/01-amf-colorspace.patch similarity index 100% rename from ffmpeg_patches/ffmpeg/01-amf-colorspace.patch rename to patches/FFmpeg/AMF/01-amf-colorspace.patch diff --git a/ffmpeg_patches/ffmpeg/02-idr-on-amf.patch b/patches/FFmpeg/AMF/02-idr-on-amf.patch similarity index 100% rename from ffmpeg_patches/ffmpeg/02-idr-on-amf.patch rename to patches/FFmpeg/AMF/02-idr-on-amf.patch diff --git a/ffmpeg_patches/ffmpeg/03-amfenc-disable-buffering.patch b/patches/FFmpeg/AMF/03-amfenc-disable-buffering.patch similarity index 100% rename from ffmpeg_patches/ffmpeg/03-amfenc-disable-buffering.patch rename to patches/FFmpeg/AMF/03-amfenc-disable-buffering.patch diff --git a/ffmpeg_patches/ffmpeg/06-amfenc-query-timeout.patch b/patches/FFmpeg/AMF/04-amfenc-query-timeout.patch similarity index 100% rename from ffmpeg_patches/ffmpeg/06-amfenc-query-timeout.patch rename to patches/FFmpeg/AMF/04-amfenc-query-timeout.patch diff --git a/patches/FFmpeg/SVT-AV1/.keep b/patches/FFmpeg/SVT-AV1/.keep new file mode 100644 index 00000000..e69de29b diff --git a/ffmpeg_patches/ffmpeg/05-vaapi-customized-surface-alignment.patch b/patches/FFmpeg/VAAPI/01-vaapi-customized-surface-alignment.patch similarity index 100% rename from ffmpeg_patches/ffmpeg/05-vaapi-customized-surface-alignment.patch rename to patches/FFmpeg/VAAPI/01-vaapi-customized-surface-alignment.patch diff --git a/ffmpeg_patches/ffmpeg/07-vaapi-leak.patch b/patches/FFmpeg/VAAPI/02-vaapi-leak.patch similarity index 100% rename from ffmpeg_patches/ffmpeg/07-vaapi-leak.patch rename to patches/FFmpeg/VAAPI/02-vaapi-leak.patch diff --git a/ffmpeg_patches/cbs/01-explicit-intmath.patch b/patches/FFmpeg/cbs/01-explicit-intmath.patch similarity index 100% rename from ffmpeg_patches/cbs/01-explicit-intmath.patch rename to patches/FFmpeg/cbs/01-explicit-intmath.patch diff --git a/ffmpeg_patches/cbs/02-include-cbs-config.patch b/patches/FFmpeg/cbs/02-include-cbs-config.patch similarity index 100% rename from ffmpeg_patches/cbs/02-include-cbs-config.patch rename to patches/FFmpeg/cbs/02-include-cbs-config.patch diff --git a/ffmpeg_patches/cbs/03-remove-register.patch b/patches/FFmpeg/cbs/03-remove-register.patch similarity index 100% rename from ffmpeg_patches/cbs/03-remove-register.patch rename to patches/FFmpeg/cbs/03-remove-register.patch diff --git a/ffmpeg_patches/cbs/04-size-specifier.patch b/patches/FFmpeg/cbs/04-size-specifier.patch similarity index 100% rename from ffmpeg_patches/cbs/04-size-specifier.patch rename to patches/FFmpeg/cbs/04-size-specifier.patch diff --git a/ffmpeg_patches/ffmpeg/04-mfenc-lowlatency.patch b/patches/FFmpeg/misc/01-mfenc-lowlatency.patch similarity index 100% rename from ffmpeg_patches/ffmpeg/04-mfenc-lowlatency.patch rename to patches/FFmpeg/misc/01-mfenc-lowlatency.patch diff --git a/patches/FFmpeg/nv-codec-headers/.keep b/patches/FFmpeg/nv-codec-headers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/patches/FFmpeg/x264/.keep b/patches/FFmpeg/x264/.keep new file mode 100644 index 00000000..e69de29b diff --git a/patches/FFmpeg/x265/.keep b/patches/FFmpeg/x265/.keep new file mode 100644 index 00000000..e69de29b diff --git a/ffmpeg_sources/AMF b/third-party/FFmpeg/AMF similarity index 100% rename from ffmpeg_sources/AMF rename to third-party/FFmpeg/AMF diff --git a/ffmpeg_sources/ffmpeg b/third-party/FFmpeg/FFmpeg similarity index 100% rename from ffmpeg_sources/ffmpeg rename to third-party/FFmpeg/FFmpeg diff --git a/ffmpeg_sources/SVT-AV1 b/third-party/FFmpeg/SVT-AV1 similarity index 100% rename from ffmpeg_sources/SVT-AV1 rename to third-party/FFmpeg/SVT-AV1 diff --git a/ffmpeg_sources/nv-codec-headers b/third-party/FFmpeg/nv-codec-headers similarity index 100% rename from ffmpeg_sources/nv-codec-headers rename to third-party/FFmpeg/nv-codec-headers diff --git a/ffmpeg_sources/x264 b/third-party/FFmpeg/x264 similarity index 100% rename from ffmpeg_sources/x264 rename to third-party/FFmpeg/x264 diff --git a/ffmpeg_sources/x265_git b/third-party/FFmpeg/x265_git similarity index 100% rename from ffmpeg_sources/x265_git rename to third-party/FFmpeg/x265_git