It's genuine again! Win under FFmpeg source Debugging Analysis II (Step into FFmpeg from OPENCV for bugs in debug mode with MSVC)

Source: Internet
Author: User
Tags function prototype

Recently work busy has not time to write, but look at the network on this aspect of resources really few, many are Linux (I love unix, haha), and many are directly introduced in the previous article compiled results to do. For the use of OpenCV but always be ffmpeg library entrap friends, may also love and hate, after all, with it processing and analysis of video is the first choice, not only because the two are easy to use, but also ffmpeg almost all of the encoder I know, But it's because this makes some bugs difficult to locate, so it's important to think about how to quickly locate your ffmpeg bug.

Sorry, that's a lot of crap. First, give a thought:

1. Enable OPENCV Highgui project to link to the above build-out FFmpeg file (Lib,dlls ... )

2. Then try to debug under MSVC, complete the macro changes, make it available under the VC.

3. Complete the cap_ffmpeg.cpp modification so that it correctly loads the FFmpeg dynamic library so that the program can debug to source. This step, rarely mentioned on the Internet, can only turn their brains.

OK, get to the point:

1.LNK Property Configuration:

Right Button-"project-" attribute, in debug mode (of course you can also be full mode), enter VC + + directories, set "Your ffmpeg/bin path" to executable directories, Of course, you'd better put this path in the computer's path, sometimes VC can not find. If not, put all DLLs, throw it under system (note to Lil bit location, System has 2 kinds)

Go to C + +, set include path, OK.

Then enter the difintions under the preprocessor below, and join

Use_ffmpeg
__stdc_constant_macros

(why add this, in fact, is to let msvc know some of GCC's unique macros, which in the previous article has explained the compiler core selection problem)

Enter linker--"General: Set additional Libaray directories, in order to let MSVC can not be affected by the FFmpeg native GCC macro, here to use to mingw the GCC library, At the same time to let OpenCV see your ffmpeg libs,dlls, so join:

C:\MinGW\lib\gcc\mingw32\4.8.1

F:\ffmpeg-dev\bin (This is Libs and DLLs)

Enter input, set all FFmpeg libs, and list them in additional dependencies.

Note: If you want to configure the static library for debug, to prevent the erro of the image Safe, you can close linker "image has Safe Exception handlers" under Advanced.

OK, so far. We have completed the Highgui configuration.

Here's the second step:

To download two headers from git files: (directly GG the first file name is available)

Inttypes.h

Stdint.h (do not confuse it with VC, some int type of this file is defined for the above file)

The 2 file here mainly defines the macro and basic data type of the FFmpeg gcc form.

Then throw it into the FFmpeg's include folder.

OK, then open the OpenCV ffmpeg Impl interface, we have seen before the Opencv_ffmpegxxx.dll function prototype is encapsulated in this, specifically you can see in the DLL.

Here's a look at my modify for this file:

#include "precomp.hpp"

#if defined have_ffmpeg//&&!defined win32//Modify
#include "cap_ffmpeg_impl.hpp"
#else
#include "cap_ffmpeg_api.hpp"
#endif

A second change:

Icvinitffmpeg ()
{
#if 0//defined WIN32 | | Defined _win32//Modification
# ifdef HAVE_WINRT
Const wchar_t* module_name = L "Opencv_ffmpeg"
CVAUX_STRW (cv_major_version) cvaux_strw (cv_minor_version) cvaux_strw (cv_subminor_version)
#if (defined _msc_ver && defined _m_x64) | | (defined __gnuc__ && defined __x86_64__)
L "_64"
#endif
L ". dll";

ICVFFOPENCV = loadpackagedlibrary (module_name, 0);

# Else
Const char* module_name = "Opencv_ffmpeg"

Cvaux_str (cv_major_version) cvaux_str (cv_minor_version) cvaux_str (cv_subminor_version)

#if (defined _msc_ver && defined _m_x64) | | (defined __gnuc__ && defined __x86_64__)
"_64"
#endif
". dll";

ICVFFOPENCV = LoadLibrary (module_name);
# endif

OK, save.

The following changes, Cap_ffmpeg_impl.cpp, this is the link core of OpenCV and FFmpeg,

The first part to be modified:


#include "cap_ffmpeg_api.hpp"
#include <assert.h>
#include <algorithm>
#include <limits>
Ek
#if _msc_ver//Modification
#define SNPRINTF _snprintf
#endif
End

This is to let Msvc avoid the compilation of GCC syntax trouble.

Part II:


#ifdef __gnuc__
# pragma GCC diagnostic ignored "-wdeprecated-declarations"
#endif
#define __stdc_constant_macros///ek Modification
#ifdef __cplusplus
extern "C" {
#endif

By this, all the modifications have been completed, saved, F5. You have entered a magical ffmpeg world.

Thanks from Ek,enjoy it.

NOTE: Reprint Please specify, thank you.

Next time, will look for a moment, write a ffmpeg source analysis ....

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.