Audio and video cannot run when using qt to test the ffmpeg interface

I just sorted out the slight blocking and doubts I encountered in the process. The doubt is that there is no dll file in the ffmpeg package I got, which led me to research a series.

Use qt to load the related lib library corresponding to audio and video ffmpeg, and conduct interface and source code research.

1: Use source code installation to obtain relevant dynamic libraries.

2: You can install the corresponding release version from the official website of ffmpeg, or the github library (there are differences between different versions, just the installation environment/refer to the corresponding package for debugging).

On the official website, select the version corresponding to windows: for debugging here, generally select shared. http://ffmpeg.org/ Download can refer to FFmpeg windows download and install_luoyayun361’s blog-CSDN blog

In github, you can see the corresponding version in the corresponding release build, here you can choose the shared version of the corresponding version to download: https://github.com/GyanD/codexffmpeg/releases

Objective: Before researching the source code, obtain the required ffmpeg-related dependencies:

1: In the previous article, I compiled ffmpeg with msys2 source code on windows, and directly used the related libraries generated after compilation.

2: Get the ffmpeng-related lib library directly here and use it directly.

(Note that the pro file in the qt project here relies on the lib file, and the related dll files are also needed at runtime, otherwise the execution will have no results, and the output window: Exit, exit code: -1073741515 )

1: Get related libraries

This version I downloaded here, the test is available:

Configure environment variables: corresponding to the bin directory:

Verify that ffmpeg takes effect:

2: Analyze the relevant dependencies when calling the library, that is, the key files of the relevant directories under ffmpeg

2.1: The bin directory is mainly the directory of executable files. dumpbin command

===》The relevant exe files in the bin directory are ffmpeg, ffplay, ffproble executable files, and the configuration environment variables are generally in this directory.

===》The relevant dll files in the bin directory actually store relevant code information, and the corresponding content of this type of file is actually called when the exe file is executed.

======= “The execution of the relevant exe actually calls the content in the corresponding dll.

#For example, check the related dlls that ffmepeg.exe depends on
#You can also see the related dependent dll and corresponding functions in the dll
C:\Users\yun68\Desktop\ffmpeg_build\ffmpeg-5.1.2-full_build-shared\bin>dumpbin -imports avcodec-59.dll

C:\Users\yun68\Desktop\ffmpeg_build\ffmpeg-5.1.2-full_build-shared\bin>dumpbin /dependents ffmpeg.exe
Microsoft (R) COFF/PE Dumper Version 14.29.30148.0
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file ffmpeg.exe

File Type: EXECUTABLE IMAGE

  Image has the following dependencies:

    KERNEL32.dll
    msvcrt.dll
    SHELL32.dll
    avcodec-59.dll
    avdevice-59.dll
    avfilter-8.dll
    avformat-59.dll
    avutil-57.dll
    postproc-56.dll
    swresample-4.dll
    swscale-6.dll

  Summary

        1000.CRT
        1000.bss
        1000.data
        5000.idata
        2000.pdata
        F000.rdata
        1000.reloc
        1000.rsrc
       3F000.text
        1000.tls
        2000.xdata

C:\Users\yun68\Desktop\ffmpeg_build\ffmpeg-5.1.2-full_build-shared\bin>

2.2: The main function of the lib directory is to provide external use as a third-party library.

===》Related .lib files (lib import library), used during compilation, the code in lib will be compiled into the target exe

===》dll is a dynamic library, used at runtime, the code in the dll does not participate in compilation, but during runtime, go to the corresponding dll file to find the function

======= “When compiling, there is no problem using the lib library for dependency, but when running, the corresponding dll needs to be recognized.

Note: I found out after a long time of research here that the lib library is divided into a static library, which contains all the information of the code; a lib import library only describes the relevant information in the dll, and the runtime needs to rely on the dll for reference : A comprehensive explanation of lib library knowledge (.lib, .dll)_zxmyoung’s blog-CSDN blog

2.3: .dll.a type file (also a dynamic library)

The .dll.a type file is the imp-lib of the DLL file under MinGW, which is similar to the import library .lib attached to the DLL file under MSVS.

==== “1: Compile under qt and build with MinGW, you can rely on the .dll.a file, but you still have to find the relevant dll file when running

==== “2: qt also supports direct dependence on dll and lib, so the .dll.a type files are not concerned, and may need to be concerned when generating related dynamic libraries with MinGW.

3: Test with demo.

1: Test with the 64-bit ffmpeg-5.1.2 version downloaded above.

===》Create a new qt project, associate related dependencies, and use the following dependencies in the .pro file to use related header files and functions.

