Location>code7788 >text

FFmpeg Development Notes (XXXIX) Integration of FFmpeg into Visual Studio's C++ Project

Popularity:960 ℃/2024-07-21 01:19:20
The book "FFmpeg Development in Action: From Zero Basics to Online Short Video", "Chapter 11 FFmpeg Desktop Development" introduces how to implement desktop programs in Windows environment with Qt combined with FFmpeg, then it is also very common to develop desktop programs on Windows system through Visual Studio. program through Visual Studio is also very common, the following describes how to integrate the FFmpeg library and SDL2 library in the C++ project of Visual Studio.

First of all, according to the "FFmpeg development in action: from zero to short video on the line" book chapter 1 "1.3 Windows system to install FFmpeg," the introduction, the compiled FFmpeg library is installed to the personal computer's E:\msys64\usr\local\ffmpeg (). This installation directory can be replaced with the actual installation path of your computer, note that once you change the installation directory of FFmpeg, all the FFmpeg installation path configurations should be changed as well).
Open the pre-installed Visual Studio 2022 again and create a C++-based console application project. Wait for Visual Studio to open the new project, right-click on the project name in the Solution Explorer window on the right side of the main interface, and select the Properties option at the bottom of the context menu. In the pop-up properties page, select the list item on the left: Configuration Properties → VC++ Catalog, and select the list item on the right side of the properties page: General → External Include Catalog → Edit. Add the following header file directory in the External Include Directory pop-up window (the exact path is adjusted according to the ffmpeg installation path on your computer):

E:\msys64\usr\local\ffmpeg\include
E:\msys64\usr\local\sdl2\include

Confirm the addition of the above two header file directories by clicking the OK button in the lower right corner of the External Include Directory window.
Next, select the list item on the left side of the property page: Configuration Properties → Linker → General, and select the list item on the right side of the page: Additional Library Directory → Edit. Add the following library directory to the Additional Library Directory window that pops up (the exact path is adjusted according to the path of the sdl2 installation on your computer):

E:\msys64\usr\local\ffmpeg\lib
E:\msys64\usr\local\sdl2\lib

Confirm the addition of the above two library file directories by clicking the OK button in the lower right corner of the Additional Library Directories window.
Next, select the list items on the left side of the properties page in order: Configuration Properties → Linker → Input and select the list items on the right side of the page in order: Additional Dependencies → Edit. Add the following list of lib files to the Additional Dependencies pop-up window:









The Additional Dependencies window with the added lib file configuration is shown below. Click the OK button in the lower right corner of the Additional Dependencies window to confirm the addition of the above list of lib files.

Then click the OK button at the bottom right corner of the property page to complete the FFmpeg and SDL2 dependency library import settings.
Go back to the main interface of Visual Studio 2022, fill in the following FFmpeg test code in the code editor window on the left, which mainly calls the av_log function of FFmpeg framework to output "Hello World".

extern "C"
{
#include <libavutil/>
}

int main(int argc, char** argv) {
    av_log(NULL, AV_LOG_INFO, "Hello World\n");
    return 0;
}

After saving the test code, select the top menu: Debug→Start Execution, Visual Studio will start to compile the test program, compilation is complete, the console window pops up and outputs a line of the log "Hello World", which indicates that the FFmpeg library has been successfully integrated into Visual Studio's C++ project. FFmpeg library in Visual Studio's C++ project.

For more details on FFmpeg development seeFFmpeg Development in Action: From Zero Basics to Short Video OnlineA book.