Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV should copy/install opencv_ffmpeg340_64.dll #2799

Closed
patrikhuber opened this issue Feb 14, 2018 · 11 comments · Fixed by #5169
Closed

OpenCV should copy/install opencv_ffmpeg340_64.dll #2799

patrikhuber opened this issue Feb 14, 2018 · 11 comments · Fixed by #5169
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@patrikhuber
Copy link
Contributor

As we found out in #2613, opencv_ffmpeg340_64.dll is not copied over to the build/install folder, and causes all operations in OpenCV that use ffmpeg to sort-of "silently" fail. For example, reading from the camera or from video files doesn't work unless the file is manually copied.

@jasjuang
Copy link
Contributor

I can try to figure this out in my free time.

@ras0219-msft
Copy link
Contributor

ras0219-msft commented Feb 14, 2018

I did a bit of investigation and determined the following:

  • The LoadLibrary call is inside the videoio component
  • You can actually run findstr /mrs "._.f.f.m.p.e.g.3.4.0._.6.4...d.l.l" *.exe and it will correctly identify applications which static link the videoio component (the name is UTF-16 encoded, thus the .s to match null bytes)

@patrikhuber
Copy link
Contributor Author

Hmm that's cool :D But how does it help us? Are you saying that vcpkg actually inspects the compiled executable, and then only copies the dll's that are necessary? So what you want to do is figure out after compilation whether an executable contains references to ffmpeg, and if so, copy the ffmpeg dll to the build/install directory?

@ras0219-msft
Copy link
Contributor

Yep, we do exactly that [1]!

figure out after compilation whether an executable contains references to ffmpeg

And that's plan A if it works. The current issue that I'm aware of is that findstr isn't exactly designed to search large binary files so it can fail with "line too long" errors (though none of my test cases hit this). I think the longer-term replacement would be for us to implement a small C++ utility in vcpkg that performs the search which won't have this problem (and might be faster).

[1] https:/Microsoft/vcpkg/blob/425d07ef7f82541e50cc8cb1e2716fc33bba7b12/scripts/buildsystems/msbuild/applocal.ps1

@KindDragon
Copy link
Contributor

Maybe use ripgrep? It supports UTF-16 and crossplatform https:/BurntSushi/ripgrep

@coderaper
Copy link

I want to add that another issue with opencv_ffmpeg340_64.dll is that the opencv[ffmpeg] package does not export opencv_ffmpeg library target at all. Therefore I cannot easily create workaround in my project by copying this target explicitly. Could you please export the opencv_ffmpeg target when opencv[ffmpeg] is built?

I think that grepping target dependent libraries for a strings which look like names of other shared libraries, and assume that they are potentially run-time loaded is a quite fragile approach. IMHO the right way is to use the available CMake mechanisms to accomplish this. I never used the shared library property IMPORTED_LINK_DEPENDENT_LIBRARIES, but it seems to me that this could be the right way to express that opencv_videoio library has dependency to opencv_ffmpeg library.

https://cmake.org/cmake/help/v3.10/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.html

Unfortunately, it seems that vcpkg does not copy automatically the libraries added to IMPORTED_LINK_DEPENDENT_LIBRARIES. In my project right before the use of the exported target opencv_videoio I have added a workaround code which created imported shared library target named opencv_ffmpeg (based on the imported location of opencv_videoio). I have added this opencv_ffmpeg target to the IMPORTED_LINK_DEPENDENT_LIBRARIES property of the opencv_videoio, but this does not fixed the installation of the opencv_ffmpeg340_64.dll.

Does one have to expect that vcpkg would copy the libraries listed in IMPORTED_LINK_DEPENDENT_LIBRARIES property of a linked library target?

I have also noticed that opencv_ffmpeg340_64.dll is the only one library which is created in the Debug sub-directory located in the release binary directory. The same is exactly reversed for the debug build. In this case opencv_ffmpeg340_64.dll is the only one library which is created in the Release sub-directory located in the debug binary directory.

buildtrees/opencv/x64-windows-rel/bin/Debug/opencv_ffmpeg340_64.dll

buildtrees/opencv/x64-windows-dbg/bin/Release/opencv_ffmpeg340_64.dll

Is it this a bug or this is intentional?

In addition no import libraries are generated for opencv_ffmpeg, also not even in the build directory tree, but this is a way more probable to be intentional, in order to prevent users from linking directly to this library.