=======”(Because there is no response when encountering code execution, exit, exit code: -1073741515 {1 ?} {2?} The research environment is time-consuming, so take notes)

# $$PWD represents the directory of the project ffmpeg-5.1.2 is to copy the package downloaded above to the project directory
# After testing, the following two dependency methods are feasible. I tested both MinGw 64 and msvc-2019 64. There is no problem with compiling

#win32 {<!-- -->
#INCLUDEPATH += $$PWD/ffmpeg-5.1.2/include
#LIBS += $$PWD/ffmpeg-5.1.2/lib/avformat.lib \
# $$PWD/ffmpeg-5.1.2/lib/avcodec.lib \
# $$PWD/ffmpeg-5.1.2/lib/avdevice.lib \
# $$PWD/ffmpeg-5.1.2/lib/avfilter.lib \
# $$PWD/ffmpeg-5.1.2/lib/avutil.lib \
# $$PWD/ffmpeg-5.1.2/lib/postproc.lib \
# $$PWD/ffmpeg-5.1.2/lib/swresample.lib \
# $$PWD/ffmpeg-5.1.2/lib/swscale.lib
#}

win32 {<!-- -->
INCLUDEPATH += $$PWD/ffmpeg-5.1.2/include
LIBS += $$PWD/ffmpeg-5.1.2/lib/libavformat.dll.a \
        $$PWD/ffmpeg-5.1.2/lib/libavcodec.dll.a \
        $$PWD/ffmpeg-5.1.2/lib/libavdevice.dll.a \
        $$PWD/ffmpeg-5.1.2/lib/libavfilter.dll.a\
        $$PWD/ffmpeg-5.1.2/lib/libavutil.dll.a \
        $$PWD/ffmpeg-5.1.2/lib/libpostproc.dll.a \
        $$PWD/ffmpeg-5.1.2/lib/libswresample.dll.a \
        $$PWD/ffmpeg-5.1.2/lib/libswscale.dll.a
}

2: After building, run directly, there is an error

1: Error 1: If msvc-2019 64 is used to build, an error will be reported when running The CDB process terminated.

The problem is because the dependent dll files are not imported.

Import the dll that the dynamic library depends on into the project file generated after the build.

2: Problem 2: If you use MinGW 64 to build, there is no response when running.

Importing the dll that the dynamic library depends on into the project file generated after the build can solve the problem.

3: Build the debug version, click to run when the relevant dll is not copied, there is no response.

Or directly build the release version, but when the dependent dll files are not copied.

Error (qt_test.exe exited, exit code: -1073741515
{1?} {2?})

3: View the dependencies corresponding to the exe generated after compilation

It can be seen that the compiled exe depends on the dll files, and the relevant dependent dlls are either placed in the environment variable, or prevented from being in the same level directory of the exe.

F:\qt_project_data\build-untitled3-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug\debug>dumpbin /dependents untitled3.exe
Microsoft (R) COFF/PE Dumper Version 14.29.30148.0
Copyright (C) Microsoft Corporation. All rights reserved.


Dump of file untitled3.exe

File Type: EXECUTABLE IMAGE

  Image has the following dependencies:

    avutil-57.dll
    KERNEL32.dll
    VCRUNTIME140D.dll
    ucrtbased.dll

  Summary

        1000.00cfg
        1000.data
        1000 .idata
        1000.pdata
        2000.rdata
        1000.reloc
        1000.rsrc
        7000.text

4: Summary of this article:

I am not familiar with the qt-related environment. When I was testing, I encountered the problem that the build was successful but the operation did not respond. I struggled with it for a long time and there was a blockage, so I made this arrangement.

During the exploration process, the following points should be noted:

1: When building qt, pay attention to the selected construction method, and the dependent dynamic library should correspond to the 32/64 version of the construction method, and the corresponding dependency location should be configured in the pro file.

2: An error message “The CDB process terminated.” is reported when running, or there is no response during running, most likely because the dll dependency is incorrect, and the corresponding dependent dll needs to be copied to the build directory.

==== “At the same time, it should be noted that when the debug version and the release version are built, the error report when clicking the direct run is different from the error report when the debug run is executed. (They all do not correspond to dll files)

3: When taking the library for testing, it is found that there is a .dll.a file, which is actually the same concept as the lib import library, and the actual operation needs to depend on the dll file.

4: In addition, it is also possible to directly copy the relevant dll to the win directory, so you don’t need to copy it every time, and don’t study it.

syntaxbug.com © 2021 All Rights Reserved.