openHEVC 编译 for VS2017+Win10 x64
编译暂未成功,有空再次更新
前期准备:
yasm下载:http://yasm.tortall.net/Download.html
1 http://www.tortall.net/projects/yasm/releases/vsyasm-1.3.0-win64.zip (用于集成)
2 http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe
3 http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz x
openHEVC源码下载: https://github.com/OpenHEVC/openHEVC
1 https://github.com/OpenHEVC/openHEVC/archive/hevc_rext.zip
SDL2.0下载: http://www.libsdl.org/download-2.0.php
1 http://www.libsdl.org/release/SDL2-2.0.5-win32-x64.zip
2 http://www.libsdl.org/release/SDL2-devel-2.0.5-mingw.tar.gz
CMake 3.8
下载: https://cmake.org/download/
1 https://cmake.org/files/v3.8/cmake-3.8.1-win64-x64.zip
FFmpeg 下载: https://ffmpeg.org/
1 http://ffmpeg.org/releases/ffmpeg-3.3.1.tar.bz2 (这个是源码)
1 http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20170503-a75ef15-win64-static.zip (已编译的程序)
pthreads-w32-2-9 openHEVC 中用到了线程,因此要下载:
1 ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip
环境配置
1、解压源码
解压后目录及文件夹结构:
1 "D:\dev\Endvlib\cmake-3.8.1-win64-x64" 【已解压的目录】 以下类同 2 "D:\dev\Endvlib\ffmpeg-3.3.1" 3 "D:\dev\Endvlib\ffmpeg-20170503-a75ef15-win64-static" 4 "D:\dev\Endvlib\openHEVC-hevc_rext" 5 "D:\dev\Endvlib\pthreads-w32-2-9-1-release" 6 "D:\dev\Endvlib\SDL2-2.0.5-win32-x64" 7 "D:\dev\Endvlib\vsyasm-1.3.0-win64" 8 "D:\dev\Endvlib\cmake-3.8.1-win64-x64.zip" 【已下载的文件】 以下类同 9 "D:\dev\Endvlib\ffmpeg-3.3.1.tar.bz2" 10 "D:\dev\Endvlib\ffmpeg-20170503-a75ef15-win64-static.zip" 11 "D:\dev\Endvlib\openHEVC-hevc_rext.zip" 12 "D:\dev\Endvlib\pthreads-w32-2-9-1-release.zip" 13 "D:\dev\Endvlib\SDL2-2.0.5-win32-x64.zip" 14 "D:\dev\Endvlib\vsyasm-1.3.0-win64.zip" 15 "D:\dev\Endvlib\yasm-1.3.0-win64.exe"
2、取出 pthreadVC2.lib pthreadVC2.dll 这两个文件放到 build 下,(build在openHEVC文件里新建一个)
1 "D:\dev\Endvlib\pthreads-w32-2-9-1-release\Pre-built.2\dll\x64\pthreadGC2.dll" 2 "D:\dev\Endvlib\pthreads-w32-2-9-1-release\Pre-built.2\dll\x64\pthreadVC2.dll"
复制上述两个文件到:
1 "D:\dev\Endvlib\openHEVC-hevc_rext\build\pthreadGC2.dll" 2 "D:\dev\Endvlib\openHEVC-hevc_rext\build\pthreadVC2.dll"
从FFmpeg源码中拷贝以下几个文件到openHEVC同名字的文件夹下 (提示缺XXX函数在XXX中,引用无法找到:原因是缺以下几个文件: )
libavutil/fifo.c
libavcodec/frame_thread_encoder.c
1 "D:\dev\Endvlib\ffmpeg-3.3.1\libavutil\fifo.c" 2 "D:\dev\Endvlib\ffmpeg-3.3.1\libavcodec\frame_thread_encoder.c"
复制上述两个文件到:
1 "D:\dev\Endvlib\openHEVC-hevc_rext\libavutil\fifo.c" 2 "D:\dev\Endvlib\openHEVC-hevc_rext\libavcodec\frame_thread_encoder.c"
这两个文件可以放到C:\Windows下
打开CMakeLists.txt("D:\dev\Endvlib\openHEVC-hevc_rext\CMakeLists.txt")找到
1 #find_package(CRYPTOPP_FOUND) 2 find_package(SDL) 3 find_package(SDL2) 4 5 set(libfilenames 6 libavutil/avstring.c 7 libavutil/atomic.c 8 libavutil/base64.c 9 libavutil/bprint.c 10 libavutil/buffer.c 11 libavutil/channel_layout.c 12 .............
在set命令中添加以下几条命令:set() 在Cmake中的意思是 将libavutil/avstring.c libavutil/atomic.c 等赋值给变量libfilenames;
1 #find_package(CRYPTOPP_FOUND) 2 find_package(SDL) 3 find_package(SDL2) 4 5 set(libfilenames 6 libavutil/avstring.c 7 libavutil/atomic.c 8 libavutil/base64.c 9 libavutil/bprint.c 10 libavutil/buffer.c 11 libavutil/channel_layout.c 12 libavutil/fifo.c 13 libavcodec/frame_thread_encoder.c
然后在CMakeLists.txt中找到target_link_libraries(LibOpenHevcWrapper m) 这条语句,这条语句的作用是添加m.lib到LibOpenHevcWrapper这一项目的链接器中。然而m.lib是没有的,找不到,既不是编译阶段能产生的,网上也无法找到,谁知道!因此注释掉:Cmake中 “#”是注释命令!
1 if(CRYPTOPP_FOUND) 2 target_link_libraries(LibOpenHevcWrapper cryptopp) 3 else() 4 # target_link_libraries(LibOpenHevcWrapper m) 5 endif()
你会发现,上述的配置都是按64位的环境来配置的,包括库
准备工作弄完了,可以开始编译了:
1、在openHEVC文件夹里新建一个文件夹:习惯命名build (上面已经完成)
2、为了在别的电脑上(没安装SDL2.X)方便用,将准备过程中下载的SDL包解压后,放到openHEVC文件夹里 (可选,此步不执行)
3、将下载的
"D:\dev\Endvlib\yasm-1.3.0-win64.exe"
改名为 yasm.exe 放在openHEVC文件夹里(或系统目录里,例如C:\windows 其实放哪里都行,因为看图,你第一次运行 configure 后,出来的红色区域,路径都是可以改的)
我是直接复制进去重命名为 yasm.exe
4、(可选,此次不执行)将pthreadVC2.lib pthreadVC2.dll这两个文件放到build文件夹下(目的是为了等项目的解决方案即xxx.sln生成后,在链接器中加入pthreadVC2.lib)。也可以放在openHEVC文件夹里,通过在CMakeLists.txt加入以下红色语句:
add_library (LibOpenHevcWrapper ${libfilenames} ${YASM_OBJECTS}) //可以通过这条语句在CMakeLists.txt中定位要加的位置
#target_link_libraries(LibOpenHevcWrapper m)
set(pthreadPATH ../pthreadVC2)
target_link_libraries(LibOpenHevcWrapper ${LINK_LIBRARIES_LIST} ${pthreadPATH})
5、打开Cmake
即 运行 "D:\dev\Endvlib\cmake-3.8.1-win64-x64\bin\cmake-gui.exe"
如图:
路径是你自己的路径,路径配好后,点击configure,出现红色背景区域,这红色背景区域的地址都可以改的,特别的是将黄色方框标记的路径改成openHEVC里面的路径:不懂看图
第一次configure:
Finish
1 DEBUG: CMAKE_SYSTEM_PROCESSOR = AMD64 2 DEBUG: CMAKE_SYSTEM_NAME = Windows 3 DEBUG: SIZEOF_VOID_P = 4 4 Detected CPU: haswell 5 Found components for YASM 6 YASM_ROOT_DIR = C:/Program Files (x86)/openHEVC 7 YASM_INCLUDES = YASM_INCLUDES-NOTFOUND 8 YASM_LIBRARIES = YASM_LIBRARIES-NOTFOUND 9 Could NOT find SDL (missing: SDL_LIBRARY) 10 Could NOT find SDL2 (missing: SDL2_LIBRARY) 11 Configuring done
修改红色部份为:
1 SDL_LIBRARY D:/dev/Endvlib/SDL2-devel-2.0.5-mingw/SDL2-2.0.5/x86_64-w64-mingw32/lib/libSDL2.a 2 SDL2_LIBRARY D:/dev/Endvlib/SDL2-devel-2.0.5-mingw/SDL2-2.0.5/x86_64-w64-mingw32/lib/libSDL2.a 3 SDL2_INCLUDE_DIR D:\dev\Endvlib\SDL2-devel-2.0.5-mingw\SDL2-2.0.5\x86_64-w64-mingw32\include 4 SDLMAIN_LIBRARY D:/dev/Endvlib/SDL2-devel-2.0.5-mingw/SDL2-2.0.5/x86_64-w64-mingw32/lib/libSDL2.a 5 YASM_EXECUTABLE D:/dev/Endvlib/vsyasm-1.3.0-win64/yasm-1.3.0-win64.exe 6
第二次configure:
搞了半天还有错误,不过项目是生成了
6. 点击Cmake的generate按钮,vs项目就生成了!
7、打开build文件夹,将里面没用的工程删掉,不然心烦,如下面左图,删掉后打开vs工程 后缀名为.sln的 就是解决方案的简称,没错打开的就是这个!发现如图右所示,按图右,在无法加载的工程上右击鼠标,选择移除。
右击LibOpenHevcWrapper项目,选择生成,会发现出现以下错误:
。。。。。。。。。
1 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): warning C4005: “vsnprintf”: 宏重定义 2 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): note: 命令行参数: 参见前面的“vsnprintf”定义 3 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1423): fatal error C1189: #error: Macro definition of vsnprintf conflicts with Standard Library function declaration 4 1>idct_sse2_xvid.c 5 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): warning C4005: “vsnprintf”: 宏重定义 6 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): note: 命令行参数: 参见前面的“vsnprintf”定义 7 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1423): fatal error C1189: #error: Macro definition of vsnprintf conflicts with Standard Library function declaration 8 1>qpeldsp_init.c 9 1>videodsp_init.c 10 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): warning C4005: “vsnprintf”: 宏重定义 11 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): note: 命令行参数: 参见前面的“vsnprintf”定义 12 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1423): fatal error C1189: #error: Macro definition of vsnprintf conflicts with Standard Library function declaration 13 1>strtod.c 14 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(43): warning C4273: “strtod”: dll 链接不一致 15 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdlib.h(497): note: 参见“strtod”的前一个定义 16 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(55): warning C4090: “=”: 不同的“const”限定符 17 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(58): warning C4090: “=”: 不同的“const”限定符 18 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(61): warning C4090: “=”: 不同的“const”限定符 19 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(64): warning C4090: “=”: 不同的“const”限定符 20 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(67): warning C4090: “=”: 不同的“const”限定符 21 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(70): warning C4090: “=”: 不同的“const”限定符 22 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(73): warning C4090: “函数”: 不同的“const”限定符 23 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(77): warning C4090: “函数”: 不同的“const”限定符 24 1>D:\dev\Endvlib\openHEVC-hevc_rext\compat\strtod.c(84): warning C4244: “=”: 从“__int64”转换到“double”,可能丢失数据 25 1>snprintf.c 26 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): warning C4005: “vsnprintf”: 宏重定义 27 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1421): note: 命令行参数: 参见前面的“vsnprintf”定义 28 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\stdio.h(1423): fatal error C1189: #error: Macro definition of vsnprintf conflicts with Standard Library function declaration 29 1>正在生成代码... 30 1>已完成生成项目“LibOpenHevcWrapper.vcxproj”的操作 - 失败。 31 ========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
预处理定义
<PreprocessorDefinitions>WIN32;_WINDOWS;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR="Debug";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR="Debug";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR=\"Debug\";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR="Release";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR=\"Release\";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR=\"MinSizeRel\";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR="RelWithDebInfo";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__SSE2AVX__;snprintf=avpriv_snprintf;vsnprintf=avpriv_vsnprintf;inline=__inline;restrict=__restrict;PIC;USE_SDL;CMAKE_INTDIR=\"RelWithDebInfo\";LibOpenHevcWrapper_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
WIN32 _WINDOWS NDEBUG __SSE2__ __SSE3__ __SSSE3__ __SSE4_1__ __SSE4_2__ __AVX__ __SSE2AVX__ snprintf=avpriv_snprintf vsnprintf=avpriv_vsnprintf inline=__inline restrict=__restrict PIC USE_SDL CMAKE_INTDIR="MinSizeRel" LibOpenHevcWrapper_EXPORTS
解决办法:在libavcodec/avcodec.h 里面#include "version.h" 后面,其实随便。添加:
#define AV_CODEC_CAP_INTRA_ONLY 0x40000000
#define AV_CODEC_FLAG_QSCALE (1 << 1)
#define AV_CODEC_FLAG_PASS1 (1 << 9)
以上三条语句,根据这个错误在FFmpeg的文件夹libavcodec/avcodec.h里面去ctrl+f 查找,复制到openHEVC的libavcodec/avcodec.h里面
在运行,发现还是错误:如图中注释,总共有三处。
在运行,还是出现错误,如:还是注释掉这条语句,总共二处
在运行,还是出现错误:如:这里的错误,
可以这么解决,将pthreadVC2.lib pthreadVC2.dll拷贝到build文件夹下,然后在项目的链接器中加入pthreadVC2.lib。如
在运行,还是有错误:如:找到这些错误,注释掉,这个错误跟机器有关,我们只用到了x86.
在运行,相信会是对了。注意上面说的运行,只运行LibOpenHevcWrapper 项目
现在,将hevc_sdl2设置 为启动项,启动项的设置是右击hevc_sdl2,在填出菜单中,选择设置为启动项。
然后运行,OK,完美!!
最后,可能还出现一个问题,可能你在编译的时候在D盘进行,你突然想拷贝到E盘去运行,那么你可能还要做一步工作,如果出现了错误就按如下做:
用UltraEdit打开build文件夹下类似hevc_sdl2.vcxproj 这个带有.vcxpro后缀名的文件,然后ctrl+f 查找D:\openHEVC-hevc_rext\ ,统一都替换为../ 就ok 了!