Commit 65a412b7 authored by Eden Abitbol's avatar Eden Abitbol Committed by Philippe Gorley

contrib/libmfx: add intel hardware acceleration support (windows)

Add media-sdk contrib folder. Includes fetch_and_patch.bat and
SHA512SUMS files.

Modify ffmpeg contrib build to link with libmfx and enable qsv
encoders/decoders.

Change-Id: I50d4e479d4619922f98377d3588424331d12aec2
parent 494b3996
......@@ -54,6 +54,7 @@ if "%1"=="uwp" (
set TOBUILD= ^
x264=build\x264\SMP\libx264.vcxproj, ^
opus=build\opus\SMP\libopus.vcxproj, ^
media-sdk=build\media-sdk\api\mfx_dispatch\windows\libmfx_vs2015.vcxproj, ^
ffmpeg=ffmpeg, ^
restbed=restbed, ^
jsoncpp=build\jsoncpp\makefiles\vs2017\lib_json.vcxproj, ^
......@@ -80,6 +81,7 @@ set TOBUILD= ^
vpx=build\vpx\SMP\libvpx.vcxproj, ^
x264=build\x264\SMP\libx264.vcxproj, ^
opus=build\opus\SMP\libopus.vcxproj, ^
media-sdk=build\media-sdk\api\mfx_dispatch\windows\libmfx_vs2015.vcxproj, ^
ffmpeg=ffmpeg, ^
restbed=restbed, ^
jsoncpp=build\jsoncpp\makefiles\vs2017\lib_json.vcxproj, ^
......
......@@ -21,6 +21,7 @@ if "%1"=="uwp" (
:uwpDeps
set DEPENDENCIES=( ^
media-sdk, ^
ffnvcodec, ^
ffmpeg, ^
argon2, ^
......@@ -46,6 +47,7 @@ goto fetch
:win32Deps
set DEPENDENCIES=( ^
media-sdk, ^
ffnvcodec, ^
ffmpeg, ^
argon2, ^
......
......@@ -32,5 +32,6 @@ bash -c "%PATCH_CMD% %UNIXPATH%ffmpeg/change-RTCP-ratio.patch"
git apply --reject --whitespace=fix %SRC%\ffmpeg\windows-configure.patch
git apply --reject --whitespace=fix %SRC%\ffmpeg\windows-configure-ffnvcodec.patch
git apply --reject --whitespace=fix %SRC%\ffmpeg\windows-configure-libmfx.patch
cd %SRC%
\ No newline at end of file
From 2358a7712c9cc88990131f04ea678b5020bc2bb0 Mon Sep 17 00:00:00 2001
From: Eden Abitbol <eden.abitbol@savoirfairelinux.com>
Date: Tue, 23 Jul 2019 12:30:03 -0400
Subject: [PATCH] Fix mfx link for windows.
---
configure | 2 --
1 file changed, 2 deletions(-)
--- a/configure
+++ b/configure
@@ -6016,8 +6016,6 @@ enabled libkvazaar && require_pkg_config libkvazaar "kvazaar >= 0.8.1" kv
# Media SDK or Intel Media Server Studio, these don't come with
# pkg-config support. Instead, users should make sure that the build
# can find the libraries and headers through other means.
-enabled libmfx && { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" MFXInit ||
- { require libmfx "mfx/mfxvideo.h" MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } }
enabled libmodplug && require_pkg_config libmodplug libmodplug libmodplug/modplug.h ModPlug_Load
enabled libmp3lame && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame $libm_extralibs
enabled libmysofa && { check_pkg_config libmysofa libmysofa mysofa.h mysofa_load ||
--
2.22.0.windows.1
......@@ -142,7 +142,7 @@ if [ "$1" == "uwp" ]; then
OUTDIR=Output/Windows10/x86
fi
elif [ "$1" == "win32" ]; then
EXTRACFLAGS='-MD -D_WINDLL -I../../../../../msvc/include -I../../../../../msvc/include/opus -I../../../../../msvc/include/vpx -I../../../../../msvc/include/ffnvcodec'
EXTRACFLAGS='-MD -D_WINDLL -I../../../../../msvc/include -I../../../../../msvc/include/opus -I../../../../../msvc/include/vpx -I../../../../../msvc/include/ffnvcodec -I../../../../../msvc/include/mfx'
FFMPEGCONF+='
--enable-libvpx
--enable-encoder=libvpx_vp8
......@@ -152,26 +152,38 @@ elif [ "$1" == "win32" ]; then
--enable-indev=dshow
--enable-indev=gdigrab
--enable-dxva2'
FFMPEGCONF+='
--enable-ffnvcodec
--enable-cuvid
--enable-nvdec
--enable-nvenc
--enable-hwaccel=h264_nvdec
--enable-hwaccel=hevc_nvdec
--enable-hwaccel=vp8_nvdec
--enable-hwaccel=mjpeg_nvdec
--enable-encoder=h264_nvenc
--enable-encoder=hevc_nvenc'
FFMPEGCONF+='
--enable-ffnvcodec
--enable-cuvid
--enable-nvdec
--enable-nvenc
--enable-hwaccel=h264_nvdec
--enable-hwaccel=hevc_nvdec
--enable-hwaccel=vp8_nvdec
--enable-hwaccel=mjpeg_nvdec
--enable-encoder=h264_nvenc
--enable-encoder=hevc_nvenc'
FFMPEGCONF+='
--enable-libmfx
--enable-encoder=h264_qsv
--enable-encoder=hevc_qsv
--enable-encoder=mjpeg_qsv
--enable-decoder=vp8_qsv
--enable-decoder=h264_qsv
--enable-decoder=hevc_qsv
--enable-decoder=mjpeg
--enable-decoder=vp9
--enable-filter=scale_qsv
--enable-filter=overlay_qsv'
if [ "$2" == "x64" ]; then
echo "configure and make ffmpeg for win32-x64..."
EXTRALDFLAGS='-APPCONTAINER:NO -MACHINE:x64 Ole32.lib Kernel32.lib Gdi32.lib User32.lib Strmiids.lib OleAut32.lib Shlwapi.lib Vfw32.lib Secur32.lib libopus.lib libx264.lib libvpx.lib -LIBPATH:../../../../../msvc/lib/x64'
EXTRALDFLAGS='-APPCONTAINER:NO -MACHINE:x64 Ole32.lib Kernel32.lib Gdi32.lib User32.lib Strmiids.lib Advapi32.lib OleAut32.lib Shlwapi.lib Vfw32.lib Secur32.lib Advapi32.lib libopus.lib libx264.lib libvpx.lib libmfx.lib -LIBPATH:../../../../../msvc/lib/x64'
FFMPEGCONF+=' --arch=x86_64'
PREFIX=../../../Build/win32/x64
OUTDIR=Output/win32/x64
elif [ "$2" == "x86" ]; then
echo "configure and make ffmpeg for win32-x86..."
EXTRALDFLAGS='-APPCONTAINER:NO -MACHINE:x86 Ole32.lib Kernel32.lib Gdi32.lib User32.lib Strmiids.lib OleAut32.lib Shlwapi.lib Vfw32.lib Secur32.lib libopus.lib libx264.lib libvpx.lib -LIBPATH:../../../../../msvc/lib/x86'
EXTRALDFLAGS='-APPCONTAINER:NO -MACHINE:x86 Ole32.lib Kernel32.lib Gdi32.lib User32.lib Strmiids.lib OleAut32.lib Shlwapi.lib Vfw32.lib Secur32.lib Advapi32.lib libopus.lib libx264.lib libvpx.lib libmfx.lib -LIBPATH:../../../../../msvc/lib/x86'
FFMPEGCONF+=' --arch=x86'
PREFIX=../../../Build/win32/x86
OUTDIR=Output/win32/x86
......
set BUILD=%SRC%..\build
set MEDIA_SDK_HASH=intel-mediasdk-19.2.0
set MEDIA_SDK_URL=https://github.com/Intel-Media-SDK/MediaSDK/archive/%MEDIA_SDK_HASH%.tar.gz
mkdir %BUILD%
if %USE_CACHE%==1 (
copy %CACHE_DIR%\%MEDIA_SDK_HASH%.tar.gz %cd%
) else (
%WGET_CMD% %MEDIA_SDK_URL%
)
7z -y x %MEDIA_SDK_HASH%.tar.gz && 7z -y x %MEDIA_SDK_HASH%.tar -o%BUILD%
del %MEDIA_SDK_HASH%.tar && del %MEDIA_SDK_HASH%.tar.gz && del %BUILD%\pax_global_header
rename %BUILD%\MediaSDK-%MEDIA_SDK_HASH% media-sdk
cd %BUILD%\media-sdk
%APPLY_CMD% %SRC%\media-sdk\windows-static-lib-build.patch
cd %SRC%
\ No newline at end of file
From 689a7acb36963c8558db3e879e6c22dcaaa535e7 Mon Sep 17 00:00:00 2001
From: Eden Abitbol <eden.abitbol@savoirfairelinux.com>
Date: Tue, 23 Jul 2019 11:30:49 -0400
Subject: [PATCH] Copy build output to correct directory
---
api/mfx_dispatch/windows/libmfx_vs2015.sln | 7 ++--
.../windows/libmfx_vs2015.vcxproj | 33 +++++++++++++++++--
2 files changed, 35 insertions(+), 5 deletions(-)
--- a/api/mfx_dispatch/windows/libmfx_vs2015.sln
+++ b/api/mfx_dispatch/windows/libmfx_vs2015.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.757
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmfx_vs2015", "libmfx_vs2015.vcxproj", "{A9F7AEFB-DC6C-49E8-8E71-5351ABDCE627}"
EndProject
@@ -25,6 +25,9 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {94706D6C-B55B-49AB-B136-337F5E9B2FA3}
+ EndGlobalSection
GlobalSection(DPCodeReviewSolutionGUID) = preSolution
DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
EndGlobalSection
--- a/api/mfx_dispatch/windows/libmfx_vs2015.vcxproj
+++ b/api/mfx_dispatch/windows/libmfx_vs2015.vcxproj
@@ -79,7 +79,7 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup>
- <OutDir>..\..\..\..\build\win_$(Platform)\$(Configuration)\lib\</OutDir>
+ <OutDir>..\..\..\build\win_$(Platform)\$(Configuration)\lib\</OutDir>
<IntDir>$(OutDir)..\objs\$(ProjectName)\</IntDir>
<IncludePath>$(MINIDDK_ROOT)\Include\um;$(MINIDDK_ROOT)\Include\shared;$(IncludePath)</IncludePath>
<LibraryPath>$(MINIDDK_ROOT)\Lib\win8\um\x86;$(LibraryPath)</LibraryPath>
@@ -88,7 +88,7 @@
<TargetName>$(ProjectName)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
- <TargetName>$(ProjectName)</TargetName>
+ <TargetName>libmfx</TargetName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
@@ -199,7 +199,7 @@
<AdditionalIncludeDirectories>include;..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN64;NDEBUG;_LIB;_ALLOW_MSC_VER_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_RUNTIME_LIBRARY_MISMATCH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<BufferSecurityCheck>true</BufferSecurityCheck>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -208,6 +208,33 @@
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Lib />
+ <Lib>
+ <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
+ <AdditionalDependencies>Advapi32.lib</AdditionalDependencies>
+ </Lib>
+ <PostBuildEvent>
+ <Command>mkdir "$(OutDir)"..\..\..\..\..\..\msvc\include
+
+mkdir "$(OutDir)"..\..\..\..\..\..\msvc\include\mfx
+
+mkdir "$(OutDir)"..\..\..\..\..\..\msvc\lib
+
+mkdir "$(OutDir)"..\..\..\..\..\..\msvc\lib\x64
+
+xcopy /S /Y "$(OutDir)"*.lib "$(OutDir)"..\..\..\..\..\..\msvc\lib\x64
+
+
+
+
+xcopy /S /Y "$(OutDir)"*.pdb "$(OutDir)"..\..\..\..\..\..\msvc\lib\x64
+
+
+xcopy /S /Y $(ProjectDir)..\..\..\api\include\*.h "$(OutDir)"..\..\..\..\..\..\msvc\include\mfx
+</Command>
+ </PostBuildEvent>
+ <ProjectReference>
+ <LinkLibraryDependencies>true</LinkLibraryDependencies>
+ </ProjectReference>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp" />
--
2.22.0.windows.1
......@@ -257,6 +257,7 @@ HardwareAccel::setupDecoder(AVCodecID id, int width, int height)
{ "vaapi", AV_HWDEVICE_TYPE_VAAPI, AV_PIX_FMT_VAAPI, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264, AV_CODEC_ID_MPEG4, AV_CODEC_ID_VP8, AV_CODEC_ID_MJPEG } },
{ "vdpau", AV_HWDEVICE_TYPE_VDPAU, AV_PIX_FMT_VDPAU, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264, AV_CODEC_ID_MPEG4 } },
{ "videotoolbox", AV_HWDEVICE_TYPE_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264, AV_CODEC_ID_MPEG4 } },
{ "qsv", AV_HWDEVICE_TYPE_QSV, AV_PIX_FMT_QSV, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264, AV_CODEC_ID_H265, AV_CODEC_ID_MJPEG, AV_CODEC_ID_VP8, AV_CODEC_ID_VP9 } },
};
for (const auto& api : apiList) {
......@@ -283,6 +284,7 @@ HardwareAccel::setupEncoder(AVCodecID id, int width, int height, AVBufferRef* fr
{ "nvenc", AV_HWDEVICE_TYPE_CUDA, AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264, AV_CODEC_ID_H265 } },
{ "vaapi", AV_HWDEVICE_TYPE_VAAPI, AV_PIX_FMT_VAAPI, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264, AV_CODEC_ID_MJPEG, AV_CODEC_ID_VP8 } },
{ "videotoolbox", AV_HWDEVICE_TYPE_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264 } },
{ "qsv", AV_HWDEVICE_TYPE_QSV, AV_PIX_FMT_QSV, AV_PIX_FMT_NV12, { AV_CODEC_ID_H264, AV_CODEC_ID_H265, AV_CODEC_ID_MJPEG, AV_CODEC_ID_VP8 } },
};
for (auto api : apiList) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment