ultravideo / kvazaar

An open-source HEVC encoder
BSD 3-Clause "New" or "Revised" License
838 stars 181 forks source link

cannot link library FFMpeg on Windows #350

Open hamlatzis opened 2 years ago

hamlatzis commented 2 years ago

I have build the library using visual studio and now I want to use it in ffmpeg

Downloaded the source code of ffmpeg and according to documentation for Windows I have to build it under msys2 I can configure ffmpeg and successfully build everything when not enabling kvazaar; but when I try this

../../configure --toolchain=msvc --arch=x86_64 --enable-shared --enable-static --enable-cross-compile --enable-libkvazaar --target-os=win32 --extra-cflags="-MD -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WIN32_WINNT=0x0A00" --extra-ldflags="-APPCONTAINER WindowsApp.lib" --prefix=../../Build/Windows10

I get "ERROR: kvazaar >= 0.8.1 not found using pkg-config", which I think is logical since under windows there is no package file

fador commented 2 years ago

It might be related to the issue with pkg-config that also prevents me from building ffmpeg using the media-autobuild suite: https://github.com/m-ab-s/media-autobuild_suite/issues/2298 The pkg-config should work in msys2 just fine.

hamlatzis commented 2 years ago

It might be related to the issue with pkg-config that also prevents me from building ffmpeg using the media-autobuild suite: m-ab-s/media-autobuild_suite#2298 The pkg-config should work in msys2 just fine.

ok, but as far as I know VS doesn't create pkg-config ".pc" files, So what's the solution?

fador commented 2 years ago

oh right, I didn't realise that, but you can basically just create it manually from src/kvazaar.pc.in 😅

Typically in linux kvazaar.pc looks like:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
incdir=${prefix}/include

Name: libkvazaar
Description: Open-source HEVC encoder
Version: 2.1.0
Libs: -L${libdir} -lkvazaar
Libs.private: -lpthread -lm   -lrt
Cflags: -I${incdir}
fador commented 2 years ago

So I was messing around with things a bit and the proper way to do this might be to build Kvazaar also in msys2.

Since our scripts are not really built for msvc, you need to sed some stuff to make it compatible. Here's how I could do a static build, running this as kvazaar.sh (assuming you have the msvc ready in the system):

sed -i 's/-Wall -Wextra -Wvla -Wno-sign-compare -Wno-unused-parameter//g' configure.ac
sed -i 's/ -ftree-vectorize -fvisibility=hidden//g' configure.ac
sed -i 's/KVZ_CFLAGS=\"/KVZ_CFLAGS=\"-DKVZ_STATIC_LIB -I.\/threadwrapper\/include\/ -I ..\/include\//g' configure.ac
sed -i 's/-I\$srcdir\/src/-I ./g' configure.ac

sed -i 's/AX_PTHREAD(/#AX_PTHREAD(/g' configure.ac
sed -i 's/PTHREAD_CFLAGS=-pthread//g' configure.ac
sed -i 's/PTHREAD_LIBS=-lpthread//g' configure.ac
sed -i 's/libkvazaar_la_SOURCES =/libkvazaar_la_SOURCES = \\\n\tthreadwrapper\/src\/pthread.cpp \\\n\tthreadwrapper\/src\/semaphore.cpp/g' src/Makefile.am
sed -i 's/kvazaar_SOURCES =/kvazaar_SOURCES = extras\/getopt.c /g' src/Makefile.am
sed -i 's/CFLAGS=\"\$PTHREAD_CFLAGS \$CFLAGS\"/CPPFLAGS=\"\$CFLAGS\"/g' configure.ac
sed -i 's/CC=\"\$PTHREAD_CC\"//g' configure.ac

./autogen.sh
LD=link.exe CC=cl ./configure --enable-static
make
make install

..for shared build just remove the --enable-static and change -DKVZ_STATIC_LIB to -DKVZ_DLL_EXPORTS

I hope this helps

fador commented 2 years ago

Here's a full code to compile Kvazaar + ffmpeg in msys2: https://gist.github.com/fador/19c4eee37a0cfd80dcc01434bbea8765

hamlatzis commented 2 years ago

@fador it worked like a charm, tried both methods (manually and the scripts you've provided)

pinbraerts commented 1 year ago

Workaround the pkg-config on MinGW: --pkg-config=true --extra-cflags="-I$PATH_TO_KVAZAAR_INCLUDES -DKVZ_STATIC_LIB" --extra-ldflags="-libpath:$PATH_TO_KVAZAAR_LIBS kvazaar.lib"

vtorri commented 6 months ago

isn't this bug resolved ? I have no problem with mingw, ffmpeg is built with kvazaar support