microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.75k stars 6.29k forks source link

[ffmpeg]Add divx support. #8960

Open mblackbourne opened 4 years ago

mblackbourne commented 4 years ago

Is there a way to re-target the vcpkg to avoid this error?

Steps to reproduce:

vcpkg install ffmpeg

Starting package 1/1: ffmpeg:x86-windows Building package ffmpeg[core]:x86-windows... -- Using cached C:/Program Files/node-support/vcpkg/downloads/ffmpeg-4.1.tar.bz2 -- Using source at C:/Program Files/node-support/vcpkg/buildtrees/ffmpeg/src/ffmpeg-4-35aba462b6 CMake Error at ports/ffmpeg/portfile.cmake:22 (message): Error: ffmpeg will not build with spaces in the path. Please use a directory with no spaces Call Stack (most recent call first): scripts/ports.cmake:85 (include)

Error: Building package ffmpeg:x86-windows failed with: BUILD_FAILED Please ensure you're using the latest portfiles with .\vcpkg update, then submit an issue at https://github.com/Microsoft/vcpkg/issues including: Package: ffmpeg:x86-windows Vcpkg version: 2019.08.27-nohash

mblackbourne commented 4 years ago

Rest of Log:: Also an issue.

The following is a result of vcpkg install opencv ; Which installs Opencv 4.1.1. When attempting a videowrite the following error appears.

