简体   繁体   中英

How can I create a c++ console application which makes use of an open source c project

I've been playing around with a compiled version of https://github.com/FFmpeg/FFmpeg . But it has some problems, during the closing of an opened stream using avio_close (it takes a really long time to close it).

I've been trying to understand what could go wrong by reading through the implementation, but couldn't find anything.

What I would like to do, is to actually have a C++ console application which uses the c files and to debug them while running the code(using breakpoints and so on).

Unfortunately I cannot find any information on how to set it up. Simply copying the files in a new console application is not enough.

Thanks in advance for any suggestions.

Edit: I can already see a closing vote. If this question is not appropriate for this website, I will delete it. But please point me in the right direction of where to post it.Although it is quite a general question, I believe that it is clear and enough information has been provided.

Edit2: Yes, I was a bit unclear about what I'm using.

I'm using Visual Studio Community 2017 on Windows 10 for creating the C++ console application.

Edit3:

Steps that I've taken into using the source files into my console application which was using the DLLs.

  1. Copy all of the contents of the FFmpeg-master to my console application
  2. Include all of them in the c++ console application project
  3. Run a build - takes forever and has infinite build errors( > 1000) - probably compiler related

Edit4:

I have no actual errors with avio_close , it just takes too long to close the stream. What I found out when playing around with the settings is that when the fifo_size parameter is set, closing the stream is a lot faster depending on how small the set value is. And it sort of makes sense since fifo_size is related to the packet size, but I haven't found out where in the code this size has an impact.

fifo_size=units Set the UDP receiving circular buffer size, expressed as a number of packets with size of 188 bytes. If not specified defaults to 7*4096.

Edit5: I still haven't found a way to compile the open source ffmpeg project into libs, dlls and pdbs. Am I the first one needing such files(seems unrealistic)? The only tool capable of delivering those so far is vcpkg . The only problem is that it compiles the 3.3.3 version and the latest is 4.0.2 .

I tried to modify the vcpkg\\ports\\ffmpeg\\portfile.cmake file to include the latest version of ffmpeg, but it doesn't build it.

Are there any other suggestions?

There are some tools and workflows that you need to be confortable with in order to debug an application from the source code using a debugger.

First you need to know how to build the application. That is usually achieved by running:

$ ./configure
$ make

Since you want to debug, you must set some compiler flags that will instruct the compiler to produce debugging information that will be used by the debugger to relate machine instructions to the relevant lines of source code. In the case of FFMpeg, you just need to change the configure commad to:

$ ./configure --enable-debug

Please take a look at $ configure --help to see all the options, configure is extremely well documented in this project.

After running make you will have an executable that has debugging information, then you need to learn how to use a debugger. The gdb debugger is the one most used, and is actually the backend of most GUI debuggers. There are lots of informations and tutorials on how to use gdb, please do a google search for gdb tutorial and choose the one you find most comprehensible.

The most relevant tasks you will need to learn are how to set up breakpoints, print variables and stack traces.

Debugging using a command line interface like plain gdb has some advantages, but even old school people must admit that GUI comes in handy. So, as a last advise, after you understand and is confortable with the gdb workflow, you can search for a GUI debugger or even a full IDE that will certainly make your life much easier.

I ended up using vcpkg .

As a guide for building this specific (as in no idea if it would work the same for others open source projects) package:

1) Download vcpkg and go through the installation process described in the README file

2) Go to

..\\vcpkg\\ports\\ffmpeg\\

and edit the portfile.cmake file.

By default vcpkg will build the 3.3.3 version of ffmpeg and it uses

vcpkg_download_distfile(ARCHIVE
URLS "http://ffmpeg.org/releases/ffmpeg-3.3.3.tar.bz2"
FILENAME "ffmpeg-3.3.3.tar.bz2"
SHA512 1cc63bf73356f4e618c0d3572a216bdf5689f10deff56b4262f6d740b0bee5a4b3eac234f45fca3d4d2da77903a507b4fba725b76d2d2070f31b6dae9e7a2dab
)

Change it to

vcpkg_download_distfile(ARCHIVE
    URLS "http://ffmpeg.org/releases/ffmpeg-4.0.2.tar.bz2"
    FILENAME "ffmpeg-4.0.2.tar.bz2"
    SHA512 92a3bedcd070df72b26dbe3ebf4a3faea0a02289fbefdb6a6c73d65801cf60a7e11cd832d29ab46b7749a1ffd0a31505cf75bb46bd01ea06423b454ca04e9b7b
)

This will download the latest ffmpeg version. In order for the build to work you also have to comment these lines:

if("ffserver" IN_LIST FEATURES)
    set(OPTIONS "${OPTIONS} --enable-ffserver")
else()
    set(OPTIONS "${OPTIONS} --disable-ffserver")
endif()

I assume that since version 3.3.3 this option was removed/disabled and it doesn't work anymore.

3) Run(it will take a while)

.\\vcpkg install ffmpeg

You should now have a 4.0.2 debug and release version of FFMPEG with DLLs, PDBs, libs and includes folders.

Not entirely sure if this process was correct, but my project is working fine and I'm now able to debug it.

You can use vcpkg, open source packager, from github to build many open source projects including ffmpeg without any hassle. vcpkg has recently given support for non-windows platforms also, check it out.

A single one liner command on Powershell prompt .\\vcpkg install ffmpeg ,is all that is needed. As usual the vs console project could be subjected for debugging also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM