barndawgie / ffmpeg-cross-compile-script

A script to cross-compile FFmpeg for Windows
MIT License
7 stars 3 forks source link

AV1 encoder and decoder #9

Closed Aleksid1 closed 2 months ago

Aleksid1 commented 3 months ago

Hi, Please can you add example for downloading/compiling dav1d and libsvtav1 libs?

barndawgie commented 3 months ago

Will try to take a look but it might be a couple of weeks.

Aleksid1 commented 3 months ago

I would be very grateful to you! There is another simple FFmpeg script, but it only compiles for Mac and Linux: https://github.com/markus-perl/ffmpeg-build-script It includes support for dav1d and libsvtav1 libs. If it possible, please add examples for Intel QSV and AMD AMF encoders.

barndawgie commented 2 months ago

libdav1d was pretty easy. Check out: https://github.com/barndawgie/ffmpeg-cross-compile-script/pull/11

    do_git_checkout $dav1d_git $dav1d_version dav1d
    pushd dav1d || exit
    meson setup build --cross-file=package/crossfiles/x86_64-w64-mingw32.meson --default-library=static --prefix=$prefix
    cd ./build || exit
    ninja
    ninja install
    popd || exit

libsvtav1 looks more complicated as there isn't cross-compile documentation and it has some undeclared dependencies; I will see if I can figure it out.

Aleksid1 commented 2 months ago

I'll check dav1d today later. Thanks! I saw libsvtav1 support in another script for Mac/Linux: https://github.com/markus-perl/ffmpeg-build-script/blob/master/build-ffmpeg

if build "svtav1" "2.0.0"; then
  # Last known working commit which passed CI Tests from HEAD branch
  download "https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v$CURRENT_PACKAGE_VERSION/SVT-AV1-v$CURRENT_PACKAGE_VERSION.tar.gz" "svtav1-$CURRENT_PACKAGE_VERSION.tar.gz"
  cd "${PACKAGES}"/svtav1-$CURRENT_PACKAGE_VERSION//Build/linux || exit
  execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../.. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
  execute make -j $MJOBS
  execute make install
  execute cp SvtAv1Enc.pc "${WORKSPACE}/lib/pkgconfig/"
  execute cp SvtAv1Dec.pc "${WORKSPACE}/lib/pkgconfig/"
  build_done "svtav1" $CURRENT_PACKAGE_VERSION
fi
CONFIGURE_OPTIONS+=("--enable-libsvtav1")
barndawgie commented 2 months ago

I'll check dav1d today later. Thanks!

I saw libsvtav1 support in another script for Mac/Linux:

https://github.com/markus-perl/ffmpeg-build-script/blob/master/build-ffmpeg


if build "svtav1" "2.0.0"; then

  # Last known working commit which passed CI Tests from HEAD branch

  download "https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v$CURRENT_PACKAGE_VERSION/SVT-AV1-v$CURRENT_PACKAGE_VERSION.tar.gz" "svtav1-$CURRENT_PACKAGE_VERSION.tar.gz"

  cd "${PACKAGES}"/svtav1-$CURRENT_PACKAGE_VERSION//Build/linux || exit

  execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../.. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release

  execute make -j $MJOBS

  execute make install

  execute cp SvtAv1Enc.pc "${WORKSPACE}/lib/pkgconfig/"

  execute cp SvtAv1Dec.pc "${WORKSPACE}/lib/pkgconfig/"

  build_done "svtav1" $CURRENT_PACKAGE_VERSION

fi

CONFIGURE_OPTIONS+=("--enable-libsvtav1")

This is more or less what I had, but it wouldn't link due to a missing cpuinfo dependency which I need to investigate. Hopefully that can either be disable or added to the script as well.

Aleksid1 commented 2 months ago

dav1d as AV1 decoder works fine now. Many thanks! Hope that you'll find a solution for libsvtav1

barndawgie commented 2 months ago

I think I got libsvtav1 working this morning - will try to get it cleaned up and into the PR this evening.

May I ask what the reason is to prefer libstvav1 vs. libaom?

Aleksid1 commented 2 months ago

Glad you had success with libsvtav1! I'll wait for the script. I discovered that libsvtav1 encodes faster than libaom. For libsvtav1 I found many advices regarding options to reach the best AV1 quality. And dav1d decodes much faster than libaom

barndawgie commented 2 months ago

Okay, just pushed an update to that PR which I think gets libsvtav1 working. I needed to build cpuinfo as well.

    do_git_checkout $libsvtav1_git $libsvtav1_version libsvtav1
    pushd libsvtav1 || exit
    cd Build/linux || exit
    ./build.sh -t "$config_dir/toolchain-x86_64-w64-mingw32.cmake" -p $prefix --static install
    popd || exit

Just running a full E2E test before I check it in to main.

Aleksid1 commented 2 months ago

Great! I just checked and libsvtav1 encoder works fine.

barndawgie commented 2 months ago

Great! I just checked and libsvtav1 encoder works fine.

There are a lot of build options for it that I didn't look at related to CPU optimizations - I'm hoping the default build is reasonable.

Aleksid1 commented 2 months ago

I'll compare a speed with BtbN FFmpeg build tomorrow.

Aleksid1 commented 2 months ago

I compared your FFmpeg build with libsvtav1 and BtbN build on Intel CPU 7-gen. Your version encodes slower than BtbN (69s vs 59s). I checked BtbN script for options in libsvtav1:

cmake -DCMAKE_TOOLCHAIN_FILE="$FFBUILD_CMAKE_TOOLCHAIN" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$FFBUILD_PREFIX" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_APPS=OFF -DENABLE_AVX512=ON ..

Probably this option is important: -DENABLE_AVX512=ON

How we can try the same option in your script?

barndawgie commented 2 months ago

Very straightforward. https://github.com/barndawgie/ffmpeg-cross-compile-script/pull/19 adds this, as well as Link Time Optimization. I'm just waiting for the build to succeed before checking it in.

Aleksid1 commented 2 months ago

I'll try it after the weekend. Thank you for your great support and responsiveness!