From 8687d7d1753a8317b4a34bcfb7d332c5ef00ea0a Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Wed, 8 Jan 2025 00:00:00 +0000 Subject: [PATCH] build(cmake): reorganize CMakeLists.txt and make it compatible with Ninja Signed-off-by: k4yt3x --- .justfile | 235 +++++++++ CMakeLists.txt | 705 +++++++++++++------------- Makefile | 225 -------- third_party/librealcugan_ncnn_vulkan | 2 +- third_party/librealesrgan_ncnn_vulkan | 2 +- third_party/librife_ncnn_vulkan | 2 +- 6 files changed, 598 insertions(+), 573 deletions(-) create mode 100644 .justfile delete mode 100644 Makefile diff --git a/.justfile b/.justfile new file mode 100644 index 0000000..393e9d9 --- /dev/null +++ b/.justfile @@ -0,0 +1,235 @@ +BINDIR := "build" +CXX := "clang++" +TEST_VIDEO := "data/standard-test.mp4" +TEST_OUTPUT := "data/output.mp4" + +build: + cmake -G Ninja -S . -B {{BINDIR}} \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_COMPILER={{CXX}} \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX={{BINDIR}}/video2x-install \ + -DVIDEO2X_ENABLE_NATIVE=ON + cmake --build {{BINDIR}} --config Release --parallel --target install + cp {{BINDIR}}/compile_commands.json . + +static: + cmake -G Ninja -S . -B {{BINDIR}} \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_COMPILER={{CXX}} \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX={{BINDIR}}/video2x-install \ + -DBUILD_SHARED_LIBS=OFF \ + -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ + -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ + -DVIDEO2X_USE_EXTERNAL_BOOST=OFF + cmake --build {{BINDIR}} --config Release --parallel --target install + cp {{BINDIR}}/compile_commands.json . + +debug: + cmake -G Ninja -S . -B {{BINDIR}} \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_COMPILER={{CXX}} \ + -DCMAKE_BUILD_TYPE=Debug + cmake --build {{BINDIR}} --config Debug --parallel + cp {{BINDIR}}/compile_commands.json . + +windows: + cmake -S . -B {{BINDIR}} \ + -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ + -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ + -DVIDEO2X_USE_EXTERNAL_BOOST=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX={{BINDIR}}/video2x-install + cmake --build {{BINDIR}} --config Release --parallel --target install + +windows-debug: + cmake -S . -B {{BINDIR}} \ + -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ + -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ + -DVIDEO2X_USE_EXTERNAL_BOOST=OFF \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_INSTALL_PREFIX={{BINDIR}}/video2x-install + cmake --build {{BINDIR}} --config Debug --parallel + +debian: + apt-get update + apt-get install -y --no-install-recommends \ + build-essential cmake clang pkg-config ninja-build \ + libavcodec-dev \ + libavdevice-dev \ + libavfilter-dev \ + libavformat-dev \ + libavutil-dev \ + libswscale-dev \ + libvulkan-dev \ + glslang-tools \ + libomp-dev \ + libspdlog-dev \ + libboost-program-options-dev + cmake -G Ninja -B /tmp/build -S . \ + -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ + -DCMAKE_CXX_COMPILER={{CXX}} \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/tmp/install \ + -DINSTALL_BIN_DESTINATION=. \ + -DINSTALL_INCLUDE_DESTINATION=include \ + -DINSTALL_LIB_DESTINATION=. \ + -DINSTALL_MODEL_DESTINATION=. + cmake --build /tmp/build --config Release --target install --parallel + +ubuntu2404: + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential cmake pkg-config ninja-build \ + libavcodec-dev \ + libavdevice-dev \ + libavfilter-dev \ + libavformat-dev \ + libavutil-dev \ + libswscale-dev \ + libvulkan-dev \ + glslang-tools \ + libomp-dev \ + libboost-program-options-dev + cmake -G Ninja -B build -S . \ + -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ + -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ + -DCMAKE_CXX_COMPILER=g++ \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=video2x-linux-ubuntu-amd64/usr + cmake --build build --config Release --target install --parallel + mkdir -p video2x-linux-ubuntu-amd64/DEBIAN + cp packaging/debian/control.ubuntu2404 video2x-linux-ubuntu-amd64/DEBIAN/control + dpkg-deb --build video2x-linux-ubuntu-amd64 + +ubuntu2204: + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common + add-apt-repository -y ppa:ubuntuhandbook1/ffmpeg7 + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential cmake ninja-build \ + libavcodec-dev \ + libavdevice-dev \ + libavfilter-dev \ + libavformat-dev \ + libavutil-dev \ + libswscale-dev \ + libvulkan-dev \ + glslang-tools \ + libomp-dev \ + libboost-program-options-dev + cmake -G Ninja -B build -S . \ + -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ + -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ + -DCMAKE_CXX_COMPILER=g++ \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=video2x-linux-ubuntu-amd64/usr + cmake --build build --config Release --target install --parallel + mkdir -p video2x-linux-ubuntu-amd64/DEBIAN + cp packaging/debian/control.ubuntu2204 video2x-linux-ubuntu-amd64/DEBIAN/control + dpkg-deb --build video2x-linux-ubuntu-amd64 + +clean: + rm -vrf {{BINDIR}} data/output*.* heaptrack*.zst valgrind.log + +test-realesrgan: + LD_LIBRARY_PATH={{BINDIR}} {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p realesrgan -s 4 --realesrgan-model realesr-animevideov3 + +test-realcugan: + LD_LIBRARY_PATH={{BINDIR}} {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p realcugan -s 4 -n 0 --realcugan-model models-se + +test-libplacebo: + LD_LIBRARY_PATH={{BINDIR}} {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p libplacebo -w 1920 -h 1080 --libplacebo-shader anime4k-v4-a + +test-rife: + LD_LIBRARY_PATH={{BINDIR}} {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p rife -m 4 --rife-model rife-v4.6 + +memcheck-realesrgan: + LD_LIBRARY_PATH={{BINDIR}} valgrind \ + --tool=memcheck \ + --leak-check=full \ + --show-leak-kinds=all \ + --track-origins=yes \ + --show-reachable=yes \ + --verbose --log-file="valgrind.log" \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p realesrgan -s 2 --realesrgan-model realesr-animevideov3 \ + -e preset=veryfast -e crf=30 + +memcheck-realcugan: + LD_LIBRARY_PATH={{BINDIR}} valgrind \ + --tool=memcheck \ + --leak-check=full \ + --show-leak-kinds=all \ + --track-origins=yes \ + --show-reachable=yes \ + --verbose --log-file="valgrind.log" \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p realcugan -s 2 -n 0 --realcugan-model models-se \ + -e preset=veryfast -e crf=30 + +memcheck-libplacebo: + LD_LIBRARY_PATH={{BINDIR}} valgrind \ + --tool=memcheck \ + --leak-check=full \ + --show-leak-kinds=all \ + --track-origins=yes \ + --show-reachable=yes \ + --verbose --log-file="valgrind.log" \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p libplacebo -w 1920 -h 1080 --libplacebo-shader anime4k-v4-a \ + -e preset=veryfast -e crf=30 + +memcheck-rife: + LD_LIBRARY_PATH={{BINDIR}} valgrind \ + --tool=memcheck \ + --leak-check=full \ + --show-leak-kinds=all \ + --track-origins=yes \ + --show-reachable=yes \ + --verbose --log-file="valgrind.log" \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p rife -m 4 --rife-model rife-v4.6 \ + -e preset=veryfast -e crf=30 + +heaptrack-realesrgan: + LD_LIBRARY_PATH={{BINDIR}} HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p realesrgan -s 4 --realesrgan-model realesr-animevideov3 \ + -e preset=veryfast -e crf=30 + +heaptrack-realcugan: + LD_LIBRARY_PATH={{BINDIR}} HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p realcugan -s 4 -n 0 --realcugan-model models-se \ + -e preset=veryfast -e crf=30 + +heaptrack-libplacebo: + LD_LIBRARY_PATH={{BINDIR}} HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p libplacebo -w 1920 -h 1080 --libplacebo-shader anime4k-v4-a \ + -e preset=veryfast -e crf=30 + +heaptrack-rife: + LD_LIBRARY_PATH={{BINDIR}} HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ + {{BINDIR}}/video2x \ + -i {{TEST_VIDEO}} -o {{TEST_OUTPUT}} \ + -p rife -m 4 --rife-model rife-v4.6 \ + -e preset=veryfast -e crf=30 diff --git a/CMakeLists.txt b/CMakeLists.txt index 24f553a..7ec6852 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,11 +10,6 @@ if(POLICY CMP0167) cmake_policy(SET CMP0167 NEW) endif() -# Set the C++ standard -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - # Set the default build type to Release if not specified if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) @@ -24,15 +19,15 @@ endif() option(BUILD_SHARED_LIBS "Build libvideo2x as a shared library" ON) option(VIDEO2X_BUILD_CLI "Build the video2x command line interface executable" ON) -option(VIDEO2X_ENABLE_NATIVE "Enable optimizations for the native architecture" OFF) -option(VIDEO2X_ENABLE_X86_64_V4 "Enable x86-64-v4 (AVX-512) optimizations" OFF) -option(VIDEO2X_ENABLE_X86_64_V3 "Enable x86-64-v3 (AVX2) optimizations" OFF) - option(VIDEO2X_USE_EXTERNAL_NCNN "Use the system-provided ncnn library" ON) option(VIDEO2X_USE_EXTERNAL_SPDLOG "Use the system-provided spdlog library" ON) option(VIDEO2X_USE_EXTERNAL_BOOST "Use the system-provided Boost library" ON) -# Set global compile options for all targets +option(VIDEO2X_ENABLE_NATIVE "Enable optimizations for the native architecture" OFF) +option(VIDEO2X_ENABLE_X86_64_V4 "Enable x86-64-v4 (AVX-512) optimizations" OFF) +option(VIDEO2X_ENABLE_X86_64_V3 "Enable x86-64-v3 (AVX2) optimizations" OFF) + +# Enable extra compiler warnings if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options(/W4 /permissive-) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") @@ -41,7 +36,6 @@ endif() # Set the default optimization flags for Release builds if(CMAKE_BUILD_TYPE STREQUAL "Release") - # Set the optimization flags for each compiler if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options(/Ox /Ot /GL /DNDEBUG) add_link_options(/LTCG /OPT:REF /OPT:ICF) @@ -72,262 +66,6 @@ elseif(VIDEO2X_ENABLE_X86_64_V3) endif() endif() -# Define lists to store include directories and libraries -set(LIBVIDEO2X_INCLUDE_DIRS) -set(LIBVIDEO2X_LIBS) -set(VIDEO2X_INCLUDE_DIRS) -set(VIDEO2X_LIBS) - -# Platform-specific dependencies -if(WIN32) - # Define base paths for FFmpeg and ncnn - set(FFMPEG_BASE_PATH ${PROJECT_SOURCE_DIR}/third_party/ffmpeg-shared) - set(NCNN_BASE_PATH ${PROJECT_SOURCE_DIR}/third_party/ncnn-shared/x64) - - # FFmpeg - set(FFMPEG_LIB - ${FFMPEG_BASE_PATH}/lib/avcodec.lib - ${FFMPEG_BASE_PATH}/lib/avdevice.lib - ${FFMPEG_BASE_PATH}/lib/avfilter.lib - ${FFMPEG_BASE_PATH}/lib/avformat.lib - ${FFMPEG_BASE_PATH}/lib/avutil.lib - ${FFMPEG_BASE_PATH}/lib/swscale.lib - ) - list(APPEND LIBVIDEO2X_LIBS ${FFMPEG_LIB}) - list(APPEND LIBVIDEO2X_INCLUDE_DIRS ${FFMPEG_BASE_PATH}/include) - list(APPEND VIDEO2X_LIBS ${FFMPEG_LIB}) - list(APPEND VIDEO2X_INCLUDE_DIRS ${FFMPEG_BASE_PATH}/include) - - # ncnn - set(SPIRV_BUILD_PATH - ${CMAKE_BINARY_DIR}/realesrgan-prefix/src/realesrgan-build/ncnn/glslang/SPIRV - ) - if(CMAKE_BUILD_TYPE STREQUAL "Release") - set(SPIRV_LIB ${SPIRV_BUILD_PATH}/Release/SPIRV.lib) - else() - set(SPIRV_LIB ${SPIRV_BUILD_PATH}/Debug/SPIRVd.lib) - endif() - - list(APPEND LIBVIDEO2X_LIBS ${NCNN_BASE_PATH}/lib/ncnn.lib ${SPIRV_LIB}) - list(APPEND LIBVIDEO2X_INCLUDE_DIRS ${NCNN_BASE_PATH}/include/ncnn) -else() - # FFmpeg - find_package(PkgConfig REQUIRED) - set(FFMPEG_REQUIRED_PKGS - libavcodec - libavdevice - libavfilter - libavformat - libavutil - libswscale - ) - - # Loop through each package to find and collect include dirs and libraries - foreach(PKG ${FFMPEG_REQUIRED_PKGS}) - pkg_check_modules(${PKG} REQUIRED ${PKG}) - list(APPEND LIBVIDEO2X_INCLUDE_DIRS ${${PKG}_INCLUDE_DIRS}) - list(APPEND LIBVIDEO2X_LIBS ${${PKG}_LIBRARIES}) - list(APPEND VIDEO2X_INCLUDE_DIRS ${${PKG}_INCLUDE_DIRS}) - list(APPEND VIDEO2X_LIBS ${${PKG}_LIBRARIES}) - endforeach() -endif() # WIN32 - -# Find ncnn package -if(VIDEO2X_USE_EXTERNAL_NCNN) - find_package(ncnn REQUIRED) -else() - option(NCNN_INSTALL_SDK "" OFF) - option(NCNN_PIXEL_ROTATE "" OFF) - option(NCNN_VULKAN "" ON) - option(NCNN_VULKAN_ONLINE_SPIRV "" ON) - option(NCNN_BUILD_BENCHMARK "" OFF) - option(NCNN_BUILD_TESTS "" OFF) - option(NCNN_BUILD_TOOLS "" OFF) - option(NCNN_BUILD_EXAMPLES "" OFF) - option(NCNN_DISABLE_RTTI "" ON) - option(NCNN_DISABLE_EXCEPTION "" ON) - option(NCNN_BUILD_SHARED_LIBS "" OFF) - option(SKIP_GLSLANG_INSTALL "" ON) - - option(WITH_LAYER_absval "" OFF) - option(WITH_LAYER_argmax "" OFF) - option(WITH_LAYER_batchnorm "" OFF) - option(WITH_LAYER_bias "" OFF) - option(WITH_LAYER_bnll "" OFF) - option(WITH_LAYER_concat "" ON) - option(WITH_LAYER_convolution "" ON) - option(WITH_LAYER_crop "" ON) - option(WITH_LAYER_deconvolution "" OFF) - option(WITH_LAYER_dropout "" OFF) - option(WITH_LAYER_eltwise "" ON) - option(WITH_LAYER_elu "" OFF) - option(WITH_LAYER_embed "" OFF) - option(WITH_LAYER_exp "" OFF) - option(WITH_LAYER_flatten "" ON) - option(WITH_LAYER_innerproduct "" ON) - option(WITH_LAYER_input "" ON) - option(WITH_LAYER_log "" OFF) - option(WITH_LAYER_lrn "" OFF) - option(WITH_LAYER_memorydata "" OFF) - option(WITH_LAYER_mvn "" OFF) - option(WITH_LAYER_pooling "" OFF) - option(WITH_LAYER_power "" OFF) - option(WITH_LAYER_prelu "" ON) - option(WITH_LAYER_proposal "" OFF) - option(WITH_LAYER_reduction "" OFF) - option(WITH_LAYER_relu "" ON) - option(WITH_LAYER_reshape "" OFF) - option(WITH_LAYER_roipooling "" OFF) - option(WITH_LAYER_scale "" OFF) - option(WITH_LAYER_sigmoid "" OFF) - option(WITH_LAYER_slice "" OFF) - option(WITH_LAYER_softmax "" OFF) - option(WITH_LAYER_split "" ON) - option(WITH_LAYER_spp "" OFF) - option(WITH_LAYER_tanh "" OFF) - option(WITH_LAYER_threshold "" OFF) - option(WITH_LAYER_tile "" OFF) - option(WITH_LAYER_rnn "" OFF) - option(WITH_LAYER_lstm "" OFF) - option(WITH_LAYER_binaryop "" ON) - option(WITH_LAYER_unaryop "" OFF) - option(WITH_LAYER_convolutiondepthwise "" OFF) - option(WITH_LAYER_padding "" ON) - option(WITH_LAYER_squeeze "" OFF) - option(WITH_LAYER_expanddims "" OFF) - option(WITH_LAYER_normalize "" OFF) - option(WITH_LAYER_permute "" OFF) - option(WITH_LAYER_priorbox "" OFF) - option(WITH_LAYER_detectionoutput "" OFF) - option(WITH_LAYER_interp "" ON) - option(WITH_LAYER_deconvolutiondepthwise "" OFF) - option(WITH_LAYER_shufflechannel "" OFF) - option(WITH_LAYER_instancenorm "" OFF) - option(WITH_LAYER_clip "" OFF) - option(WITH_LAYER_reorg "" OFF) - option(WITH_LAYER_yolodetectionoutput "" OFF) - option(WITH_LAYER_quantize "" OFF) - option(WITH_LAYER_dequantize "" OFF) - option(WITH_LAYER_yolov3detectionoutput "" OFF) - option(WITH_LAYER_psroipooling "" OFF) - option(WITH_LAYER_roialign "" OFF) - option(WITH_LAYER_packing "" ON) - option(WITH_LAYER_requantize "" OFF) - option(WITH_LAYER_cast "" ON) - option(WITH_LAYER_hardsigmoid "" OFF) - option(WITH_LAYER_selu "" OFF) - option(WITH_LAYER_hardswish "" OFF) - option(WITH_LAYER_noop "" OFF) - option(WITH_LAYER_pixelshuffle "" ON) - option(WITH_LAYER_deepcopy "" OFF) - option(WITH_LAYER_mish "" OFF) - option(WITH_LAYER_statisticspooling "" OFF) - option(WITH_LAYER_swish "" OFF) - option(WITH_LAYER_gemm "" OFF) - option(WITH_LAYER_groupnorm "" OFF) - option(WITH_LAYER_layernorm "" OFF) - option(WITH_LAYER_softplus "" OFF) - - add_subdirectory(third_party/ncnn) -endif() - -# spdlog -if(VIDEO2X_USE_EXTERNAL_SPDLOG) - find_package(spdlog REQUIRED) - list(APPEND LIBVIDEO2X_INCLUDE_DIRS ${spdlog_INCLUDE_DIRS}) - list(APPEND VIDEO2X_INCLUDE_DIRS ${spdlog_INCLUDE_DIRS}) - set(SPDLOG_LIB spdlog::spdlog) -else() - # spdlog exceptions are incompatible with ncnn - option(SPDLOG_NO_EXCEPTIONS "" ON) - add_subdirectory(third_party/spdlog) - set(SPDLOG_LIB spdlog::spdlog_header_only) -endif() -list(APPEND LIBVIDEO2X_LIBS ${SPDLOG_LIB}) -list(APPEND VIDEO2X_LIBS ${SPDLOG_LIB}) - -# Find dependencies required for the CLI -if(VIDEO2X_BUILD_CLI) - # Vulkan - find_package(Vulkan REQUIRED) - list(APPEND VIDEO2X_LIBS Vulkan::Vulkan) - - # Boost - if(VIDEO2X_USE_EXTERNAL_BOOST) - find_package(Boost REQUIRED COMPONENTS program_options) - list(APPEND LIBVIDEO2X_INCLUDE_DIRS ${Boost_INCLUDE_DIRS}) - else() - option(Boost_USE_STATIC_LIBS "" ON) - option(Boost_USE_STATIC_RUNTIME "" ON) - option(Boost_COMPONENTS "program_options") - - add_subdirectory(third_party/boost) - include_directories(${PROJECT_SOURCE_DIR}/third_party/boost/libs/program_options/include) - set(BOOST_BASE_PATH - ${CMAKE_BINARY_DIR}/third_party/boost/libs/program_options/${CMAKE_BUILD_TYPE} - ) - endif() - list(APPEND VIDEO2X_LIBS Boost::program_options) -endif() - -# Add librealesrgan-ncnn-vulkan as an external project -ExternalProject_Add( - realesrgan - SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/librealesrgan_ncnn_vulkan/src - CMAKE_ARGS - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/realesrgan-install - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DUSE_SYSTEM_NCNN=${VIDEO2X_USE_EXTERNAL_NCNN} - BUILD_ALWAYS ON - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE} -) - -# Add librealcugan-ncnn-vulkan as an external project -ExternalProject_Add( - realcugan - SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/librealcugan_ncnn_vulkan/src - CMAKE_ARGS - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/realcugan-install - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DUSE_SYSTEM_NCNN=${VIDEO2X_USE_EXTERNAL_NCNN} - BUILD_ALWAYS ON - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE} -) - -# Add librife-ncnn-vulkan as an external project -ExternalProject_Add( - rife - SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/librife_ncnn_vulkan/src - CMAKE_ARGS - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/rife-install - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DUSE_SYSTEM_NCNN=${VIDEO2X_USE_EXTERNAL_NCNN} - BUILD_ALWAYS ON - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE} -) - -# Remove duplicate entries -list(REMOVE_DUPLICATES LIBVIDEO2X_INCLUDE_DIRS) -list(REMOVE_DUPLICATES LIBVIDEO2X_LIBS) -list(REMOVE_DUPLICATES VIDEO2X_INCLUDE_DIRS) -list(REMOVE_DUPLICATES VIDEO2X_LIBS) - -# Create the shared library 'libvideo2x' -file(GLOB LIBVIDEO2X_SOURCES src/*.cpp) -add_library(libvideo2x ${LIBVIDEO2X_SOURCES}) -target_compile_definitions(libvideo2x PRIVATE LIBVIDEO2X_EXPORTS) -if(WIN32) - set_target_properties(libvideo2x PROPERTIES OUTPUT_NAME libvideo2x) -else() - set_target_properties(libvideo2x PROPERTIES OUTPUT_NAME video2x) -endif() - -# Ensure that the shared library is built after the external projects -add_dependencies(libvideo2x realesrgan realcugan rife) - # Generate the version header file configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in" @@ -335,154 +73,431 @@ configure_file( @ONLY ) -# Include directories for the shared library -target_include_directories(libvideo2x PRIVATE - ${LIBVIDEO2X_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/include/libvideo2x - ${PROJECT_SOURCE_DIR}/third_party/librealesrgan_ncnn_vulkan/src - ${PROJECT_SOURCE_DIR}/third_party/librealcugan_ncnn_vulkan/src - ${PROJECT_SOURCE_DIR}/third_party/librife_ncnn_vulkan/src +# Add the libvideo2x shared library +add_library(libvideo2x + src/avutils.cpp + src/conversions.cpp + src/decoder.cpp + src/encoder.cpp + src/filter_libplacebo.cpp + src/filter_realcugan.cpp + src/filter_realesrgan.cpp + src/fsutils.cpp + src/interpolator_rife.cpp + src/libplacebo.cpp + src/libvideo2x.cpp + src/logger_manager.cpp + src/processor_factory.cpp ) -# Set the compile options for the shared library +# Set the C++ standard to C++17 +target_compile_features(libvideo2x PRIVATE cxx_std_17) + +# Set the shared library output name and disable C++ extensions +set_target_properties(libvideo2x PROPERTIES + PREFIX lib + OUTPUT_NAME video2x + CXX_EXTENSIONS OFF +) + +# Include directories for the shared library +target_include_directories(libvideo2x PRIVATE + "${CMAKE_CURRENT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_SOURCE_DIR}/include/libvideo2x" + "${PROJECT_SOURCE_DIR}/third_party/librealesrgan_ncnn_vulkan/src" + "${PROJECT_SOURCE_DIR}/third_party/librealcugan_ncnn_vulkan/src" + "${PROJECT_SOURCE_DIR}/third_party/librife_ncnn_vulkan/src" +) + +# Add the export definition for the exported symbols +target_compile_definitions(libvideo2x PRIVATE LIBVIDEO2X_EXPORTS) + +# Set debug compile options if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(libvideo2x PRIVATE $<$:/Zi /Od /MDd>) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") target_compile_options(libvideo2x PRIVATE -fPIC $<$:-g -O0>) endif() -# Define the paths to the shared libraries +# FFmpeg if(WIN32) - set(REALESRGAN_LIB ${CMAKE_BINARY_DIR}/realesrgan-install/lib/librealesrgan-ncnn-vulkan.lib) - set(REALCUGAN_LIB ${CMAKE_BINARY_DIR}/realcugan-install/lib/librealcugan-ncnn-vulkan.lib) - set(RIFE_LIB ${CMAKE_BINARY_DIR}/rife-install/lib/librife-ncnn-vulkan.lib) + target_include_directories(libvideo2x SYSTEM PRIVATE + "${PROJECT_SOURCE_DIR}/third_party/ffmpeg-shared/include" + ) + target_link_libraries(libvideo2x PRIVATE + "${ffmpeg_base_path}/lib/avcodec.lib" + "${ffmpeg_base_path}/lib/avfilter.lib" + "${ffmpeg_base_path}/lib/avformat.lib" + "${ffmpeg_base_path}/lib/avutil.lib" + "${ffmpeg_base_path}/lib/swscale.lib" + ) else() - set(REALESRGAN_LIB ${CMAKE_BINARY_DIR}/realesrgan-install/lib/librealesrgan-ncnn-vulkan.so) - set(REALCUGAN_LIB ${CMAKE_BINARY_DIR}/realcugan-install/lib/librealcugan-ncnn-vulkan.so) - set(RIFE_LIB ${CMAKE_BINARY_DIR}/rife-install/lib/librife-ncnn-vulkan.so) + # Use pkg-config to find FFmpeg libraries + find_package(PkgConfig REQUIRED) + + # Find and configure FFmpeg libraries + pkg_check_modules(libavcodec REQUIRED libavcodec) + pkg_check_modules(libavfilter REQUIRED libavfilter) + pkg_check_modules(libavformat REQUIRED libavformat) + pkg_check_modules(libavutil REQUIRED libavutil) + pkg_check_modules(libswscale REQUIRED libswscale) + + # Apply include directories and libraries directly to the target + target_include_directories(libvideo2x SYSTEM PRIVATE + ${libavcodec_INCLUDE_DIRS} + ${libavfilter_LIBRARIES} + ${libavformat_INCLUDE_DIRS} + ${libavutil_INCLUDE_DIRS} + ${libswscale_INCLUDE_DIRS} + ) + target_link_libraries(libvideo2x PRIVATE + ${libavcodec_LIBRARIES} + ${libavfilter_LIBRARIES} + ${libavformat_LIBRARIES} + ${libavutil_LIBRARIES} + ${libswscale_LIBRARIES} + ) endif() -list(APPEND LIBVIDEO2X_LIBS ${REALESRGAN_LIB} ${REALCUGAN_LIB} ${RIFE_LIB}) -# Link the shared library with the dependencies -target_link_libraries(libvideo2x PRIVATE ${LIBVIDEO2X_LIBS}) +# ncnn +if(VIDEO2X_USE_EXTERNAL_NCNN) + find_package(ncnn REQUIRED) + target_link_libraries(libvideo2x PRIVATE ncnn) +else() + if(WIN32) + # On Windows, use the pre-built shared ncnn library + set(ncnn_base_path "${PROJECT_SOURCE_DIR}/third_party/ncnn-shared/x64") + set(spirv_build_path + "${CMAKE_BINARY_DIR}/realesrgan-prefix/src/realesrgan-build/ncnn/glslang/SPIRV" + ) -if(NOT WIN32) - if(VIDEO2X_USE_EXTERNAL_NCNN) - target_link_libraries(libvideo2x PUBLIC ncnn) + # Link ncnn and SPIRV libraries + target_include_directories(libvideo2x SYSTEM PRIVATE "${ncnn_base_path}/include/ncnn") + target_link_libraries(libvideo2x PRIVATE "${ncnn_base_path}/lib/ncnn.lib") + + # SPIRV needs to be linked explicitly + if(CMAKE_BUILD_TYPE STREQUAL Release) + target_link_libraries(libvideo2x PRIVATE "${spirv_build_path}/Release/SPIRV.lib") + else() + target_link_libraries(libvideo2x PRIVATE "${spirv_build_path}/Debug/SPIRVd.lib") + endif() else() + option(NCNN_INSTALL_SDK "" ON) + option(SKIP_GLSLANG_INSTALL "" OFF) + + option(NCNN_PIXEL_ROTATE "" OFF) + option(NCNN_VULKAN "" ON) + option(NCNN_VULKAN_ONLINE_SPIRV "" ON) + option(NCNN_BUILD_BENCHMARK "" OFF) + option(NCNN_BUILD_TESTS "" OFF) + option(NCNN_BUILD_TOOLS "" OFF) + option(NCNN_BUILD_EXAMPLES "" OFF) + option(NCNN_DISABLE_RTTI "" ON) + option(NCNN_DISABLE_EXCEPTION "" ON) + option(NCNN_BUILD_SHARED_LIBS "" OFF) + + option(WITH_LAYER_absval "" OFF) + option(WITH_LAYER_argmax "" OFF) + option(WITH_LAYER_batchnorm "" OFF) + option(WITH_LAYER_bias "" OFF) + option(WITH_LAYER_bnll "" OFF) + option(WITH_LAYER_concat "" ON) + option(WITH_LAYER_convolution "" ON) + option(WITH_LAYER_crop "" ON) + option(WITH_LAYER_deconvolution "" OFF) + option(WITH_LAYER_dropout "" OFF) + option(WITH_LAYER_eltwise "" ON) + option(WITH_LAYER_elu "" OFF) + option(WITH_LAYER_embed "" OFF) + option(WITH_LAYER_exp "" OFF) + option(WITH_LAYER_flatten "" ON) + option(WITH_LAYER_innerproduct "" ON) + option(WITH_LAYER_input "" ON) + option(WITH_LAYER_log "" OFF) + option(WITH_LAYER_lrn "" OFF) + option(WITH_LAYER_memorydata "" OFF) + option(WITH_LAYER_mvn "" OFF) + option(WITH_LAYER_pooling "" OFF) + option(WITH_LAYER_power "" OFF) + option(WITH_LAYER_prelu "" ON) + option(WITH_LAYER_proposal "" OFF) + option(WITH_LAYER_reduction "" OFF) + option(WITH_LAYER_relu "" ON) + option(WITH_LAYER_reshape "" OFF) + option(WITH_LAYER_roipooling "" OFF) + option(WITH_LAYER_scale "" OFF) + option(WITH_LAYER_sigmoid "" OFF) + option(WITH_LAYER_slice "" OFF) + option(WITH_LAYER_softmax "" OFF) + option(WITH_LAYER_split "" ON) + option(WITH_LAYER_spp "" OFF) + option(WITH_LAYER_tanh "" OFF) + option(WITH_LAYER_threshold "" OFF) + option(WITH_LAYER_tile "" OFF) + option(WITH_LAYER_rnn "" OFF) + option(WITH_LAYER_lstm "" OFF) + option(WITH_LAYER_binaryop "" ON) + option(WITH_LAYER_unaryop "" OFF) + option(WITH_LAYER_convolutiondepthwise "" OFF) + option(WITH_LAYER_padding "" ON) + option(WITH_LAYER_squeeze "" OFF) + option(WITH_LAYER_expanddims "" OFF) + option(WITH_LAYER_normalize "" OFF) + option(WITH_LAYER_permute "" OFF) + option(WITH_LAYER_priorbox "" OFF) + option(WITH_LAYER_detectionoutput "" OFF) + option(WITH_LAYER_interp "" ON) + option(WITH_LAYER_deconvolutiondepthwise "" OFF) + option(WITH_LAYER_shufflechannel "" OFF) + option(WITH_LAYER_instancenorm "" OFF) + option(WITH_LAYER_clip "" OFF) + option(WITH_LAYER_reorg "" OFF) + option(WITH_LAYER_yolodetectionoutput "" OFF) + option(WITH_LAYER_quantize "" OFF) + option(WITH_LAYER_dequantize "" OFF) + option(WITH_LAYER_yolov3detectionoutput "" OFF) + option(WITH_LAYER_psroipooling "" OFF) + option(WITH_LAYER_roialign "" OFF) + option(WITH_LAYER_packing "" ON) + option(WITH_LAYER_requantize "" OFF) + option(WITH_LAYER_cast "" ON) + option(WITH_LAYER_hardsigmoid "" OFF) + option(WITH_LAYER_selu "" OFF) + option(WITH_LAYER_hardswish "" OFF) + option(WITH_LAYER_noop "" OFF) + option(WITH_LAYER_pixelshuffle "" ON) + option(WITH_LAYER_deepcopy "" OFF) + option(WITH_LAYER_mish "" OFF) + option(WITH_LAYER_statisticspooling "" OFF) + option(WITH_LAYER_swish "" OFF) + option(WITH_LAYER_gemm "" OFF) + option(WITH_LAYER_groupnorm "" OFF) + option(WITH_LAYER_layernorm "" OFF) + option(WITH_LAYER_softplus "" OFF) + + add_subdirectory(third_party/ncnn) target_link_libraries(libvideo2x PRIVATE ncnn) endif() endif() -# Build the Video2X CLI executable -if(VIDEO2X_BUILD_CLI) - file(GLOB VIDEO2X_SOURCES tools/video2x/src/*.cpp) - add_executable(video2x ${VIDEO2X_SOURCES}) - set_target_properties(video2x PROPERTIES OUTPUT_NAME video2x) - - # Include directories for the executable - target_include_directories(video2x PRIVATE - ${VIDEO2X_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/tools/video2x/include - ) - - # Compile options for the executable - target_compile_options(video2x PRIVATE $<$:-g -DDEBUG>) - - # Link the executable with the shared library - target_link_libraries(video2x PRIVATE libvideo2x ${VIDEO2X_LIBS}) +# spdlog +if(VIDEO2X_USE_EXTERNAL_SPDLOG) + find_package(spdlog REQUIRED) + target_include_directories(libvideo2x SYSTEM PRIVATE ${spdlog_INCLUDE_DIRS}) + target_link_libraries(libvideo2x PRIVATE spdlog::spdlog) +else() + # spdlog exceptions are incompatible with ncnn + option(SPDLOG_NO_EXCEPTIONS "" ON) + option(SPDLOG_INSTALL "" ON) + add_subdirectory(third_party/spdlog) + target_link_libraries(libvideo2x PRIVATE spdlog::spdlog_header_only) endif() +# Real-ESRGAN, Real-CUGAN, and RIFE +option(USE_SYSTEM_NCNN "" ${VIDEO2X_USE_EXTERNAL_NCNN}) +add_subdirectory(third_party/librealesrgan_ncnn_vulkan/src) +add_subdirectory(third_party/librealcugan_ncnn_vulkan/src) +add_subdirectory(third_party/librife_ncnn_vulkan/src) + +# Determine the library suffix based on the platform +if(WIN32) + set(suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) +else() + set(suffix ${CMAKE_SHARED_LIBRARY_SUFFIX}) +endif() + +# Link the shared library with the ncnn-Vulkan-based libraries +set(ncnn_vulkan_libs) +foreach(lib IN ITEMS realesrgan realcugan rife) + list(APPEND ncnn_vulkan_libs + "${CMAKE_BINARY_DIR}/third_party/lib${lib}_ncnn_vulkan/src/lib${lib}-ncnn-vulkan${suffix}" + ) +endforeach() +target_link_libraries(libvideo2x PRIVATE ${ncnn_vulkan_libs}) + # Determine the installation directories if(WIN32) - set(INSTALL_BIN_DESTINATION ".") - set(INSTALL_INCLUDE_DESTINATION "include/libvideo2x") - set(INSTALL_LIB_DESTINATION ".") - set(INSTALL_MODEL_DESTINATION ".") - set(INSTALL_CMAKE_DESTINATION "cmake/Video2X") + set(install_bin_destination .) + set(install_include_destination include/libvideo2x) + set(install_lib_destination .) + set(install_model_destination .) + set(install_cmake_destination cmake/Video2X) else() - set(INSTALL_BIN_DESTINATION "${CMAKE_INSTALL_BINDIR}") - set(INSTALL_INCLUDE_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libvideo2x") - set(INSTALL_LIB_DESTINATION "${CMAKE_INSTALL_LIBDIR}") - set(INSTALL_MODEL_DESTINATION "${CMAKE_INSTALL_DATADIR}/video2x") - set(INSTALL_CMAKE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Video2X") + set(install_bin_destination "${CMAKE_INSTALL_BINDIR}") + set(install_include_destination "${CMAKE_INSTALL_INCLUDEDIR}/libvideo2x") + set(install_lib_destination "${CMAKE_INSTALL_LIBDIR}") + set(install_model_destination "${CMAKE_INSTALL_DATADIR}/video2x") + set(install_cmake_destination "${CMAKE_INSTALL_LIBDIR}/cmake/Video2X") endif() # Common installation rules for libvideo2x and models install(TARGETS libvideo2x EXPORT Video2XTargets - LIBRARY DESTINATION ${INSTALL_LIB_DESTINATION} - ARCHIVE DESTINATION ${INSTALL_LIB_DESTINATION} - RUNTIME DESTINATION ${INSTALL_BIN_DESTINATION} + RUNTIME DESTINATION "${install_bin_destination}" + LIBRARY DESTINATION "${install_lib_destination}" + ARCHIVE DESTINATION "${install_lib_destination}" + INCLUDES DESTINATION "${install_include_destination}" ) # Install the header files from the include directory -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/libvideo2x/ - DESTINATION ${INSTALL_INCLUDE_DESTINATION} +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/libvideo2x/" + DESTINATION "${install_include_destination}" FILES_MATCHING PATTERN "*.h" ) # Install the generated version.h file install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/libvideo2x/version.h - DESTINATION ${INSTALL_INCLUDE_DESTINATION} + "${CMAKE_CURRENT_BINARY_DIR}/libvideo2x/version.h" + DESTINATION "${install_include_destination}" ) # Export targets and create CMake package config install(EXPORT Video2XTargets FILE Video2XTargets.cmake NAMESPACE Video2X:: - DESTINATION ${INSTALL_CMAKE_DESTINATION} + DESTINATION "${install_cmake_destination}" ) # Generate the CMake package config file configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Video2XConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/Video2XConfig.cmake" - INSTALL_DESTINATION ${INSTALL_CMAKE_DESTINATION} + INSTALL_DESTINATION "${install_cmake_destination}" ) # Install the CMake package config file install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Video2XConfig.cmake" - DESTINATION ${INSTALL_CMAKE_DESTINATION} + DESTINATION "${install_cmake_destination}" ) # Install model files -install(DIRECTORY ${CMAKE_SOURCE_DIR}/models DESTINATION ${INSTALL_MODEL_DESTINATION}) +install(DIRECTORY "${CMAKE_SOURCE_DIR}/models" DESTINATION "${install_model_destination}") # Platform-specific installation rules if(WIN32) - file(GLOB FFMPEG_DLLS "${FFMPEG_BASE_PATH}/bin/*.dll") + file(GLOB ffmpeg_dlls "${ffmpeg_base_path}/bin/*.dll") install(FILES - ${CMAKE_BINARY_DIR}/realesrgan-install/bin/librealesrgan-ncnn-vulkan.dll - ${CMAKE_BINARY_DIR}/realcugan-install/bin/librealcugan-ncnn-vulkan.dll - ${CMAKE_BINARY_DIR}/rife-install/bin/librife-ncnn-vulkan.dll - ${FFMPEG_DLLS} - ${NCNN_BASE_PATH}/bin/ncnn.dll - DESTINATION ${INSTALL_BIN_DESTINATION} + ${ffmpeg_dlls} + "${ncnn_base_path}/bin/ncnn.dll" + ${ncnn_vulkan_libs} + DESTINATION "${install_bin_destination}" ) else() - install(FILES ${REALESRGAN_LIB} ${REALCUGAN_LIB} ${RIFE_LIB} - DESTINATION ${INSTALL_LIB_DESTINATION} + install(FILES + ${ncnn_vulkan_libs} + DESTINATION "${install_lib_destination}" ) endif() -# Install the Video2X CLI executable +# Build the video2x CLI executable if(VIDEO2X_BUILD_CLI) - install(TARGETS video2x RUNTIME DESTINATION ${INSTALL_BIN_DESTINATION}) + add_executable(video2x + tools/video2x/src/argparse.cpp + tools/video2x/src/newline_safe_sink.cpp + tools/video2x/src/timer.cpp + tools/video2x/src/validators.cpp + tools/video2x/src/video2x.cpp + tools/video2x/src/vulkan_utils.cpp + ) + + # Set the C++ standard to C++17 + target_compile_features(video2x PRIVATE cxx_std_17) + + # Set the shared library output name and disable C++ extensions + set_target_properties(video2x PROPERTIES + OUTPUT_NAME video2x + CXX_EXTENSIONS OFF + ) + + # Include directories for the executable + target_include_directories(video2x PRIVATE + "${CMAKE_CURRENT_BINARY_DIR}" + "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_SOURCE_DIR}/tools/video2x/include" + ) + + # Link the executable with the shared library + target_link_libraries(video2x PRIVATE libvideo2x) + + # Set debug compile options + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + target_compile_options(video2x PRIVATE $<$:/Zi /Od /MDd>) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(video2x PRIVATE -fPIC $<$:-g -O0>) + endif() + + # FFmpeg + if(WIN32) + target_include_directories(video2x SYSTEM PRIVATE + "${PROJECT_SOURCE_DIR}/third_party/ffmpeg-shared/include" + ) + target_link_libraries(video2x PRIVATE + "${ffmpeg_base_path}/lib/avcodec.lib" + "${ffmpeg_base_path}/lib/avutil.lib" + ) + else() + # FFmpeg libraries have already been found + # Apply include directories and libraries directly to the target + target_include_directories(video2x SYSTEM PRIVATE + ${libavcodec_INCLUDE_DIRS} + ${libavutil_INCLUDE_DIRS} + ) + target_link_libraries(video2x PRIVATE ${libavcodec_LIBRARIES} ${libavutil_LIBRARIES}) + endif() + + # spdlog + # spdlog targets has already been added + if(VIDEO2X_USE_EXTERNAL_SPDLOG) + target_include_directories(video2x SYSTEM PRIVATE ${spdlog_INCLUDE_DIRS}) + target_link_libraries(video2x PRIVATE spdlog::spdlog) + else() + target_link_libraries(video2x PRIVATE spdlog::spdlog_header_only) + endif() + + # Vulkan + find_package(Vulkan REQUIRED) + target_link_libraries(video2x PRIVATE Vulkan::Vulkan) + + # Boost + if(VIDEO2X_USE_EXTERNAL_BOOST) + find_package(Boost REQUIRED COMPONENTS program_options) + else() + option(Boost_USE_STATIC_LIBS "" ON) + option(Boost_USE_STATIC_RUNTIME "" ON) + option(Boost_COMPONENTS program_options) + + add_subdirectory(third_party/boost) + target_include_directories(video2x SYSTEM PRIVATE + ${PROJECT_SOURCE_DIR}/third_party/boost/libs/program_options/include + ) + + # Suppress the -Wsign-conversion warnings for Boost.Nowide + if (TARGET boost_nowide) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(boost_nowide PRIVATE -Wno-error=sign-conversion) + endif() + endif() + endif() + target_link_libraries(video2x PRIVATE Boost::program_options) + + # Install the video2x executable + install(TARGETS video2x RUNTIME DESTINATION "${install_bin_destination}") # Install the Boost DLL if(WIN32 AND NOT VIDEO2X_USE_EXTERNAL_BOOST) - if(CMAKE_BUILD_TYPE STREQUAL "Release") - set(BOOST_DLL_PATH ${BOOST_BASE_PATH}/boost_program_options-vc143-mt-x64-1_86.dll) + set(boost_base_path + "${CMAKE_BINARY_DIR}/third_party/boost/libs/program_options/${CMAKE_BUILD_TYPE}" + ) + + # Different build types have different DLL names + if(CMAKE_BUILD_TYPE STREQUAL Release) + set(boost_dll_path "${boost_base_path}/boost_program_options-vc143-mt-x64-1_86.dll") else() - set(BOOST_DLL_PATH ${BOOST_BASE_PATH}/boost_program_options-vc143-mt-gd-x64-1_86.dll) + set(boost_dll_path "${boost_base_path}/boost_program_options-vc143-mt-gd-x64-1_86.dll") endif() - install(FILES ${BOOST_DLL_PATH} DESTINATION ${INSTALL_BIN_DESTINATION}) + + install(FILES "${boost_dll_path}" DESTINATION "${install_bin_destination}") endif() endif() diff --git a/Makefile b/Makefile deleted file mode 100644 index 9aa6814..0000000 --- a/Makefile +++ /dev/null @@ -1,225 +0,0 @@ -.PHONY: build static debug windows windows-debug debian ubuntu clean \ - test-realesrgan test-realcugan test-libplacebo test-rife \ - memcheck-realesrgan memcheck-realcugan memcheck-libplacebo memcheck-rife \ - heaptrack-realesrgan heaptrack-realcugan heaptrack-libplacebo heaptrack-rife - -BINDIR=build -CXX=clang++ - -TEST_VIDEO=data/standard-test.mp4 -TEST_OUTPUT=data/output.mp4 - -build: - cmake -S . -B $(BINDIR) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DCMAKE_CXX_COMPILER=$(CXX) \ - -DCMAKE_INSTALL_PREFIX=$(BINDIR)/video2x-install \ - -DCMAKE_BUILD_TYPE=Release \ - -DVIDEO2X_ENABLE_NATIVE=ON - cmake --build $(BINDIR) --config Release --parallel --target install - cp $(BINDIR)/compile_commands.json . - -static: - cmake -S . -B $(BINDIR) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DCMAKE_CXX_COMPILER=$(CXX) \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=OFF \ - -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ - -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ - -DVIDEO2X_USE_EXTERNAL_BOOST=OFF - cmake --build $(BINDIR) --config Release --parallel --target install - cp $(BINDIR)/compile_commands.json . - -debug: - cmake -S . -B $(BINDIR) \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DCMAKE_CXX_COMPILER=$(CXX) \ - -DCMAKE_BUILD_TYPE=Debug - cmake --build $(BINDIR) --config Debug --parallel - cp $(BINDIR)/compile_commands.json . - -windows: - cmake -S . -B $(BINDIR) \ - -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ - -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ - -DVIDEO2X_USE_EXTERNAL_BOOST=OFF \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=build/libvideo2x-shared - cmake --build $(BINDIR) --config Release --parallel --target install - -windows-debug: - cmake -S . -B $(BINDIR) \ - -DVIDEO2X_USE_EXTERNAL_NCNN=OFF \ - -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ - -DVIDEO2X_USE_EXTERNAL_BOOST=OFF \ - -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_INSTALL_PREFIX=build/libvideo2x-shared - cmake --build $(BINDIR) --config Debug --parallel --target install - -debian: - apt-get update - apt-get install -y --no-install-recommends \ - build-essential cmake clang pkg-config \ - libavcodec-dev \ - libavdevice-dev \ - libavfilter-dev \ - libavformat-dev \ - libavutil-dev \ - libswscale-dev \ - libvulkan-dev \ - glslang-tools \ - libomp-dev \ - libspdlog-dev \ - libboost-program-options-dev - cmake -B /tmp/build -S . -DVIDEO2X_USE_EXTERNAL_NCNN=OFF -DCMAKE_CXX_COMPILER=$(CXX) \ - -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install \ - -DINSTALL_BIN_DESTINATION=. -DINSTALL_INCLUDE_DESTINATION=include \ - -DINSTALL_LIB_DESTINATION=. -DINSTALL_MODEL_DESTINATION=. - cmake --build /tmp/build --config Release --target install --parallel - -ubuntu2404: - apt-get update - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - build-essential cmake pkg-config \ - libavcodec-dev \ - libavdevice-dev \ - libavfilter-dev \ - libavformat-dev \ - libavutil-dev \ - libswscale-dev \ - libvulkan-dev \ - glslang-tools \ - libomp-dev \ - libboost-program-options-dev - cmake -B build -S . -DVIDEO2X_USE_EXTERNAL_NCNN=OFF -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ - -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=video2x-linux-ubuntu-amd64/usr - cmake --build build --config Release --target install --parallel - mkdir -p video2x-linux-ubuntu-amd64/DEBIAN - cp packaging/debian/control.ubuntu2404 video2x-linux-ubuntu-amd64/DEBIAN/control - dpkg-deb --build video2x-linux-ubuntu-amd64 - -ubuntu2204: - apt-get update - DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common - add-apt-repository -y ppa:ubuntuhandbook1/ffmpeg7 - apt-get update - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - build-essential cmake \ - libavcodec-dev \ - libavdevice-dev \ - libavfilter-dev \ - libavformat-dev \ - libavutil-dev \ - libswscale-dev \ - libvulkan-dev \ - glslang-tools \ - libomp-dev \ - libboost-program-options-dev - cmake -B build -S . -DVIDEO2X_USE_EXTERNAL_NCNN=OFF -DVIDEO2X_USE_EXTERNAL_SPDLOG=OFF \ - -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=video2x-linux-ubuntu-amd64/usr - cmake --build build --config Release --target install --parallel - mkdir -p video2x-linux-ubuntu-amd64/DEBIAN - cp packaging/debian/control.ubuntu2204 video2x-linux-ubuntu-amd64/DEBIAN/control - dpkg-deb --build video2x-linux-ubuntu-amd64 - -clean: - rm -vrf $(BINDIR) data/output*.* heaptrack*.zst valgrind.log - -test-realesrgan: - LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p realesrgan -s 4 --realesrgan-model realesr-animevideov3 - -test-realcugan: - LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p realcugan -s 4 -n 0 --realcugan-model models-se - -test-libplacebo: - LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p libplacebo -w 1920 -h 1080 --libplacebo-shader anime4k-v4-a - -test-rife: - LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p rife -m 4 --rife-model rife-v4.6 - -memcheck-realesrgan: - LD_LIBRARY_PATH=$(BINDIR) valgrind \ - --tool=memcheck \ - --leak-check=full \ - --show-leak-kinds=all \ - --track-origins=yes \ - --show-reachable=yes \ - --verbose --log-file="valgrind.log" \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p realesrgan -s 2 --realesrgan-model realesr-animevideov3 \ - -e preset=veryfast -e crf=30 - -memcheck-realcugan: - LD_LIBRARY_PATH=$(BINDIR) valgrind \ - --tool=memcheck \ - --leak-check=full \ - --show-leak-kinds=all \ - --track-origins=yes \ - --show-reachable=yes \ - --verbose --log-file="valgrind.log" \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p realcugan -s 2 -n 0 --realcugan-model models-se \ - -e preset=veryfast -e crf=30 - -memcheck-libplacebo: - LD_LIBRARY_PATH=$(BINDIR) valgrind \ - --tool=memcheck \ - --leak-check=full \ - --show-leak-kinds=all \ - --track-origins=yes \ - --show-reachable=yes \ - --verbose --log-file="valgrind.log" \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p libplacebo -w 1920 -h 1080 --libplacebo-shader anime4k-v4-a \ - -e preset=veryfast -e crf=30 - -memcheck-rife: - LD_LIBRARY_PATH=$(BINDIR) valgrind \ - --tool=memcheck \ - --leak-check=full \ - --show-leak-kinds=all \ - --track-origins=yes \ - --show-reachable=yes \ - --verbose --log-file="valgrind.log" \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p rife -m 4 --rife-model rife-v4.6 \ - -e preset=veryfast -e crf=30 - -heaptrack-realesrgan: - LD_LIBRARY_PATH=$(BINDIR) HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p realesrgan -s 4 --realesrgan-model realesr-animevideov3 \ - -e preset=veryfast -e crf=30 - -heaptrack-realcugan: - LD_LIBRARY_PATH=$(BINDIR) HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p realcugan -s 4 -n 0 --realcugan-model models-se \ - -e preset=veryfast -e crf=30 - -heaptrack-libplacebo: - LD_LIBRARY_PATH=$(BINDIR) HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p libplacebo -w 1920 -h 1080 --libplacebo-shader anime4k-v4-a \ - -e preset=veryfast -e crf=30 - -heaptrack-rife: - LD_LIBRARY_PATH=$(BINDIR) HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \ - $(BINDIR)/video2x \ - -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \ - -p rife -m 4 --rife-model rife-v4.6 \ - -e preset=veryfast -e crf=30 diff --git a/third_party/librealcugan_ncnn_vulkan b/third_party/librealcugan_ncnn_vulkan index 52f5982..97faecb 160000 --- a/third_party/librealcugan_ncnn_vulkan +++ b/third_party/librealcugan_ncnn_vulkan @@ -1 +1 @@ -Subproject commit 52f598265a973fc8b17eb5e13cddc0e71c0a79dc +Subproject commit 97faecb22d2c32d9bbd9478e726b1add6eabcf9c diff --git a/third_party/librealesrgan_ncnn_vulkan b/third_party/librealesrgan_ncnn_vulkan index 7966e68..95ce7b8 160000 --- a/third_party/librealesrgan_ncnn_vulkan +++ b/third_party/librealesrgan_ncnn_vulkan @@ -1 +1 @@ -Subproject commit 7966e68979ab9c002d10f9bfa507bd25e551b377 +Subproject commit 95ce7b81685a5a324c347df60f16ce96a1dd6e50 diff --git a/third_party/librife_ncnn_vulkan b/third_party/librife_ncnn_vulkan index b3b2ce8..8bdf0a5 160000 --- a/third_party/librife_ncnn_vulkan +++ b/third_party/librife_ncnn_vulkan @@ -1 +1 @@ -Subproject commit b3b2ce899011fa7940178163f0b4a3ebc251a934 +Subproject commit 8bdf0a596d8562f909cea96d5816460d8bf7e024