diff --git a/ffmpeg/cppbuild.sh b/ffmpeg/cppbuild.sh index 146e9d1357..061098f43b 100755 --- a/ffmpeg/cppbuild.sh +++ b/ffmpeg/cppbuild.sh @@ -7,9 +7,13 @@ if [[ -z "$PLATFORM" ]]; then exit fi -DISABLE="--disable-iconv --disable-opencl --disable-sdl2 --disable-bzlib --disable-lzma --disable-linux-perf --disable-xlib" +DISABLE="--disable-iconv --disable-sdl2 --disable-bzlib --disable-lzma --disable-linux-perf --disable-xlib" ENABLE="--enable-shared --enable-version3 --enable-runtime-cpudetect --enable-zlib --enable-libmp3lame --enable-libspeex --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-openssl --enable-libopenh264 --enable-libvpx --enable-libfreetype --enable-libharfbuzz --enable-libopus --enable-libxml2 --enable-libsrt --enable-libwebp --enable-libaom --enable-libsvtav1 --enable-libzimg" ENABLE_VULKAN="--enable-vulkan --enable-hwaccel=h264_vulkan --enable-hwaccel=hevc_vulkan --enable-hwaccel=av1_vulkan" +OPENCL_CONFIG="--disable-opencl" +OPENCL_CFLAGS="" +OPENCL_LDFLAGS="" +OPENCL_LIBS="" if [[ "$EXTENSION" == *gpl ]]; then # Enable GPLv3 modules @@ -56,7 +60,7 @@ FFMPEG_VERSION=8.1.2 # with the unsupported FFmpeg 8.1 Changelog hunk already removed. V4L2_REQUEST_PATCH=ffmpeg-v4l2-request-20847-ffmpeg-8.1.patch download https://www.nasm.us/pub/nasm/releasebuilds/$NASM_VERSION/nasm-$NASM_VERSION.tar.gz nasm-$NASM_VERSION.tar.gz -download https://zlib.net/$ZLIB.tar.gz $ZLIB.tar.gz +download https://github.com/madler/zlib/releases/download/v${ZLIB#zlib-}/$ZLIB.tar.gz $ZLIB.tar.gz download https://downloads.sourceforge.net/project/lame/lame/3.100/$LAME.tar.gz $LAME.tar.gz download https://ftp.osuosl.org/pub/xiph/releases/speex/$SPEEX.tar.gz $SPEEX.tar.gz download https://archive.mozilla.org/pub/opus/$OPUS.tar.gz $OPUS.tar.gz @@ -64,7 +68,7 @@ download https://sourceforge.net/projects/opencore-amr/files/opencore-amr/$OPENC download https://sourceforge.net/projects/opencore-amr/files/vo-amrwbenc/$VO_AMRWBENC.tar.gz/download $VO_AMRWBENC.tar.gz download https://www.openssl.org/source/$OPENSSL.tar.gz $OPENSSL.tar.gz download https://github.com/cisco/openh264/archive/v$OPENH264_VERSION.tar.gz openh264-$OPENH264_VERSION.tar.gz -download https://code.videolan.org/videolan/x264/-/archive/stable/$X264.tar.gz $X264.tar.gz +download https://github.com/mirror/x264/archive/refs/heads/stable.tar.gz $X264.tar.gz download https://github.com/videolan/x265/archive/$X265.tar.gz x265-$X265.tar.gz download https://github.com/webmproject/libvpx/archive/v$VPX_VERSION.tar.gz libvpx-$VPX_VERSION.tar.gz download https://ftp.osuosl.org/pub/blfs/conglomeration/alsa-lib/alsa-lib-$ALSA_VERSION.tar.bz2 alsa-lib-$ALSA_VERSION.tar.bz2 @@ -83,6 +87,35 @@ download https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2 ffmpeg-$FFMP mkdir -p $PLATFORM$EXTENSION cd $PLATFORM$EXTENSION INSTALL_PATH=`pwd` +case $PLATFORM in + linux-arm64 | linux-x86_64 | macosx-arm64 | macosx-x86_64 | windows-x86_64) + OPENCL_PATH="${BUILD_PATH:-$TOP_PATH/opencl/cppbuild/$PLATFORM}" + if [[ "$PLATFORM" == windows-* ]]; then + OPENCL_PATH="$(cygpath -u "$OPENCL_PATH")" + fi + OPENCL_CONFIG="--enable-opencl" + OPENCL_CFLAGS="-I$OPENCL_PATH/include" + OPENCL_LDFLAGS="-L$OPENCL_PATH/lib" + OPENCL_LIBS="-lOpenCL" + if [[ "$PLATFORM" == linux-* ]]; then + # The ICD loader install contains only its soname. FFmpeg's + # configure probes add -lOpenCL itself. + OPENCL_LINK_PATH="$TOP_PATH/ffmpeg/cppbuild/opencl-$PLATFORM$EXTENSION" + mkdir -p "$OPENCL_LINK_PATH" + ln -sf "$OPENCL_PATH/lib/libOpenCL.so.1" "$OPENCL_LINK_PATH/libOpenCL.so" + OPENCL_LDFLAGS="-L$OPENCL_LINK_PATH $OPENCL_LDFLAGS" + elif [[ "$PLATFORM" == macosx-* ]]; then + OPENCL_LIBS="-framework OpenCL" + elif [[ "$PLATFORM" == windows-* ]]; then + if [[ ! -f "$OPENCL_PATH/include/CL/cl_d3d11.h" ]]; then + echo "Error: OpenCL D3D11 sharing header not found: $OPENCL_PATH/include/CL/cl_d3d11.h" + exit 1 + fi + OPENCL_LIBS="-l:OpenCL.lib" + fi + ;; +esac +DISABLE="$DISABLE $OPENCL_CONFIG" echo "Decompressing archives..." tar --totals -xzf ../nasm-$NASM_VERSION.tar.gz tar --totals -xzf ../$ZLIB.tar.gz @@ -138,6 +171,10 @@ sedinplace 's/CMAKE_C_COMPILER_ID MATCHES "Clang"/FALSE/g' SVT-AV1-*/CMakeLists. sedinplace '/ANativeWindow_release/d' ffmpeg-*/libavutil/hwcontext_mediacodec.c sedinplace 's/#define MAX_SLICES 32/#define MAX_SLICES 256/g' ffmpeg-*/libavcodec/h264dec.h +if [[ "$PLATFORM" == macosx-* && "$OPENCL_CONFIG" == "--enable-opencl" ]]; then + export DYLD_LIBRARY_PATH="$OPENCL_PATH/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}" +fi + case $PLATFORM in android-arm) export AR="$ANDROID_PREFIX-ar" @@ -1136,7 +1173,7 @@ EOF make install cd .. cd ../ffmpeg-$FFMPEG_VERSION - LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-libdrm --enable-cuda --enable-cuvid --enable-nvenc --enable-pthreads --enable-libxcb --enable-libpulse --cc="gcc -m64" --cxx="g++ -m64" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -lpthread -ldl -lz -lm $LIBS" || cat ffbuild/config.log + LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-libdrm --enable-cuda --enable-cuvid --enable-nvenc --enable-pthreads --enable-libxcb --enable-libpulse --cc="gcc -m64" --cxx="g++ -m64" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1 $OPENCL_CFLAGS" --extra-ldflags="-L../lib/ $OPENCL_LDFLAGS" --extra-libs="-lstdc++ -lpthread -ldl -lz -lm $LIBS $OPENCL_LIBS" || cat ffbuild/config.log make -j $MAKEJ make install ;; @@ -1556,7 +1593,7 @@ EOF if [[ ! -d $USERLAND_PATH ]]; then USERLAND_PATH="$(which aarch64-linux-gnu-gcc | grep -o '.*/tools/')../userland" fi - LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-cuda --enable-cuvid --enable-nvenc --enable-omx `#--enable-mmal` --enable-omx-rpi --enable-pthreads --enable-libxcb --enable-libpulse --cc="aarch64-linux-gnu-gcc" --cxx="aarch64-linux-gnu-g++" --extra-cflags="$CFLAGS -I$USERLAND_PATH/ -I$USERLAND_PATH/interface/vmcs_host/khronos/IL/ -I$USERLAND_PATH/host_applications/linux/libs/bcm_host/include/ -I../include/ -I../include/libxml2 -I../include/mfx/ -I../include/svt-av1 -fno-aggressive-loop-optimizations" --extra-ldflags="-Wl,-z,relro -L$USERLAND_PATH/build/lib/ -L../lib/" --extra-libs="-lstdc++ -lasound -lvchiq_arm `#-lvcsm` -lvcos -lpthread -ldl -lz -lm" --enable-cross-compile --arch=arm64 --target-os=linux --cross-prefix="aarch64-linux-gnu-" || cat ffbuild/config.log + LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-cuda --enable-cuvid --enable-nvenc --enable-omx `#--enable-mmal` --enable-omx-rpi --enable-pthreads --enable-libxcb --enable-libpulse --cc="aarch64-linux-gnu-gcc" --cxx="aarch64-linux-gnu-g++" --extra-cflags="$CFLAGS -I$USERLAND_PATH/ -I$USERLAND_PATH/interface/vmcs_host/khronos/IL/ -I$USERLAND_PATH/host_applications/linux/libs/bcm_host/include/ -I../include/ -I../include/libxml2 -I../include/mfx/ -I../include/svt-av1 $OPENCL_CFLAGS -fno-aggressive-loop-optimizations" --extra-ldflags="-Wl,-z,relro -L$USERLAND_PATH/build/lib/ -L../lib/ $OPENCL_LDFLAGS" --extra-libs="-lstdc++ -lasound -lvchiq_arm `#-lvcsm` -lvcos -lpthread -ldl -lz -lm $OPENCL_LIBS" --enable-cross-compile --arch=arm64 --target-os=linux --cross-prefix="aarch64-linux-gnu-" || cat ffbuild/config.log make -j $MAKEJ make install ;; @@ -1970,7 +2007,7 @@ EOF cd .. cd ../ffmpeg-$FFMPEG_VERSION patch -Np1 < ../../../ffmpeg-macosx.patch - LDEXEFLAGS='-Wl,-rpath,@loader_path/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-pthreads --enable-indev=avfoundation --disable-libxcb --cc="clang -arch arm64" --cxx="clang++ -arch arm64" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -ldl -lz -lm" --enable-cross-compile --arch=arm64 --target-os=darwin || cat ffbuild/config.log + LDEXEFLAGS='-Wl,-rpath,@loader_path/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-pthreads --enable-indev=avfoundation --disable-libxcb --cc="clang -arch arm64" --cxx="clang++ -arch arm64" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1 $OPENCL_CFLAGS" --extra-ldflags="-L../lib/ $OPENCL_LDFLAGS" --extra-libs="-lstdc++ -ldl -lz -lm $OPENCL_LIBS" --enable-cross-compile --arch=arm64 --target-os=darwin || cat ffbuild/config.log make -j $MAKEJ make install ;; @@ -2110,7 +2147,7 @@ EOF cd .. cd ../ffmpeg-$FFMPEG_VERSION patch -Np1 < ../../../ffmpeg-macosx.patch - LDEXEFLAGS='-Wl,-rpath,@loader_path/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-pthreads --enable-indev=avfoundation --disable-libxcb --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -ldl -lz -lm" || cat ffbuild/config.log + LDEXEFLAGS='-Wl,-rpath,@loader_path/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-pthreads --enable-indev=avfoundation --disable-libxcb --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1 $OPENCL_CFLAGS" --extra-ldflags="-L../lib/ $OPENCL_LDFLAGS" --extra-libs="-lstdc++ -ldl -lz -lm $OPENCL_LIBS" || cat ffbuild/config.log make -j $MAKEJ make install ;; @@ -2416,7 +2453,12 @@ EOF make install cd .. cd ../ffmpeg-$FFMPEG_VERSION - PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-cuda --enable-cuvid --enable-nvenc --enable-libmfx --enable-w32threads --enable-indev=dshow --target-os=mingw32 --cc="gcc -m64" --cxx="g++ -m64" --extra-cflags="-DLIBXML_STATIC -I../include/ -I../include/libxml2 -I../include/mfx/ -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lgcc_eh -lWs2_32 -lcrypt32 -lpthread -lz -lm -Wl,-Bdynamic -lole32 -luuid" || cat ffbuild/config.log + PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-cuda --enable-cuvid --enable-nvenc --enable-libmfx --enable-w32threads --enable-indev=dshow --target-os=mingw32 --cc="gcc -m64" --cxx="g++ -m64" --extra-cflags="-DLIBXML_STATIC -I../include/ -I../include/libxml2 -I../include/mfx/ -I../include/svt-av1 $OPENCL_CFLAGS" --extra-ldflags="-L../lib/ $OPENCL_LDFLAGS" --extra-libs="-static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lgcc_eh -lWs2_32 -lcrypt32 -lpthread -lz -lm -Wl,-Bdynamic -lole32 -luuid $OPENCL_LIBS" || cat ffbuild/config.log + if ! grep -q "^#define HAVE_OPENCL_D3D11 1" config.h; then + echo "Error: FFmpeg configured OpenCL without D3D11 sharing support" + cat ffbuild/config.log + exit 1 + fi make -j $MAKEJ make install ;; diff --git a/ffmpeg/pom.xml b/ffmpeg/pom.xml index 109eda9ee6..ce08a22049 100644 --- a/ffmpeg/pom.xml +++ b/ffmpeg/pom.xml @@ -15,6 +15,12 @@ JavaCPP Presets for FFmpeg + + org.bytedeco + opencl + 3.1-${project.parent.version} + true + org.bytedeco javacpp @@ -32,6 +38,52 @@ org.bytedeco javacpp + + + org.bytedeco + opencl-platform + 3.1-${project.parent.version} + + + + + ${basedir}/../opencl/target/classes/ + ${project.build.outputDirectory} + + + ${basedir}/../opencl/target/classes/org/bytedeco/opencl/include/ + ${basedir}/../opencl/src/main/resources/org/bytedeco/opencl/include/ + ${basedir}/../opencl/cppbuild/${javacpp.platform}/include/ + ${basedir}/src/main/resources/org/bytedeco/ffmpeg/include/ + ${basedir}/cppbuild/${javacpp.platform}${javacpp.platform.extension}/include/ + + + ${basedir}/../opencl/cppbuild/${javacpp.platform}/lib/ + ${basedir}/cppbuild/${javacpp.platform}${javacpp.platform.extension}/lib/ + + + ${basedir}/../opencl/cppbuild/${javacpp.platform}/bin/ + ${basedir}/cppbuild/${javacpp.platform}${javacpp.platform.extension}/bin/ + + + /${javacpp.platform.library.path}/ + /org/bytedeco/opencl/${javacpp.platform}/ + + + /${javacpp.platform.library.path}/include/ + /org/bytedeco/opencl/include/ + /org/bytedeco/opencl/${javacpp.platform}/include/ + + + /${javacpp.platform.library.path}/ + /${javacpp.platform.library.path}/lib/ + /org/bytedeco/opencl/${javacpp.platform}/ + /org/bytedeco/opencl/${javacpp.platform}/lib/ + + + ${basedir}/cppbuild/${javacpp.platform}${javacpp.platform.extension}/ + + maven-jar-plugin