@cenit
Copy link
Contributor

cenit commented Mar 1, 2018

@coderaper Did you try the vcpkg branch with external ffmpeg? There's still some work to do, but it is almost ready to merge.
I proposed that and I am strongly for it, I need other users' opinions!
I'd like to see it merged soon... It should solve your problems because it uses normal ffmpeg from vcpkg, not a binary library downloaded on the fly by the OpenCV builchain

@coderaper
Copy link

@cenit I have tried to build the external ffmpeg branch, but opencv build fails because the FFMPEG package cannot be found. As far as I can see, another reason for the configuration error can be that the installed libpng headers are located in installed\x64-windows\include\libpng16 and not in installed\x64-windows\include\libpng.

vcpkg-ext-ffmpeg>vcpkg install opencv[qt,ffmpeg,core,eigen,tiff,png,jpeg]:x64-windows
The following packages will be built and installed:
opencv[qt,ffmpeg,core,eigen,tiff,png,jpeg]:x64-windows
Starting package 1/1: opencv:x64-windows
Building package opencv[qt,ffmpeg,core,eigen,tiff,png,jpeg]:x64-windows...
-- CURRENT_INSTALLED_DIR=C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows
-- DOWNLOADS=C:/balkanski/work/vcpkg-ext-ffmpeg/downloads
-- CURRENT_PACKAGES_DIR=C:/balkanski/work/vcpkg-ext-ffmpeg/packages/opencv_x64-windows
-- CURRENT_BUILDTREES_DIR=C:/balkanski/work/vcpkg-ext-ffmpeg/buildtrees/opencv
-- CURRENT_PORT_DIR=C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/.
-- Using cached C:/balkanski/work/vcpkg-ext-ffmpeg/downloads/opencv-opencv-3.4.0.tar.gz
-- Testing integrity of cached file...
-- Testing integrity of cached file... OK
-- Extracting done
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0001-winrt-fixes.patch
-- Applying patch failed. This is expected if this patch was previously applied.
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0001-winrt-fixes.patch done
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0002-install-options.patch
-- Applying patch failed. This is expected if this patch was previously applied.
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0002-install-options.patch done
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0003-disable-downloading.patch
-- Applying patch failed. This is expected if this patch was previously applied.
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0003-disable-downloading.patch done
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0004-use-find-package-required.patch
-- Applying patch failed. This is expected if this patch was previously applied.
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0004-use-find-package-required.patch done
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0005-use-external-ffmpeg.patch
-- Applying patch failed. This is expected if this patch was previously applied.
-- Applying patch C:/balkanski/work/vcpkg-ext-ffmpeg/ports/opencv/0005-use-external-ffmpeg.patch done
-- Using cached C:/balkanski/work/vcpkg-ext-ffmpeg/downloads/opencv-cache/tiny_dnn/adb1c512e09ca2c7a6faef36f9c53e59-v1.0.0a3.tar.gz
-- Testing integrity of cached file...
-- Testing integrity of cached file... OK
-- Configuring x64-windows
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:56 (message):
Command failed: ninja;-v
Working Directory: C:/balkanski/work/vcpkg-ext-ffmpeg/buildtrees/opencv/x64-windows-rel/vcpkg-parallel-configure
See logs for more information:
C:\balkanski\work\vcpkg-ext-ffmpeg\buildtrees\opencv\config-x64-windows-out.log

Call Stack (most recent call first):
scripts/cmake/vcpkg_configure_cmake.cmake:248 (vcpkg_execute_required_process)
ports/opencv/portfile.cmake:203 (vcpkg_configure_cmake)
scripts/ports.cmake:72 (include)

Error: Building package opencv:x64-windows failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with .\vcpkg update, then
submit an issue at https:/Microsoft/vcpkg/issues including:
Package: opencv:x64-windows
Vcpkg version: 0.0.105-2018-02-23-d6aca74b0ccbab217d521a2e105658e6820a9f3d

Additionally, attach any relevant sections from the log files above.

