Debug FFmpeg in VC2015

Source: Internet
Author: User

Compiling X264 requires at least VS2013 Update 2 or later. This article uses VS2015.

Example Project: Https://github.com/gitgjogh/FFmpeg-gitgjogh/tree/msvc/build_msvc

Build libav*** Using MSVC Compiler under Mingw32import vcvarInto MSYS (MINGW32)
    • scheme#1: Start Menu vs2015 tools VS2015 x86 本机工具命令提示 start msys.bat binding with mingw32 . (Don ' t use mingw64 )
    • scheme#2: Add to the call "C:/Program Files/Microsoft Visual Studio 14.0/VC/vcvarsall.bat" 1st line of msys.bat . Then kick off msys.bat .

Confirm has vcvar been imported:

$ which link nmake  /c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/BIN/link.exe  /c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/BIN/nmake.exe  

nmakeIs the make programe under MSVC. Needed for making zlib . See later.

Fix collision between VC-linkand MSYS-LINK
    • VC-linkLinks obj/libs files to create Exe/dll file
    • MSYS-LINKCreates a link named FILE2 to an existing FILE1.

It is possible, msys‘s file linker or coreutils‘s linker conflicts with MSVC’s linker . You can find the running to see which link which link binary is using. If It /bin/link.exe is located at, MV to /bin/link.exe/bin/msys-link.exe

YasmX264

You need in least VS2013 update 2 to compile x264.

Go to an x264 source tree

> $ CC=cl ./configure --prefix=${PATH_TO_build_msvc} --enable-static --disable-gpl --enable-debug --enable-win32thread> $ make && make install  > $ MSVC=‘/c/Program Files (x86)/Microsoft Visual Studio 14.0/VC/‘  > $ cp libx264.lib ${MSVC}/lib/x264.lib> $ cp x264.h x264_config.h ${MSVC}/include/
Zlib
    • $ cd zlib-1.2.8
    • Edit win32/Makefile.msc CFLAGS -MT -MD so the uses instead of, since this is what FFmpeg is built as well.
      > del CFLAGS =-nologo-md-w3-o2-oy--zi-fd "Zlib" $ (LOC)
      > Add CFLAGS =-nologo-mt-w3-o2-oy-zi-fd "Zlib" $ (LOC)
    • Edit and zconf.h remove its inclusion of unistd.h . This gets erroneously included when building FFmpeg.
    • $ nmake -f win32/Makefile.msc
    • Move zlib.lib , and to zconf.h zlib.h somewhere MSVC can see.
      > $ Msvc= '/c/program Files (x86)/microsoft Visual Studio 14.0/vc/'
      > $ CP zlib.lib ${msvc}/vc/lib/
      > $ cp zconf.h zlib.h ${msvc}/include/

Reference: http://www.ffmpeg.org/platform.html

Build FFmpeg Libs Using msvcToolchain

Under build_msvc :

> $ madir build && cd build  > $ ../../configure --prefix=`pwd`/.. --toolchain=msvc --disable-shared --enable-static --enable-libx264 --enable-gpl  > $ make --debug | tee make.log  > $ make install  

If configuration failed because ' can ' t find libx264 ':

Create Win32 Console App. Project

Add the following files to the project:

cmdutils.h cmdutils_common_opt.h build/config.h ffmpeg.h  cmdutils.c ffmpeg.c ffmpeg_dxva2.cffmpeg_filter.c ffmpeg_opt.c  

Clue: Run to see what grep "^CC" make.log files is compiled.

ADD Dependency
    • Additional Include Directories:include;build
    • Additional Library Directories:lib
    • Additional Dependent Libraries:vfw32.lib;psapi.lib;strmiids.lib;shlwapi.lib;ws2_32.lib;x264.lib;zlib.lib;libavdevice.a;libavfilter.a;libswscale.a;libpostproc.a;libavformat.a;libavcodec.a;libswresample.a;libavutil.a

clue#1: Under build_msvc , run to see what env PKG_CONFIG_PATH=lib/pkgconfig/ pkg-config --libs libavdevice additional libs need to be added. For example, my result is:

vfw32.lib user32.lib gdi32.lib psapi.lib ole32.lib strmiids.lib uuid.lib oleaut32.lib shlwapi.lib ws2_32.lib x264.lib zlib.lib advapi32.lib shell32.lib -L../lib -lavdevice -lavfilter -lswscale -lpostproc -lavformat -lavcodec -libpath:../lib -lswresample -lavutil

clue#2: The following lines in the generated ' malefile ' also can is took as reference to decide Lib orders

# $(FFLIBS-yes) needs to be in linking orderFFLIBS-$(CONFIG_AVDEVICE)   += avdeviceFFLIBS-$(CONFIG_AVFILTER)   += avfilterFFLIBS-$(CONFIG_AVFORMAT)   += avformatFFLIBS-$(CONFIG_AVCODEC)    += avcodecFFLIBS-$(CONFIG_AVRESAMPLE) += avresampleFFLIBS-$(CONFIG_POSTPROC)   += postprocFFLIBS-$(CONFIG_SWRESAMPLE) += swresampleFFLIBS-$(CONFIG_SWSCALE)    += swscale
Set Preprocessor

clue#1: search ' cppflags ', ' CFLAGS ', ' cxxflags '. Asflags ' in ' Config.mak ' to-see-autoconfig deal with ' inline ', ' snprintf ' compatibility by setting '--toolchain=msvc ' O Ption.

clue#2: search ' ^cl ' in ' Config.log ', see that how MSVC compiler ' cl.exe ' is called. Here are an example:

"cl -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_WIN32_WINNT=0x0502 -nologo -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -I../include -Z7 -W4 -wd4244 -wd4127 -wd4018 -wd4389 -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 -wd4152 -wd4324 -we4013 -wd4100 -wd4214 -wd4307 -wd4273 -wd4554 -wd4701 -O2 -Oy- -P -Fi./ffconf.wAKKajHY.o ./ffconf.FbkkcFDo.c"
Problemsfix collision between LIBCMT.liband msvcrtd.lib
1>------ 已启动生成:  项目: build_msvc, 配置: Debug Win32 ------  1>LIBCMT.lib(open.obj) : error LNK2005: __sopen 已经在 MSVCRT.lib(MSVCR120.dll) 中定义  1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson 已经在 MSVCRT.lib(MSVCR120.dll) 中定义  1>LIBCMT.lib(_file.obj) : error LNK2005: ___iob_func 已经在 MSVCRT.lib(MSVCR120.dll) 中定义  

Reason: some code link to the static RTL (run time library) with some code link to dynamic RTL Solution:set MSV CR TO/MT in "Properties->c/c++->code generation"

Reference: https://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=VS.71%29.aspx

Undefined Reference to ' avresample_version ', ' postproc_version '

Scheme:

1) goto "cmdutil.c"::"print_all_libs_info()", comment the following two lines:    // PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);    // PRINT_LIB_INFO(postproc, POSTPROC, flags, level);2) configure --enable-avresample
Network Module

which have to link to the WINDOWS SDK, so is careful with how ' _win32_winnt ' defined in ' Config.mak ' or ' config.log ', copie D it to the VC preprocessors. Reference to the ' Set preprocessor ' section.

Debug FFmpeg in VC2015

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.