[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\videoio_registry.cpp (187) cv::anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940)
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (340) cv::impl::getPluginCandidates Found 2 plugin(s) for FFMPEG
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load C:\Users\admin\source\repos\IanVision\Debug\opencv_videoio_ffmpeg411.dll => FAILED
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg411.dll => FAILED
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (340) cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load C:\Users\admin\source\repos\IanVision\Debug\opencv_videoio_gstreamer411.dll => FAILED
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer411.dll => FAILED
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (340) cv::impl::getPluginCandidates Found 2 plugin(s) for INTEL_MFX
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load C:\Users\admin\source\repos\IanVision\Debug\opencv_videoio_intel_mfx411.dll => FAILED
[ INFO:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load opencv_videoio_intel_mfx411.dll => FAILED
OpenCV(4.1.1) Error: Bad argument (CAP_IMAGES: can't find starting number (in the name of file): ./desktop_capture.avi) in cv::icvExtractPattern, file C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\cap_images.cpp, line 253
[ERROR:0] global C:\Program Files\node-support\vcpkg\buildtrees\opencv4\src\4.1.1-d4651a36c2\modules\videoio\src\cap.cpp (392) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:
JackBoosY commented 4 years ago

Hi @mblackbourne, thanks for reporting this issue. C:/Program Files/node-support/vcpkg Since building ffmpeg in a path with spaces will cause some errors, please re-clone vcpkg and install ffmpeg in a path that does not contain spaces.

Thanks.

mblackbourne commented 4 years ago

Moved package and upgraded.

PS S:\dev\vsTools\vcpkg> vcpkg.exe update
Warning: Different source is available for vcpkg (2019.8.27 -> 2019.9.12). Use .\bootstrap-vcpkg.bat to update.
Using local portfile versions. To update the local portfiles, use git pull.
No packages need updating.
PS S:\dev\vsTools\vcpkg> vcpkg.exe upgrade
All installed packages are up-to-date with the local portfiles.
PS S:\dev\vsTools\vcpkg> vcpkg install curl
Warning: Different source is available for vcpkg (2019.8.27 -> 2019.9.12). Use .\bootstrap-vcpkg.bat to update.
Your feedback is important to improve Vcpkg! Please take 3 minutes to complete our survey by running: vcpkg contact --survey
The following packages will be built and installed:
    curl[core,ssl,winssl]:x86-windows
  * zlib[core]:x86-windows
Additional packages (*) will be modified to complete this operation.
Starting package 1/2: zlib:x86-windows
Building package zlib[core]:x86-windows...
CMake Error at scripts/ports.cmake:15 (message):
          Your vcpkg executable is outdated and is not compatible with the current CMake scripts.
          Please re-build vcpkg by running bootstrap-vcpkg.

Could not copy into file: S:\dev\vsTools\vcpkg\packages\zlib_x86-windows\share\zlib\vcpkg_abi_info.txt`
JackBoosY commented 4 years ago

Please rerun ./bootstrap-vcpkg.bat then rebuild ffmpeg.

Thanks.

mblackbourne commented 4 years ago

FFMPEG appears to have installed fully; however some errors still remain

[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\videoio_registry.cpp (187) cv::anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940)
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (340) cv::impl::getPluginCandidates Found 2 plugin(s) for FFMPEG
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load C:\Users\admin\source\repos\IanVision\Debug\opencv_videoio_ffmpeg411.dll => FAILED
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load opencv_videoio_ffmpeg411.dll => FAILED
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (340) cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load C:\Users\admin\source\repos\IanVision\Debug\opencv_videoio_gstreamer411.dll => FAILED
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer411.dll => FAILED
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (340) cv::impl::getPluginCandidates Found 2 plugin(s) for INTEL_MFX
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load C:\Users\admin\source\repos\IanVision\Debug\opencv_videoio_intel_mfx411.dll => FAILED
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load opencv_videoio_intel_mfx411.dll => FAILED
OpenCV(4.1.1) Error: Bad argument (CAP_IMAGES: can't find starting number (in the name of file): ./desktop_capture.avi) in cv::icvExtractPattern, file S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\cap_images.cpp, line 253
[ERROR:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\cap.cpp (392) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

When opencv is installed, the above libs should be created and linked by vcpkg?

JackBoosY commented 4 years ago

@mblackbourne Which compiler do you use? If you use cmake or msbuild, please use the commands .\vcpkg integrate install and .\vcpkg integrate project and view the documentation to add the tool-chain.

Thanks.

mblackbourne commented 4 years ago

Compiler: cmake gui. I used both integrate commands; with no change to the output. The video libraries are still not there.

JackBoosY commented 4 years ago

@mblackbourne Could you provide a sample code?

Thanks.

mblackbourne commented 4 years ago

I "patched" the issue by installing the opencv binary from openvc.org then copied the opencv_videoio_ffmpeg411.dll from the build\bin folder.

int main2(int argc, char** argv)
{
    std::cout << "Starting Script" << std::endl;
    HWND hwndDesktop = GetDesktopWindow(); //FindWindowEx();
    namedWindow("output", WINDOW_NORMAL);
    int key = 0;

    VideoWriter video("out.avi", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), 10, Size(1920,1080), true); // ctlHeight, ctlWidth
    int count = 0;
    //video.open();

    while (key != 27)
    //for(;;)
    {
        // InputArray img = src;
        Mat src = hwnd2mat(hwndDesktop); // src =frame
        //count++;
        imwrite("outer%d.jpg", src);
        imshow("output", src);
        video.write(src);
        key = waitKey(60); // you can change wait time
    }
    exception();
    //ReleaseCapture();
    //video.release();
    //destroyAllWindows();
    return 0;
}

The current Debug Output:

[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\videoio_registry.cpp (187) cv::'anonymous namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940)
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (340) cv::impl::getPluginCandidates Found 2 plugin(s) for FFMPEG
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load C:\Users\admin\source\repos\IanVision\Debug\opencv_videoio_ffmpeg411.dll => OK
[ INFO:0] global S:\DEV\vsTools\vcpkg\buildtrees\opencv4\src\4.1.1-fb9e10326a\modules\videoio\src\backend_plugin.cpp (220) cv::impl::PluginBackend::PluginBackend Video I/O: loaded plugin 'FFmpeg OpenCV Video I/O plugin'

So far it appears to be working. What would be the best way to add the dll to vcpkg?

JackBoosY commented 4 years ago

@mblackbourne Nope, if it's a bug, we will fix it in source.

JackBoosY commented 4 years ago

@mblackbourne Use your provide code:

#include "pch.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cctype>
#include <windows.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>

using namespace std;
using namespace cv;

Mat hwnd2mat(HWND hwnd) {
    HDC hwindowDC, hwindowCompatibleDC;

    int height, width, srcheight, srcwidth;
    HBITMAP hbwindow;
    Mat src;
    BITMAPINFOHEADER  bi;

    hwindowDC = GetDC(hwnd);
    hwindowCompatibleDC = CreateCompatibleDC(hwindowDC);
    SetStretchBltMode(hwindowCompatibleDC, COLORONCOLOR);

    RECT windowsize;    // get the height and width of the screen
    GetClientRect(hwnd, &windowsize);

    srcheight = windowsize.bottom;
    srcwidth = windowsize.right;
    height = windowsize.bottom / 1;  //change this to whatever size you want to resize to
    width = windowsize.right / 1;

    src.create(height, width, CV_8UC4);

    // create a bitmap
    hbwindow = CreateCompatibleBitmap(hwindowDC, width, height);
    bi.biSize = sizeof(BITMAPINFOHEADER);    //http://msdn.microsoft.com/en-us/library/windows/window/dd183402%28v=vs.85%29.aspx
    bi.biWidth = width;
    bi.biHeight = -height;  //this is the line that makes it draw upside down or not
    bi.biPlanes = 1;
    bi.biBitCount = 32;
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;

    // use the previously created device context with the bitmap
    SelectObject(hwindowCompatibleDC, hbwindow);
    // copy from the window device context to the bitmap device context
    StretchBlt(hwindowCompatibleDC, 0, 0, width, height, hwindowDC, 0, 0, srcwidth, srcheight, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !
    GetDIBits(hwindowCompatibleDC, hbwindow, 0, height, src.data, (BITMAPINFO *)&bi, DIB_RGB_COLORS);  //copy from hwindowCompatibleDC to hbwindow

    // avoid memory leak
    DeleteObject(hbwindow);
    DeleteDC(hwindowCompatibleDC);
    ReleaseDC(hwnd, hwindowDC);

    return src;
}

int main(int argc, char** argv)
{
    std::cout << "Starting Script" << std::endl;
    HWND hwndDesktop = GetDesktopWindow(); //FindWindowEx();
    namedWindow("output", WINDOW_NORMAL);
    int key = 0;

    VideoWriter video("out.avi", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), 10, Size(1920, 1080), true); // ctlHeight, ctlWidth
    int count = 0;
    //video.open();

    while (key != 27)
        //for(;;)
    {
        // InputArray img = src;
        Mat src = hwnd2mat(hwndDesktop); // src =frame
        //count++;
        imwrite("outer%d.jpg", src);
        imshow("output", src);
        video.write(src);
        key = waitKey(60); // you can change wait time
    }
    exception();
    ReleaseCapture();
    video.release();
    destroyAllWindows();
    return 0;
}

Build result:

1>------ Build started: Project: ConsoleApplication5, Configuration: Debug Win32 ------
1>pch.cpp
1>ConsoleApplication5.cpp
1>ConsoleApplication5.vcxproj -> C:\Users\source\repos\ConsoleApplication5\Debug\ConsoleApplication5.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

image And successfully run, no abnormalities were found.

mblackbourne commented 4 years ago

The show has always worked. Did the out.avi run for you? Mine was 6kb and "invalid".

cenit commented 4 years ago

It might be possible that ffmpeg built by vcpkg does not support the divx codec, so the video saved to disk might be broken. It’s a long time I am not using divx anymore, I have to check if it’s the case. @JackBoosY it might be a nice feature if missing, what do you think?

mblackbourne commented 4 years ago

@cenit I think your correct. However it seemed to be the same for XVID as well. DIVX worked for show and imread.