Content of config-x64-windows-out.log:
. . . . . . . . . .
-- Found LibLZMA: C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/include (found version "5.2.3")
-- Found ZLIB: optimized;C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/lib/zlib.lib;debug;C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/debug/lib/zlibd.lib (found version "1.2.11")
-- Found PNG: optimized;C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/lib/libpng16.lib;debug;C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/debug/lib/libpng16d.lib (found version "1.6.34")
-- Looking for C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/include/libpng/png.h
-- Looking for C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/include/libpng/png.h - not found
CMake Error at C:/Program Files/CMake/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find FFMPEG (missing: FFMPEG_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/share/ffmpeg/FindFFMPEG.cmake:11 (find_package_handle_standard_args)
C:/balkanski/work/vcpkg-ext-ffmpeg/scripts/buildsystems/vcpkg.cmake:252 (_find_package)
cmake/OpenCVFindLibsVideo.cmake:217 (find_package)
CMakeLists.txt:604 (include)

-- Configuring incomplete, errors occurred!
See also "C:/balkanski/work/vcpkg-ext-ffmpeg/buildtrees/opencv/x64-windows-dbg/CMakeFiles/CMakeOutput.log".
See also "C:/balkanski/work/vcpkg-ext-ffmpeg/buildtrees/opencv/x64-windows-dbg/CMakeFiles/CMakeError.log".
ninja: build stopped: subcommand failed.

Content of vcpkg-ext-ffmpeg\buildtrees\opencv\x64-windows-dbg\CMakeFiles\CMakeError.log:
. . . . . . . . . . . . . . . .
Determining if the include file C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/include/libpng/png.h exists failed with the following output:
Change Dir: C:/balkanski/work/vcpkg-ext-ffmpeg/buildtrees/opencv/x64-windows-dbg/CMakeFiles/CMakeTmp

Run Build Command:"C:/balkanski/work/vcpkg-ext-ffmpeg/downloads/tools/ninja/ninja-1.8.2/ninja.exe" "cmTC_cce1d"
[1/2] Building C object CMakeFiles\cmTC_cce1d.dir\CheckIncludeFile.c.obj
FAILED: CMakeFiles/cmTC_cce1d.dir/CheckIncludeFile.c.obj
C:\PROGRA2\MICROS3.0\VC\bin\amd64\cl.exe /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /MP /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /MP8 /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\cmTC_cce1d.dir\CheckIncludeFile.c.obj /FdCMakeFiles\cmTC_cce1d.dir\ /FS -c CheckIncludeFile.c
CheckIncludeFile.c(1): fatal error C1083: Cannot open include file: 'C:/balkanski/work/vcpkg-ext-ffmpeg/installed/x64-windows/include/libpng/png.h': No such file or directory
ninja: build stopped: subcommand failed.

vcpkg-ext-ffmpeg>vcpkg list libpng
libpng:x64-windows 1.6.34-2 libpng is a library implementing an interface fo…

vcpkg-ext-ffmpeg>dir vcpkg-ext-ffmpeg\installed\x64-windows\include\libpng16
. . . . . . . . . . . .
03/02/2018 03:45 PM <DIR> .
03/02/2018 03:45 PM <DIR> ..
09/29/2017 09:42 AM 144,149 png.h
09/29/2017 09:42 AM 22,845 pngconf.h
03/02/2018 03:45 PM 7,839 pnglibconf.h

vcpkg-ext-ffmpeg>vcpkg list ffmpeg
ffmpeg:x64-windows 3.3.3-3 a library to decode, encode, transcode, mux, dem...
ffmpeg[openssl]:x64-windows openssl support in ffmpeg

@coderaper
Copy link

@ras0219-msft I don't know if the GNU Binutils are accepted as vcpkg tools, but the strings utility in combination with grep seems to work:

strings --encoding=l opencv_videoio340.dll | grep "\.dll"
opencv_ffmpeg340_64.dll
kernel32.dll
opencv_videoio340.dll

If the use of 16-bit littleendian encoding is not specified (--encoding=l command line switch), than I guess strings searches for single-8-bit-byte characters and other dll names are found:

strings opencv_videoio340.dll | grep "\.dll"
opencv_videoio340.dll
opencv_imgcodecs340.dll
MSVFW32.dll
AVIFIL32.dll
AVICAP32.dll
opencv_imgproc340.dll
opencv_core340.dll
KERNEL32.dll
USER32.dll
ole32.dll
OLEAUT32.dll
MSVCP140.dll
MF.dll
MFReadWrite.dll
VCRUNTIME140.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll

@sirexeclp
Copy link

I just want to kindly ask, if any progress has been made on this.
If i wanted to fix this issue for myself, in which file is the function defined, that is supposed to copy the dlls?

@chausner
Copy link
Contributor

Just stumbled upon this problem myself. Does anyone have any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants