### Build Examples Configuration Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Conditionally builds example executables if AVIF_BUILD_EXAMPLES is enabled. It defines a list of example targets and iterates to add each as an executable, linking against the 'avif' and 'avif_enable_warnings' targets. ```cmake option(AVIF_BUILD_EXAMPLES "Build avif examples." OFF) if(AVIF_BUILD_EXAMPLES) set(AVIF_EXAMPLES avif_example_decode_memory avif_example_decode_file avif_example_decode_streaming avif_example_encode) foreach(EXAMPLE ${AVIF_EXAMPLES}) add_executable(${EXAMPLE} examples/${EXAMPLE}.c) if(AVIF_LIB_USE_CXX) set_target_properties(${EXAMPLE} PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(${EXAMPLE} avif avif_enable_warnings) endforeach() endif() ``` -------------------------------- ### Install Applications Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Installs the avifenc, avifdec, and avifgainmaputil executables to the runtime destination. This is conditional on NOT SKIP_INSTALL_APPS and NOT SKIP_INSTALL_ALL. ```cmake install( TARGETS avifenc avifdec avifgainmaputil RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) ``` -------------------------------- ### Install libavif on Windows with vcpkg Source: https://github.com/aomediacodec/libavif/blob/main/README.md Install the libavif library on Windows using the vcpkg package manager. ```sh vcpkg install libavif ``` -------------------------------- ### Install Libraries Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Installs the avif library (either shared or static) and exports CMake configuration files. This is conditional on NOT SKIP_INSTALL_LIBRARIES and NOT SKIP_INSTALL_ALL. ```cmake if(BUILD_SHARED_LIBS) set(LIBAVIF_INSTALL_TARGET avif) else() set(LIBAVIF_INSTALL_TARGET avif_static) endif() install( TARGETS ${LIBAVIF_INSTALL_TARGET} EXPORT ${PROJECT_NAME}-config RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) # Enable CMake configs in VCPKG mode if(BUILD_SHARED_LIBS OR VCPKG_TARGET_TRIPLET) install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) ``` -------------------------------- ### Build libavif with Installed Dependencies Source: https://github.com/aomediacodec/libavif/blob/main/README.md Use this method to link against already installed libraries like aom, libjpeg, libpng, and libyuv. Ensure these dependencies are available on your system before running. ```sh git clone -b v1.2.1 https://github.com/AOMediaCodec/libavif.git cmake -S libavif -B libavif/build -DAVIF_CODEC_AOM=SYSTEM -DAVIF_BUILD_APPS=ON cmake --build libavif/build --config Release --parallel ``` -------------------------------- ### ffprobe CICP Value Example Source: https://github.com/aomediacodec/libavif/wiki/CICP This example shows how ffprobe displays CICP values from a video, noting the MC/CP/TC ordering. It maps these values to their corresponding numerical representations. ```text yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67) ``` -------------------------------- ### Install libavif on MinGW MSYS2 Source: https://github.com/aomediacodec/libavif/blob/main/README.md Install the libavif package for the MSYS2 UCRT64 environment using pacman. ```sh pacman -S mingw-w64-ucrt-x86_64-libavif ``` -------------------------------- ### Install libavif on macOS with Homebrew Source: https://github.com/aomediacodec/libavif/blob/main/README.md Install the libavif library on macOS using the Homebrew package manager. ```sh brew install libavif ``` -------------------------------- ### Install libavif on Debian-based Linux Source: https://github.com/aomediacodec/libavif/blob/main/README.md Install the libavif development package on Debian-based Linux distributions using apt. ```sh sudo apt install libavif-dev ``` -------------------------------- ### Install libavif on Red Hat-based Linux Source: https://github.com/aomediacodec/libavif/blob/main/README.md Install the libavif library on Red Hat-based Linux distributions using yum. ```sh sudo yum -y install libavif ``` -------------------------------- ### Install libavif on macOS with MacPorts Source: https://github.com/aomediacodec/libavif/blob/main/README.md Install the libavif library on macOS using the MacPorts package manager. ```sh sudo port install libavif ``` -------------------------------- ### Video to AVIF with Filtering and Format Source: https://github.com/aomediacodec/libavif/wiki/Sequences Apply video filters like scaling and format conversion before encoding to AVIF. This example scales to 480x270 and uses a 10-bit YUV444p format. The dimensions, YUV format, and range are automatically detected by avifenc. ```bash ffmpeg -i src.mp4 -vf "scale=480:270, format=yuv444p10" -f yuv4mpegpipe -strict -1 - | avifenc --stdin --fps 30 dst.avif ``` -------------------------------- ### FuzzTest Setup and Flags Source: https://github.com/aomediacodec/libavif/blob/main/tests/CMakeLists.txt This command sets up the necessary flags for FuzzTest fuzzing. It is typically called after including the LocalFuzztest module. ```cmake fuzztest_setup_fuzzing_flags() ``` -------------------------------- ### Access OSS-Fuzz Docker Shell Source: https://github.com/aomediacodec/libavif/blob/main/tests/oss-fuzz/README.md Enter the Docker container for the libavif project to debug code or install necessary tools. ```sh python3 infra/helper.py shell libavif ``` -------------------------------- ### Enable Code Coverage Build Source: https://github.com/aomediacodec/libavif/blob/main/README.md Enable code coverage reporting by setting the `AVIF_ENABLE_COVERAGE` CMake option and building the `avif_coverage` target. Requires clang compiler and installed LLVM. ```cmake make avif_coverage -j ``` -------------------------------- ### Link Target Library for Build and Export Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Links a target library to 'avif_obj' for public build use and as an install link library for static linking consumers. It conditionally adds an install link library for static builds. ```cmake function(avif_target_link_library target) target_link_libraries(avif_obj PUBLIC $) get_target_property(target_is_local ${target} AVIF_LOCAL) if(target_is_local) return() endif() get_target_property(install_target ${target} IMPORTED_SONAME) if(NOT install_target) set(install_target ${target}) endif() # The transitive dependency needs to be an export link library in a static build. if(NOT BUILD_SHARED_LIBS) target_link_libraries(avif PUBLIC $) endif() endfunction() ``` -------------------------------- ### Conditional Test Setup for AVIF GTest Source: https://github.com/aomediacodec/libavif/blob/main/tests/CMakeLists.txt This block configures Google Tests for AVIF if the AVIF_GTEST option is enabled. It includes helper library setup and conditional test definitions. ```cmake if(AVIF_GTEST) check_avif_option(AVIF_GTEST TARGET GTest::GTest PKG_NAME GTest) add_library(avifincrtest_helpers OBJECT gtest/avifincrtest_helpers.cc) target_link_libraries(avifincrtest_helpers PUBLIC avif_internal) target_link_libraries(avifincrtest_helpers PRIVATE GTest::GTest avif_enable_warnings) endif() ``` -------------------------------- ### Configure AVIF GDK-Pixbuf Loader Source: https://github.com/aomediacodec/libavif/blob/main/contrib/gdk-pixbuf/CMakeLists.txt This CMake code configures the build for the AVIF GDK-Pixbuf loader. It checks for dependencies like PkgConfig and GDK-Pixbuf, defines build targets, and sets up installation paths. ```cmake option(AVIF_BUILD_GDK_PIXBUF "Build a gdk-pixbuf loader" OFF) if(AVIF_BUILD_GDK_PIXBUF) find_package(PkgConfig) if(PKG_CONFIG_FOUND) pkg_search_module(GDK_PIXBUF gdk-pixbuf-2.0) if(GDK_PIXBUF_FOUND) set(GDK_PIXBUF_SRCS loader.c) add_library(pixbufloader-avif MODULE ${GDK_PIXBUF_SRCS}) target_link_libraries(pixbufloader-avif PUBLIC ${GDK_PIXBUF_LIBRARIES} avif) target_link_directories(pixbufloader-avif PUBLIC ${GDK_PIXBUF_LIBRARY_DIRS}) target_include_directories(pixbufloader-avif SYSTEM PUBLIC ${GDK_PIXBUF_INCLUDE_DIRS}) pkg_get_variable(GDK_PIXBUF_MODULEDIR gdk-pixbuf-2.0 gdk_pixbuf_moduledir) string(REPLACE ${GDK_PIXBUF_PREFIX} ${CMAKE_INSTALL_PREFIX} GDK_PIXBUF_MODULEDIR ${GDK_PIXBUF_MODULEDIR}) install(TARGETS pixbufloader-avif DESTINATION ${GDK_PIXBUF_MODULEDIR}) configure_file(avif.thumbnailer.in ${CMAKE_CURRENT_BINARY_DIR}/avif.thumbnailer @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/avif.thumbnailer DESTINATION ${CMAKE_INSTALL_DATADIR}/thumbnailers) else() message(WARNING "gdk-pixbuf loader: disabled due to missing gdk-pixbuf-2.0") endif() else() message(WARNING "gdk-pixbuf loader: disabled due to missing pkg-config") endif() endif() ``` -------------------------------- ### Build Local Codecs (Optional) Source: https://github.com/aomediacodec/libavif/wiki/Coverage Build local codecs, such as AOM, if required. Navigate to the 'ext' directory and run the build script. ```bash cd ext $SHELL aom.cmd cd .. ``` -------------------------------- ### Build libavif from Scratch for Development Source: https://github.com/aomediacodec/libavif/blob/main/README.md This method is recommended for development and debugging purposes, as it builds all necessary components locally. It configures the build to use local versions of dependencies and sets the build type to Debug. ```sh git clone -b v1.2.1 https://github.com/AOMediaCodec/libavif.git cmake -S libavif -B libavif/build -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DAVIF_CODEC_AOM=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_JPEG=LOCAL -DAVIF_ZLIBPNG=LOCAL -DAVIF_BUILD_APPS=ON cmake --build libavif/build --config Debug --parallel ``` -------------------------------- ### Clone libavif Repository Source: https://github.com/aomediacodec/libavif/blob/main/android_jni/README.md Clone the libavif repository to your local machine. This is the first step in the build process. ```bash git clone https://github.com/AOMediaCodec/libavif.git cd libavif ``` -------------------------------- ### Build libavif with Tests and GoogleTest Source: https://github.com/aomediacodec/libavif/blob/main/README.md Enable building tests for libavif and integrate GoogleTest. Ensure GoogleTest is available either system-wide or locally. ```cmake AVIF_BUILD_TESTS AVIF_GTEST=SYSTEM ``` -------------------------------- ### Build Man Pages Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Configures the build process for man pages using pandoc. It finds the pandoc executable and generates man pages for avifenc and avifdec. ```cmake find_program(PANDOC_EXE pandoc) if(PANDOC_EXE) message(STATUS "libavif: Using pandoc: ${PANDOC_EXE}") else() message(FATAL_ERROR "libavif: Pandoc is missing, bailing out") endif() set(MAN_PAGES avifenc.1 avifdec.1) foreach(MAN_PAGE ${MAN_PAGES}) add_custom_command( OUTPUT ${MAN_PAGE} COMMAND ${PANDOC_EXE} -s -V "footer=libavif ${PROJECT_VERSION}" -f markdown -t man -o "${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE}" "${CMAKE_CURRENT_SOURCE_DIR}/doc/${MAN_PAGE}.md" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/doc/${MAN_PAGE}.md" VERBATIM ) endforeach() add_custom_target(man_pages ALL DEPENDS ${MAN_PAGES}) foreach(MAN_PAGE ${MAN_PAGES}) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE}" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1") endforeach() ``` -------------------------------- ### Set Android SDK and NDK Paths Source: https://github.com/aomediacodec/libavif/blob/main/android_jni/README.md Set the ANDROID_SDK_ROOT and ANDROID_NDK_HOME environment variables. Ensure you are using a compatible NDK revision (e.g., r25c). ```bash export ANDROID_SDK_ROOT="/path/to/android/sdk" export ANDROID_NDK_HOME="/path/to/android/ndk" ``` -------------------------------- ### Build OSS-Fuzz Image for libavif Source: https://github.com/aomediacodec/libavif/blob/main/tests/oss-fuzz/README.md Build the Docker image for the libavif project within the oss-fuzz environment. ```sh python3 infra/helper.py build_image libavif ``` -------------------------------- ### Enable AV1 Codec Dependency with CMake Source: https://github.com/aomediacodec/libavif/blob/main/README.md Enable a specific AV1 codec dependency (e.g., libaom) for local building or system installation using CMake flags. Ensure the chosen codec is compatible with your build requirements. ```cmake -DAVIF_CODEC_AOM=LOCAL ``` -------------------------------- ### Build libyuv Library for Android Source: https://github.com/aomediacodec/libavif/blob/main/android_jni/README.md Checkout and build the libyuv library for Android. This library is used for color space conversions and requires the NDK path. ```bash cd ext ./libyuv_android.sh "${ANDROID_NDK_HOME}" cd .. ``` -------------------------------- ### Build avifgainmaputil Application Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Defines the avifgainmaputil executable with a list of C++ source files and links it with necessary libraries. Includes platform-specific source files for Windows manifests or resource scripts. ```cmake set(AVIFGAINMAPUTIL_SRCS apps/avifgainmaputil/avifgainmaputil.cc apps/avifgainmaputil/convert_command.cc apps/avifgainmaputil/combine_command.cc apps/avifgainmaputil/extractgainmap_command.cc apps/avifgainmaputil/imageio.cc apps/avifgainmaputil/printmetadata_command.cc apps/avifgainmaputil/tonemap_command.cc apps/avifgainmaputil/program_command.cc apps/avifgainmaputil/swapbase_command.cc ) add_executable(avifgainmaputil "${AVIFGAINMAPUTIL_SRCS}") if(WIN32) if(MSVC) target_sources(avifgainmaputil PRIVATE apps/utf8.manifest) elseif(MINGW) target_sources(avifgainmaputil PRIVATE apps/utf8.rc) endif() endif() set_target_properties(avifgainmaputil PROPERTIES LINKER_LANGUAGE "CXX") target_link_libraries(avifgainmaputil libargparse avif_apps avif avif_enable_warnings) ``` -------------------------------- ### Configure and Build libavif with Coverage Source: https://github.com/aomediacodec/libavif/wiki/Coverage Build libavif with local codecs and coverage enabled. Tweak the CMake command line as appropriate for your system. ```bash mkdir build cd build cmake -G Ninja -DBUILD_SHARED_LIBS=0 -DAVIF_CODEC_AOM=1 -DAVIF_LOCAL_AOM=1 -DAVIF_ENABLE_COVERAGE=1 -DAVIF_BUILD_TESTS=1 .. ninja avif_coverage ``` -------------------------------- ### Build avifenc Application Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Defines the avifenc executable, linking it with necessary libraries. Includes platform-specific source files for Windows manifests or resource scripts. ```cmake add_executable(avifenc apps/avifenc.c) if(WIN32) if(MSVC) target_sources(avifenc PRIVATE apps/utf8.manifest) elseif(MINGW) # MinGW doesn't have a manifest tool (mt.exe), so we need to wrap # utf8.manifest in a resource-definition script (.rc file). target_sources(avifenc PRIVATE apps/utf8.rc) endif() endif() if(AVIF_LIB_USE_CXX) set_target_properties(avifenc PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(avifenc avif_apps avif avif_enable_warnings) ``` -------------------------------- ### Build aviftest Executable Source: https://github.com/aomediacodec/libavif/blob/main/tests/CMakeLists.txt Builds the `aviftest` executable from `aviftest.c`. It links against the `avif` library and `avif_enable_warnings`. ```cmake add_executable(aviftest aviftest.c) if(AVIF_CODEC_LIBGAV1_ENABLED OR AVIF_LIBYUV_ENABLED) set_target_properties(aviftest PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(aviftest avif avif_enable_warnings) add_test(NAME aviftest COMMAND aviftest ${CMAKE_CURRENT_SOURCE_DIR}/data) register_test_for_coverage(aviftest ${CMAKE_CURRENT_SOURCE_DIR}/data/) ``` -------------------------------- ### Build avifyuv Executable Source: https://github.com/aomediacodec/libavif/blob/main/tests/CMakeLists.txt Builds the `avifyuv` executable from `avifyuv.c`. It links against the `avif` library and `avif_enable_warnings`. ```cmake add_executable(avifyuv avifyuv.c) if(AVIF_CODEC_LIBGAV1_ENABLED OR AVIF_LIBYUV_ENABLED) set_target_properties(avifyuv PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(avifyuv avif avif_enable_warnings) foreach(AVIFYUV_MODE limited rgb) # Modes drift and premultiply take more than 2 minutes each so they are disabled. add_test(NAME avifyuv_${AVIFYUV_MODE} COMMAND avifyuv -m ${AVIFYUV_MODE}) endforeach() ``` -------------------------------- ### Check and Enable Build Options Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Checks a build option, enabling it if set to 'LOCAL' or 'SYSTEM' and the target is usable. It handles finding packages or including local CMake files based on the option's value. ```cmake macro(check_avif_option _VAR) set(_oneValueArgs TARGET PKG_NAME) cmake_parse_arguments(_AVIF_OPTION "" "${_oneValueArgs}" "" ${ARGN}) string(SUBSTRING ${_AVIF_OPTION_PKG_NAME} 0 1 FIRST_LETTER) string(TOUPPER ${FIRST_LETTER} FIRST_LETTER) string(REGEX REPLACE ".(.*)" "Local${FIRST_LETTER}\1" _LOCAL_INCLUDE "${_AVIF_OPTION_PKG_NAME}") set(${_VAR}_ENABLED OFF) if(${_VAR} STREQUAL "LOCAL" OR ${_VAR} STREQUAL "SYSTEM") if(${_VAR} STREQUAL "LOCAL" AND TARGET ${_AVIF_OPTION_TARGET}) message(ERROR "${_AVIF_OPTION_TARGET} is already defined and ${_VAR} should be set to SYSTEM to use it") return() endif() set(${_VAR}_ENABLED ON) if(NOT TARGET ${_AVIF_OPTION_TARGET}) if(${_VAR} STREQUAL "LOCAL") include(${_LOCAL_INCLUDE}) elseif(${_VAR} STREQUAL "SYSTEM") # QUIET instead of REQUIRED in order to use a custom error message below. find_package(${_AVIF_OPTION_PKG_NAME} QUIET) if(NOT ${_AVIF_OPTION_PKG_NAME}_FOUND) message( FATAL_ERROR "Cannot find ${_AVIF_OPTION_PKG_NAME}. Make sure it's installed on the system, or pass -D${_VAR}=LOCAL (to fetch and build it locally) or -D${_VAR}=OFF (to disable it)" ) endif() endif() endif() endif() endmacro() ``` -------------------------------- ### Check OSS-Fuzz Build Source: https://github.com/aomediacodec/libavif/blob/main/tests/oss-fuzz/README.md Verify the build of libavif fuzzers with a specified sanitizer within the oss-fuzz environment. ```sh python3 infra/helper.py check_build --sanitizer
libavif ``` -------------------------------- ### Build OSS-Fuzz Fuzzers for Coverage/Introspector Source: https://github.com/aomediacodec/libavif/blob/main/tests/oss-fuzz/README.md Compile fuzzers specifically for coverage and introspector reports on libavif. ```sh python3 infra/helper.py build_fuzzers --sanitizer libavif ``` -------------------------------- ### Build JNI Wrapper and Generate AAR Package Source: https://github.com/aomediacodec/libavif/blob/main/android_jni/README.md Build the JNI wrapper and generate the AAR package using Gradle. This command should be run from the android_jni directory. ```bash cd android_jni ./gradlew build assembleRelease ``` -------------------------------- ### Basic Video to AVIF Conversion Source: https://github.com/aomediacodec/libavif/wiki/Sequences Use this command for a straightforward conversion of a video file to an AVIF image sequence. The `-strict -1` flag enables higher bit-depth YUV formats. Ensure `--fps` matches your source. ```bash ffmpeg -i src.mp4 -f yuv4mpegpipe -strict -1 - | avifenc --stdin --fps 30 dst.avif ``` -------------------------------- ### Generate AVIF with idat Box Source: https://github.com/aomediacodec/libavif/blob/main/tests/data/README.md Use this command to generate an AVIF file using the 'idat' box for data storage. This is a standard way to create AVIF files with libavif. ```bash ./avifenc -q 100 ../tests/data/draw_points.png ../tests/data/draw_points_idat.avif ``` -------------------------------- ### Set ZLIBPNG Option Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Sets the ZLIBPNG build option, defaulting to 'SYSTEM'. If AVIF_ZLIBPNG is set to 'LOCAL', it includes the LocalZlibpng.cmake file. ```cmake set_local_or_system_option("ZLIBPNG" "SYSTEM" "Use zlib and libpng.") if(AVIF_ZLIBPNG STREQUAL "LOCAL") include(LocalZlibpng) endif() ``` -------------------------------- ### Add Executable for Image Comparison Source: https://github.com/aomediacodec/libavif/blob/main/tests/CMakeLists.txt Defines the `are_images_equal` executable, used for testing. It includes platform-specific manifest or resource files for Windows builds. ```cmake add_executable(are_images_equal gtest/are_images_equal.cc) if(WIN32) if(MSVC) target_sources(are_images_equal PRIVATE ${CMAKE_SOURCE_DIR}/apps/utf8.manifest) elseif(MINGW) target_sources(are_images_equal PRIVATE ${CMAKE_SOURCE_DIR}/apps/utf8.rc) endif() endif() target_link_libraries(are_images_equal aviftest_helpers avif_enable_warnings) ``` -------------------------------- ### Build libgav1 Decoder for Android Source: https://github.com/aomediacodec/libavif/blob/main/android_jni/README.md Alternatively, checkout and build the libgav1 decoder for Android using its script. This also requires the NDK path. ```bash cd ext ./libgav1_android.sh "${ANDROID_NDK_HOME}" cd .. ``` -------------------------------- ### Set LIBYUV Option Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Sets the LIBYUV build option, defaulting to 'SYSTEM'. ```cmake set_local_or_system_option("LIBYUV" "SYSTEM" "Use libyuv.") ``` -------------------------------- ### Check and Enable libyuv Support in libavif Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Checks if libyuv is available and meets the minimum version requirement (1755) for enabling libyuv-based fast paths in libavif. If the version is insufficient or unknown, the feature is disabled. ```cmake check_avif_option(AVIF_LIBYUV TARGET yuv::yuv PKG_NAME libyuv) if(AVIF_LIBYUV_ENABLED) if(NOT LIBYUV_VERSION) message(STATUS "libavif: libyuv found, but version unknown; libyuv-based fast paths disabled.") unset(AVIF_LIBYUV_ENABLED) elseif(LIBYUV_VERSION LESS 1755) message(STATUS "libavif: libyuv (${LIBYUV_VERSION}) found, but is too old; libyuv-based fast paths disabled.") unset(AVIF_LIBYUV_ENABLED) else() message(STATUS "libavif: libyuv (${LIBYUV_VERSION}) found; libyuv-based fast paths enabled.") if(LIBYUV_VERSION LESS 1813) message(STATUS "libavif: some libyuv optimizations require at least version 1813 to work.") endif() endif() endif() if(AVIF_LIBYUV_ENABLED) target_compile_definitions(avif_obj PRIVATE -DAVIF_LIBYUV_ENABLED=1) avif_target_link_library(yuv::yuv) set(AVIF_PKG_CONFIG_EXTRA_LIBS_PRIVATE "${AVIF_PKG_CONFIG_EXTRA_LIBS_PRIVATE} -lyuv") set(AVIF_LIB_USE_CXX ON) endif(AVIF_LIBYUV_ENABLED) ``` -------------------------------- ### Add Include Directories Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Configures include directories for the 'avif_obj' target. It adds build interface include directories and private include directories for third-party libraries like libyuv and ComplianceWarden if not explicitly disabled or enabled. ```cmake target_include_directories(avif_obj PUBLIC $) if(NOT AVIF_LIBYUV_ENABLED) target_include_directories(avif_obj PRIVATE ${libavif_SOURCE_DIR}/third_party/libyuv/include/) endif() if(AVIF_ENABLE_COMPLIANCE_WARDEN) target_include_directories(avif_obj PRIVATE ${libavif_SOURCE_DIR}/ext/ComplianceWarden/src/utils/) endif() ``` -------------------------------- ### Create FuzzTest Helper Library Source: https://github.com/aomediacodec/libavif/blob/main/tests/CMakeLists.txt This creates an OBJECT library for fuzz test helper functions to ensure they are compiled only once. It links against aviftest_helpers and FuzzTest. ```cmake add_library(avif_fuzztest_helpers OBJECT gtest/avif_fuzztest_helpers.cc) target_link_libraries(avif_fuzztest_helpers PUBLIC aviftest_helpers) link_fuzztest(avif_fuzztest_helpers) ``` -------------------------------- ### Generate AVIF with idat Box and Zero Meta Size Source: https://github.com/aomediacodec/libavif/blob/main/tests/data/README.md This command generates an AVIF file using the 'idat' box and sets the meta size to zero. This is achieved by uncommenting a specific line in the libavif source before encoding. ```bash ./avifenc -q 100 ../tests/data/draw_points.png ../tests/data/draw_points_idat_metasize0.avif ``` -------------------------------- ### Macro for Adding avif_apps Libraries Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt A CMake macro to simplify the creation of 'avif_apps' static libraries. It handles adding sources, linking dependencies (including conditional linking for LibXml2), and setting include directories. ```cmake macro(add_avif_apps_library suffix) add_library(avif_apps${suffix} STATIC ${AVIF_APPS_SRCS}) target_link_libraries(avif_apps${suffix} PUBLIC avif${suffix} PRIVATE PNG::PNG ZLIB::ZLIB JPEG::JPEG avif_enable_warnings) if(NOT WIN32 AND NOT APPLE) target_link_libraries(avif_apps${suffix} PRIVATE m) endif() if(AVIF_ENABLE_JPEG_GAIN_MAP_CONVERSION) target_link_libraries(avif_apps${suffix} PRIVATE LibXml2::LibXml2) endif() target_include_directories(avif_apps${suffix} INTERFACE apps/shared) # In GitHub CI's macos-latest os image, /usr/local/include has not only the headers of libpng # and libjpeg but also the headers of an older version of libavif. Put the avif include # directory before ${PNG_PNG_INCLUDE_DIR} ${JPEG_INCLUDE_DIR} to prevent picking up old libavif # headers from /usr/local/include. target_include_directories(avif_apps${suffix} PRIVATE third_party/iccjpeg) target_include_directories(avif_apps${suffix} SYSTEM PRIVATE ${PNG_PNG_INCLUDE_DIR} ${JPEG_INCLUDE_DIR}) endmacro() ``` -------------------------------- ### Build aviftest_helpers Library Source: https://github.com/aomediacodec/libavif/blob/main/tests/CMakeLists.txt Builds an object library `aviftest_helpers` from `gtest/aviftest_helpers.cc`. This library is intended for use with GoogleTest. ```cmake add_library(aviftest_helpers OBJECT gtest/aviftest_helpers.cc) target_link_libraries(aviftest_helpers PUBLIC avif_apps_internal avif_internal) target_link_libraries(aviftest_helpers PRIVATE avif_enable_warnings) ``` -------------------------------- ### Two-Step Video to AVIF Conversion (No Pipe) Source: https://github.com/aomediacodec/libavif/wiki/Sequences Convert video to an intermediate YUV4MPEG2 file first, then encode to AVIF. This method avoids using pipes and is useful for debugging, as Y4M files can be played directly by players like VLC. ```bash ffmpeg -i src.mp4 -strict -1 tmp.y4m avifenc --fps 30 tmp.y4m dst.avif ``` -------------------------------- ### Enable Testing Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Enables testing for the project using ctest. Includes a custom command to copy the avif.dll to the tests binary directory on Windows for convenience. ```cmake enable_testing() # Allow ctest to be called from top-level directory. # An executable on Windows searches for DLLs it is linked with in the same # directory where it resides and in the directories listed in the Path # environment variable. For convenience, copy avif.dll to the tests binary # directory to allow are_images_equal.exe and the test programs find it. if(WIN32 AND BUILD_SHARED_LIBS) add_custom_command( TARGET avif POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$" ${CMAKE_CURRENT_BINARY_DIR}/tests COMMENT "Copying avif.dll to the tests binary directory" ) endif() add_subdirectory(tests) ``` -------------------------------- ### Generate Progressive AVIF with idat Box and Zero Meta Size Source: https://github.com/aomediacodec/libavif/blob/main/tests/data/README.md This command generates a progressive AVIF file using the 'idat' box with the meta size set to zero. This configuration is achieved by modifying the libavif source before encoding. ```bash ./avifenc -q 100 --progressive ../tests/data/draw_points.png ../tests/data/draw_points_idat_progressive_metasize0.avif ``` -------------------------------- ### Run Connected Android Tests Source: https://github.com/aomediacodec/libavif/blob/main/android_jni/README.md Execute connected Android tests to verify the JNI bindings. Ensure the library is built and a device/emulator is available. ```bash cd android_jni ./gradlew connectedAndroidTest ``` -------------------------------- ### Build avifdec Application Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Defines the avifdec executable, linking it with necessary libraries. Includes platform-specific source files for Windows manifests or resource scripts. ```cmake add_executable(avifdec apps/avifdec.c) if(WIN32) if(MSVC) target_sources(avifdec PRIVATE apps/utf8.manifest) elseif(MINGW) target_sources(avifdec PRIVATE apps/utf8.rc) endif() endif() if(AVIF_LIB_USE_CXX) set_target_properties(avifdec PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(avifdec avif_apps avif avif_enable_warnings) ``` -------------------------------- ### Create and Push Git Tag Source: https://github.com/aomediacodec/libavif/wiki/Release-Checklist Clones the repository, creates a new annotated tag for the release, and pushes the tag to the remote repository. ```sh git clone https://github.com/AOMediaCodec/libavif.git libavif_tag cd libavif_tag git tag v6.7.8 -a -m v6.7.8 git push origin tag v6.7.8 ``` -------------------------------- ### Build dav1d Decoder for Android Source: https://github.com/aomediacodec/libavif/blob/main/android_jni/README.md Checkout and build the dav1d decoder for Android using the provided script. This script requires the NDK path to be set. ```bash cd ext ./dav1d_android.sh "${ANDROID_NDK_HOME}" cd .. ``` -------------------------------- ### Main avif Library Configuration Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Configures the main 'avif' library target, setting version, linking dependencies, and managing include directories. It also handles conditional compilation for shared libraries and C++ linking. ```cmake set_target_properties(avif PROPERTIES VERSION ${LIBRARY_VERSION} SOVERSION ${LIBRARY_SOVERSION}) target_link_libraries(avif PRIVATE avif_obj) target_include_directories( avif PUBLIC $ $ ) if(BUILD_SHARED_LIBS) target_compile_definitions(avif INTERFACE AVIF_DLL) if(AVIF_LIB_USE_CXX) set_target_properties(avif PROPERTIES LINKER_LANGUAGE "CXX") endif() endif() ``` -------------------------------- ### Compress PNG to AVIF Source: https://github.com/aomediacodec/libavif/blob/main/doc/avifenc.1.md Compress a PNG file to an AVIF file using the avifenc command. ```bash avifenc input.png output.avif ``` -------------------------------- ### Set JPEG Option Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Sets the JPEG build option, defaulting to 'SYSTEM'. If AVIF_JPEG is set to 'LOCAL', it includes the LocalJpeg.cmake file. ```cmake set_local_or_system_option("JPEG" "SYSTEM" "Use jpeg.") if(AVIF_JPEG STREQUAL "LOCAL") include(LocalJpeg) endif() ``` -------------------------------- ### Build OSS-Fuzz Fuzzers Source: https://github.com/aomediacodec/libavif/blob/main/tests/oss-fuzz/README.md Compile the fuzzers for libavif using a specified sanitizer (e.g., address, memory, undefined). ```sh python3 infra/helper.py build_fuzzers --sanitizer
libavif ``` -------------------------------- ### Enable C++ Standard for Build Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Enables the C++ language and sets the standard to C++17 if C++ is required for building applications, tests, or fuzzing. ```cmake if(AVIF_LIB_USE_CXX OR AVIF_BUILD_APPS OR (AVIF_BUILD_TESTS AND (AVIF_FUZZTEST OR AVIF_GTEST))) enable_language(CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() ``` -------------------------------- ### Main avif_apps Library Definition Source: https://github.com/aomediacodec/libavif/blob/main/CMakeLists.txt Defines the main static library 'avif_apps' which includes shared application source files. It links against the main 'avif' library and other required dependencies like PNG, ZLIB, and JPEG. Include directories for shared apps and internal headers are managed. ```cmake # Main avif_apps library. add_avif_apps_library("") # avif_apps_internal is to use when linking to avif_internal. if(BUILD_SHARED_LIBS) add_avif_apps_library(_internal) else() add_library(avif_apps_internal ALIAS avif_apps) endif() ``` -------------------------------- ### Generate Progressive AVIF with idat Box Source: https://github.com/aomediacodec/libavif/blob/main/tests/data/README.md This command generates a progressive AVIF file using the 'idat' box. Progressive encoding allows the image to be displayed gradually as it downloads. ```bash ./avifenc -q 100 --progressive ../tests/data/draw_points.png ../tests/data/draw_points_idat_progressive.avif ``` -------------------------------- ### Add Audio Track to AVIF with MP4Box Source: https://github.com/aomediacodec/libavif/blob/main/tests/data/README.md Use MP4Box to add an audio track to an existing AVIF file. Ensure the audio file is compatible and of the correct duration. ```bash MP4Box -add audio.aac colors-animated-8bpc-audio.avif ``` -------------------------------- ### Generate PNG with Points and Transparency Source: https://github.com/aomediacodec/libavif/blob/main/tests/data/README.md This command uses ImageMagick to create a PNG image with specific pixel colors and transparency. It's useful for testing PNG encoding with transparency and palette color types. ```bash convert -size 3x1 xc:red -alpha on -fill '#00F8' \ -draw 'point 1,0' \ -draw 'color 2,0 point' -scale 33x33 draw_points.png ```