TianZerL / Anime4KCPP

A high performance anime upscaler
GNU General Public License v3.0
1.79k stars 137 forks source link

build Vapoursynth plugin under Linux #26

Closed DeadNews closed 4 years ago

DeadNews commented 4 years ago
~/my/downloads >>> git clone https://github.com/TianZerL/Anime4KCPP && \                        
cd ./Anime4KCPP && \
export CPATH=/usr/include/vapoursynth && \
cmake . -D Build_VapourSynth_plugin=ON -D Build_GUI=OFF -D Build_CLI=OFF && \
make

Cloning into 'Anime4KCPP'...
remote: Enumerating objects: 116, done.
remote: Counting objects: 100% (116/116), done.
remote: Compressing objects: 100% (76/76), done.
remote: Total 1227 (delta 33), reused 89 (delta 28), pack-reused 1111
Receiving objects: 100% (1227/1227), 4.26 MiB | 6.91 MiB/s, done.
Resolving deltas: 100% (632/632), done.
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Check for working C compiler: /bin/cc
-- Check for working C compiler: /bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /bin/c++
-- Check for working CXX compiler: /bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr (found version "4.3.0") 
-- Looking for CL_VERSION_2_2
-- Looking for CL_VERSION_2_2 - found
-- Found OpenCL: /usr/lib/libOpenCL.so (found version "2.2") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/deadnews/my/downloads/Anime4KCPP
Scanning dependencies of target Anime4KCPPCore
[  3%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/ACNet.cpp.o
[  7%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/ACNetHDN.cpp.o
[ 11%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/Anime4K.cpp.o
[ 14%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/Anime4KCPP.cpp.o
[ 18%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/Anime4KCPU.cpp.o
[ 22%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/Anime4KCPUCNN.cpp.o
[ 25%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/Anime4KGPU.cpp.o
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPU.cpp: In static member function ‘static void Anime4KCPP::Anime4KGPU::initOpenCL()’:
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPU.cpp:552:73: warning: ‘_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)’ is deprecated [-Wdeprecated-declarations]
  552 |             commandQueue = clCreateCommandQueue(context, device, 0, &err);
      |                                                                         ^
In file included from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/include/Anime4KGPU.h:11,
                 from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPU.cpp:3:
/usr/include/CL/cl.h:1443:1: note: declared here
 1443 | clCreateCommandQueue(cl_context                     /* context */,
      | ^~~~~~~~~~~~~~~~~~~~
[ 29%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/Anime4KGPUCNN.cpp.o
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPUCNN.cpp: In static member function ‘static void Anime4KCPP::Anime4KGPUCNN::initOpenCL(Anime4KCPP::CNNType)’:
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPUCNN.cpp:842:73: warning: ‘_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)’ is deprecated [-Wdeprecated-declarations]
  842 |             commandQueue = clCreateCommandQueue(context, device, 0, &err);
      |                                                                         ^
In file included from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/include/Anime4KGPUCNN.h:12,
                 from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPUCNN.cpp:3:
/usr/include/CL/cl.h:1443:1: note: declared here
 1443 | clCreateCommandQueue(cl_context                     /* context */,
      | ^~~~~~~~~~~~~~~~~~~~
[ 33%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/CNN.cpp.o
[ 37%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/CNNProcessor.cpp.o
[ 40%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/VideoIO.cpp.o
[ 44%] Building CXX object Anime4KCore/CMakeFiles/Anime4KCPPCore.dir/src/filterprocessor.cpp.o
[ 48%] Linking CXX shared library ../bin/libAnime4KCPPCore.so
[ 48%] Built target Anime4KCPPCore
Scanning dependencies of target Anime4KCPP_VapourSynth
[ 51%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/src/Anime4KCPPVS.cpp.o                                                                                               
[ 55%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/ACNet.cpp.o                                                                                       
[ 59%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/ACNetHDN.cpp.o                                                                                    
[ 62%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/Anime4K.cpp.o                                                                                     
[ 66%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/Anime4KCPP.cpp.o                                                                                  
[ 70%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/Anime4KCPU.cpp.o                                                                                  
[ 74%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/Anime4KCPUCNN.cpp.o
[ 77%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/Anime4KGPU.cpp.o
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPU.cpp: In static member function ‘static void Anime4KCPP::Anime4KGPU::initOpenCL()’:
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPU.cpp:552:73: warning: ‘_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)’ is deprecated [-Wdeprecated-declarations]
  552 |             commandQueue = clCreateCommandQueue(context, device, 0, &err);
      |                                                                         ^
In file included from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/include/Anime4KGPU.h:11,
                 from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPU.cpp:3:
/usr/include/CL/cl.h:1443:1: note: declared here
 1443 | clCreateCommandQueue(cl_context                     /* context */,
      | ^~~~~~~~~~~~~~~~~~~~
[ 81%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/Anime4KGPUCNN.cpp.o
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPUCNN.cpp: In static member function ‘static void Anime4KCPP::Anime4KGPUCNN::initOpenCL(Anime4KCPP::CNNType)’:
/home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPUCNN.cpp:842:73: warning: ‘_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)’ is deprecated [-Wdeprecated-declarations]
  842 |             commandQueue = clCreateCommandQueue(context, device, 0, &err);
      |                                                                         ^
In file included from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/include/Anime4KGPUCNN.h:12,
                 from /home/deadnews/my/downloads/Anime4KCPP/Anime4KCore/src/Anime4KGPUCNN.cpp:3:
/usr/include/CL/cl.h:1443:1: note: declared here
 1443 | clCreateCommandQueue(cl_context                     /* context */,
      | ^~~~~~~~~~~~~~~~~~~~
[ 85%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/CNN.cpp.o
[ 88%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/CNNProcessor.cpp.o
[ 92%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/VideoIO.cpp.o
[ 96%] Building CXX object VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/__/Anime4KCore/src/filterprocessor.cpp.o
[100%] Linking CXX shared library ../bin/libAnime4KCPP_VapourSynth.so
/bin/ld: cannot find -lVapourSynth
collect2: error: ld returned 1 exit status
make[2]: *** [VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/build.make:339: bin/libAnime4KCPP_VapourSynth.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:246: VapourSynth/CMakeFiles/Anime4KCPP_VapourSynth.dir/all] Error 2
make: *** [Makefile:104: all] Error 2

OS: Manjaro

How build Vapoursynth plugin under Linux? «Solutions from google» didn't help me :)

TianZerL commented 4 years ago

Compilation was successful, but cmake can't find the lib of VapourSynth API, you may need to build VapourSynth of Linux first, or get a prebuild version of VapourSynth with SDK. Then you need to set -D VapourSynth_SDK_PATH = your sdk path And make sure that the directory structure of VapourSynth SDK is like

somepath
    - sdk
        - include
               -VapourSynth.h
        - lib64
              -libVapourSynth.a

cmake . -D Build_VapourSynth_plugin=ON -D Build_GUI=OFF -D Build_CLI=OFF -D VapourSynth_SDK_PATH = somepath/sdk

DeadNews commented 4 years ago

What do you mean by “VapourSynth SDK”? Vapoursynth installed from repo: https://www.archlinux.org/packages/community/x86_64/vapoursynth/

Package Contents: usr/ usr/bin/ usr/bin/vspipe usr/include/ usr/include/vapoursynth/ usr/include/vapoursynth/VSHelper.h usr/include/vapoursynth/VSScript.h usr/include/vapoursynth/VapourSynth.h usr/lib/ usr/lib/libvapoursynth-script.so usr/lib/libvapoursynth-script.so.0 usr/lib/libvapoursynth-script.so.0.0.0 usr/lib/libvapoursynth.so usr/lib/pkgconfig/ usr/lib/pkgconfig/vapoursynth-script.pc usr/lib/pkgconfig/vapoursynth.pc usr/lib/python3.8/ usr/lib/python3.8/site-packages/ usr/lib/python3.8/site-packages/vapoursynth.so usr/lib/vapoursynth/ usr/lib/vapoursynth/libeedi3.so usr/lib/vapoursynth/libimwri.so usr/lib/vapoursynth/libmiscfilters.so usr/lib/vapoursynth/libmorpho.so usr/lib/vapoursynth/libocr.so usr/lib/vapoursynth/libremovegrain.so usr/lib/vapoursynth/libsubtext.so usr/lib/vapoursynth/libvinverse.so usr/lib/vapoursynth/libvivtc.so usr/share/ usr/share/licenses/ usr/share/licenses/vapoursynth/ usr/share/licenses/vapoursynth/ofl.txt usr/share/mime/ usr/share/mime/packages/ usr/share/mime/packages/vapoursynth.xml

directory structure of VapourSynth SDK

There's no such directory structure.

VapourSynth.h

Without "export CPATH=/usr/include/vapoursynth" the build will end with error:

/home/deadnews/Anime4KCPP/VapourSynth/src/Anime4KCPPVS.cpp:2:10: fatal error: VapourSynth.h: No such file or directory
    2 | #include <VapourSynth.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.

It's kind of been resolved (thx to google).

libVapourSynth.a

There is no such file. There's "libvapoursynth.so". I tried with:

export LIBRARY_PATH=/usr/lib/ && \
export LD_LIBRARY_PATH=/usr/lib/ && \
export LDFLAGS="-L/usr/lib/" && \

But it's not helping...

TianZerL commented 4 years ago

This directory structure is what VapourSynth do in the Windows, in Linux, you may need to create a directory like that, and copy files to it, then specify VapourSynth_SDK_PATH

Create a dir like what I showed, then copy usr/lib/libvapoursynth.so and usr/include/vapoursynth/VapourSynth.h to the corresponding dir.

Specify VapourSynth_SDK_PATH to the dir.

DeadNews commented 4 years ago

I tried that (with copy of libvapoursynth.so). It's not helping.

TianZerL commented 4 years ago

I will test it in the Manjaro Linux. What's error info if try to link libvapoursynth.so

DeadNews commented 4 years ago

libAnime4KCPP_VapourSynth.so is not created with this error. If remove these lines from "./Anime4KCPP/cmake/ThirdPartyForVS.cmake":

target_link_directories(${PROJECT_NAME} PRIVATE ${VapourSynth_SDK_PATH}/lib64)
target_link_libraries(${PROJECT_NAME} VapourSynth)

Then libAnime4KCPP_VapourSynth.so is created.

What's error info if try to link libvapoursynth.so

Like that ~ >>> ld --library-path=/usr/lib --library=vapoursynth /home/deadnews/my/downloads/Anime4KCPP/bin/libAnime4KCPP_VapourSynth.so ? ld out: link

TianZerL commented 4 years ago

Then libAnime4KCPP_VapourSynth.so is created.

Does the libAnime4KCPP_VapourSynth.so work? The lines you removed will find the VapourSynth SDK lib then link it.
From your error info it looks like if your try to link a shard lib of VapourSynth, there are too many other libs need be linked.

DeadNews commented 4 years ago

Does the libAnime4KCPP_VapourSynth.so work?

Doesn't look like it.

src = core.anime4kcpp.Anime4KCPP(src = src, GPUMode = 1, ACNet = 1, zoomFactor = 2, HDN = 1)
File "src\cython\vapoursynth.pyx", line 1546, in vapoursynth.Core.__getattr__
AttributeError: No attribute with the name anime4kcpp exists. Did you mistype a plugin namespace?
TianZerL commented 4 years ago

I have just tested it, the problem is the file name. Copy usr/lib/libvapoursynth.so, then you need rename it to libVapourSynth.so or you need change the ./Anime4KCPP/cmake/ThirdPartyForVS.cmake to target_link_libraries(${PROJECT_NAME} vapoursynth)

TianZerL commented 4 years ago

Windows is not case sensitive, but Linux is. Finally just copy libAnime4KCPP_VapourSynth.so to /usr/lib/vapoursynth/, it works fine.

DeadNews commented 4 years ago

Well, then why not replace https://github.com/TianZerL/Anime4KCPP/blob/aab869bf42b06068995f4861044ffec9ec1e0c9b/cmake/ThirdPartyForVS.cmake#L5 with this target_link_libraries(${PROJECT_NAME} vapoursynth) ?

After this replacement, this works [1]. But the end result is the same as with manual linking:

src = core.anime4kcpp.Anime4KCPP(src = src, GPUMode = 1, ACNet = 1, zoomFactor = 2, HDN = 1)
File "src\cython\vapoursynth.pyx", line 1546, in vapoursynth.Core.__getattr__
AttributeError: No attribute with the name anime4kcpp exists. Did you mistype a plugin namespace?
TianZerL commented 4 years ago

copy libAnime4KCPP_VapourSynth.so to /usr/lib/vapoursynth/, then vapoursynth can find it

TianZerL commented 4 years ago

this is my test vpy, it works fine in Manjaro Linux:

import vapoursynth as vs
core = vs.get_core()
core.anime4kcpp.listGPUs()

My /usr/lib/vapoursynth/:

$ ls /usr/lib/vapoursynth/
libAnime4KCPP_VapourSynth.so  libeedi3.so  libimwri.so  libmiscfilters.so  libmorpho.so  libocr.so  libremovegrain.so  libsubtext.so  libvinverse.so  libvivtc.so
DeadNews commented 4 years ago

There's no mistake in the location of the file.

TianZerL commented 4 years ago

Your vapoursynth doesn't find libAnime4KCPP_VapourSynth.so. Make sure you didn't move other .so files or delete them. I mean, do not move or delete the sdk dir that you created.

DeadNews commented 4 years ago

Something else is required other than libAnime4KCPP_VapourSynth.so:

import vapoursynth as vs
core = vs.get_core()
core.std.LoadPlugin(path=r'/home/deadnews/my/bin/vpy-plugins/libAnime4KCPP_VapourSynth.so')

src = core.anime4kcpp.listGPUs()

File "src\cython\vapoursynth.pyx", line 1862, in vapoursynth.Function.__call__
vapoursynth.Error: Failed to load /home/deadnews/my/bin/vpy-plugins/libAnime4KCPPCore.so. Error given: libhdf5.so.200: cannot open shared object file: No such file or directory

First warning here:

ld: warning: libhdf5.so.200, needed by /usr/lib//libopencv_hdf.so.4.3, not found (try using -rpath or -rpath-link)
TianZerL commented 4 years ago

libAnime4KCPPCore.so is not required by libAnime4KCPP_VapourSynth.so, but camke will build it by default for CLI and GUI.

So, do not copy libAnime4KCPPCore.so to plugin dir of vapoursynth.

All you need is libAnime4KCPP_VapourSynth.so, and beacuse you linked it to libvapoursynth.so which is a shard lib, you need make sure libAnime4KCPP_VapourSynth.so can find it.

And what's that warning is? Its actually from OpenCV.

DeadNews commented 4 years ago

I copied the wrong output. It should have been:

core.std.LoadPlugin(path=r'/home/deadnews/my/bin/vpy-plugins/libAnime4KCPP_VapourSynth.so')
File "src\cython\vapoursynth.pyx", line 1862, in vapoursynth.Function.__call__
vapoursynth.Error: Failed to load /home/deadnews/my/bin/vpy-plugins/libAnime4KCPP_VapourSynth.so. Error given: libhdf5.so.200: cannot open shared object file: No such file or directory

Instead of this:

core.std.LoadPlugin(path=r'/home/deadnews/my/bin/vpy-plugins/libAnime4KCPPCore.so')
File "src\cython\vapoursynth.pyx", line 1862, in vapoursynth.Function.__call__
vapoursynth.Error: Failed to load /home/deadnews/my/bin/vpy-plugins/libAnime4KCPPCore.so. Error given: libhdf5.so.200: cannot open shared object file: No such file or directory
DeadNews commented 4 years ago

So, do not copy libAnime4KCPPCore.so to plugin dir of vapoursynth.

This does not change anything.

TianZerL commented 4 years ago

No such file or directory ? How could it be, I tried the same code, it just works. Does it have the right permissions, did you use root user to build it then it only can be readed by root?

DeadNews commented 4 years ago

it seems i just don't have:

hdf5 (optional) - for the HDF5 module and the Python bindings vtk (optional) - for the viz module

Because they are optional dependencies for opencv, and opencv was installed as a dependency for another package ...

TianZerL commented 4 years ago

well, I see. I install opencv by pacman directly, everything is fine. Maybe you need reinstall opencv.😂

DeadNews commented 4 years ago

After installing them, at first glance, everything works.