Bundle FFmpeg with Qt6 application using CMake
-
@Christian-Ehrlicher said in Bundle FFmpeg with Qt6 application using CMake:
I even asked ChatGPT :)
Yeah, we're going to be out of business soon, no longer needed....
-
@Christian-Ehrlicher said in Bundle FFmpeg with Qt6 application using CMake:
@Ali-Fadel said in Bundle FFmpeg with Qt6 application using CMake:
I even asked ChatGPT :)
wtf?
main.cpp:6:10: In included file: 'libavutil/avconfig.h' file not found
As you can see you have to add the include directory which contains the
libavutil
directory so the compiler can findlibavutil/avconfig.h
As you can see in the CMake configs I attached above I'm including
libavutil
directory. The other issue that I can't findavconfig.h
file when I navigate to the folder.I found some people saying that this file is auto-generated by running
./configure
executable within FFmpeg source code. I don't have any idea about this TBH. -
@Ali-Fadel if you can not find the header files which your project needs, that means your fetch might grab only libs., but not the all dev packages which have include dir and all header files. clone FFmpeg manually and see what you get.
-
ffmpeg is not a CMake based project, so just fetching source from GitHub and including some headers is not gonna work.
You need to build ffmpeg first. This includes running the configure script and then make and make install. See here. This will create a directory which will have a set of header files for including and built shared libraries. It will also generate that missing config header.
With ffmpeg built you can then populate
target_include_directories
andtarget_link_libraries
with paths to that build artifacts. Alsotarget_link_libraries
is for linking libraries. Adding header files there like you did makes no sense.If you don't want to build ffmpeg yourself you can look for a prebuilt version that you can fetch or use a package manager that will take care of the fetch and build for you.
-
@Ali-Fadel said in Bundle FFmpeg with Qt6 application using CMake:
As you can see you have to add the include directory which contains the libavutil directory so the compiler can find libavutil/avconfig.h
As you can see in the CMake configs I attached above I'm including libavutil directory.
And now re-read my answer and your response and adjust your target_include_directories() call to include the correct directory.
-
Thanks all for your explanation!
I will give it another try and see what happens, I tried to build ffmpeg myself on macos but it failed with multiple errors related to missing packages while they are already installed.
I will try to find a prebuilt version and use it. -
Hello everyone, I found this FFmpeg setup: https://github.com/thomas-moulard/visp-deb/blob/master/CMakeModules/FindFFMPEG.cmake, and I used it in my project and it works fine now.
I used it in this way:
FIND_PATH(FFMPEG_INCLUDE_DIR_AVUTIL NAMES libavutil/avutil.h) FIND_PATH(FFMPEG_INCLUDE_DIR_AVCODEC NAMES libavcodec/avcodec.h) FIND_PATH(FFMPEG_INCLUDE_DIR_AVFORMAT NAMES libavformat/avformat.h) FIND_PATH(FFMPEG_INCLUDE_DIR_AVDEVICE NAMES libavdevice/avdevice.h) FIND_PATH(FFMPEG_INCLUDE_DIR_AVFILTER NAMES libavfilter/avfilter.h) FIND_PATH(FFMPEG_INCLUDE_DIR_SWSCALE NAMES libswscale/swscale.h) FIND_PATH(FFMPEG_INCLUDE_DIR_SWRESAMPLE NAMES libswresample/swresample.h) FIND_PATH(FFMPEG_INCLUDE_DIR_POSTPROC NAMES libpostproc/postprocess.h) target_include_directories(taqtie PRIVATE ${FFMPEG_INCLUDE_DIR_AVUTIL} ${FFMPEG_INCLUDE_DIR_AVCODEC} ${FFMPEG_INCLUDE_DIR_AVFORMAT} ${FFMPEG_INCLUDE_DIR_AVDEVICE} ${FFMPEG_INCLUDE_DIR_AVFILTER} ${FFMPEG_INCLUDE_DIR_SWSCALE} ${FFMPEG_INCLUDE_DIR_SWRESAMPLE} ${FFMPEG_INCLUDE_DIR_POSTPROC} ) FIND_LIBRARY(FFMPEG_AVUTIL_LIBRARY NAMES avutil) FIND_LIBRARY(FFMPEG_AVCODEC_LIBRARY NAMES avcodec) FIND_LIBRARY(FFMPEG_AVFORMAT_LIBRARY NAMES avformat) FIND_LIBRARY(FFMPEG_AVDEVICE_LIBRARY NAMES avdevice) FIND_LIBRARY(FFMPEG_AVFILTER_LIBRARY NAMES avfilter) FIND_LIBRARY(FFMPEG_SWSCALE_LIBRARY NAMES swscale) FIND_LIBRARY(FFMPEG_SWRESAMPLE_LIBRARY NAMES swresample) FIND_LIBRARY(FFMPEG_POSTPROC_LIBRARY NAMES postproc) target_link_libraries(taqtie PRIVATE ${FFMPEG_AVUTIL_LIBRARY} ${FFMPEG_AVCODEC_LIBRARY} ${FFMPEG_AVFORMAT_LIBRARY} ${FFMPEG_AVDEVICE_LIBRARY} ${FFMPEG_AVFILTER_LIBRARY} ${FFMPEG_SWSCALE_LIBRARY} ${FFMPEG_SWRESAMPLE_LIBRARY} ${FFMPEG_POSTPROC_LIBRARY} )
And finally I can import the libraries like this:
#include <libavutil/avutil.h> #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavdevice/avdevice.h> #include <libavfilter/avfilter.h> #include <libswscale/swscale.h> #include <libswresample/swresample.h> #include <libpostproc/postprocess.h>
Thanks for your help! Very appreciated.
-
I faced a weird issue after including FFmpeg directories and libraries. When I start my application in debug mode and try to use
QFileDialog::getOpenFileName
, it crashes immediately, but when I run the executable, it works fine. I don't know why. Any thoughts? -
I tried that also, and nothing changed. Here is my CMakeLists.txt:
include(FetchContent) cmake_minimum_required(VERSION 3.5) project(taqtie VERSION 0.1 LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_BUILD_TYPE Debug) find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core LinguistTools) # For more information, see https://github.com/pedrolcl/qt-i18n include(TranslationUtils) set(PROJECT_SOURCES main.cpp enums/section_columns.h helpers/file_helpers.h helpers/file_helpers.cpp helpers/process_helpers.h helpers/process_helpers.cpp helpers/time_helpers.h helpers/time_helpers.cpp models/section_info.h models/section_info.cpp readers/sections_reader.h readers/sections_reader.cpp windows/main_window.h windows/main_window.cpp windows/main_window.ui windows/about_window.h windows/about_window.cpp windows/about_window.ui wrappers/ffmpeg_wrapper.h wrappers/ffmpeg_wrapper.cpp ) # set(TS_FILES # i18n_ar.ts # i18n_en.ts # ) # qt_add_translation(QM_FILES ${TS_FILES}) # add_app_translations_resource(APP_RES ${QM_FILES}) add_qt_translations_resource(QT_RES ar) if (WIN32) set(app_icon "${CMAKE_CURRENT_SOURCE_DIR}/resources/taqtie.rc") elseif (APPLE) set(MACOSX_BUNDLE_ICON_FILE taqtie.icns) set(app_icon "${CMAKE_CURRENT_SOURCE_DIR}/resources/taqtie.icns") set_source_files_properties(${app_icon} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") endif() qt_add_executable(taqtie MANUAL_FINALIZATION ${PROJECT_SOURCES} # ${APP_RES} ${QT_RES} ${app_icon} ) target_link_libraries(taqtie PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) target_link_libraries(taqtie PRIVATE Qt${QT_VERSION_MAJOR}::Core) set_target_properties(taqtie PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER taqtie.ieasybooks.com MACOSX_BUNDLE_BUNDLE_NAME تقطيع MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} OUTPUT_NAME تقطيع MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) set(taqtie_resource_files "resources/taqtie.png" ) qt6_add_resources(taqtie "taqtie" PREFIX "/" FILES ${taqtie_resource_files} ) install(TARGETS taqtie BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) qt_finalize_executable(taqtie) # QXlsx Setup FetchContent_Declare( QXlsx GIT_REPOSITORY https://github.com/QtExcel/QXlsx.git GIT_TAG b5585decd4e1d30ddd6563556c1c6a8da6753492 SOURCE_SUBDIR QXlsx ) FetchContent_MakeAvailable(QXlsx) target_link_libraries(taqtie PRIVATE QXlsx::QXlsx) # FFmpeg Setup # This setup was found here: https://github.com/thomas-moulard/visp-deb/blob/master/CMakeModules/FindFFMPEG.cmake. # For more information, check the discussion here: https://forum.qt.io/topic/141950/bundle-ffmpeg-with-qt6-application-using-cmake. FIND_PATH(FFMPEG_INCLUDE_DIR_AVUTIL NAMES libavutil/avutil.h) FIND_PATH(FFMPEG_INCLUDE_DIR_AVCODEC NAMES libavcodec/avcodec.h) FIND_PATH(FFMPEG_INCLUDE_DIR_AVFORMAT NAMES libavformat/avformat.h) target_include_directories(taqtie PRIVATE ${FFMPEG_INCLUDE_DIR_AVUTIL} ${FFMPEG_INCLUDE_DIR_AVCODEC} ${FFMPEG_INCLUDE_DIR_AVFORMAT} ) FIND_LIBRARY(FFMPEG_AVUTIL_LIBRARY NAMES avutil) FIND_LIBRARY(FFMPEG_AVCODEC_LIBRARY NAMES avcodec) FIND_LIBRARY(FFMPEG_AVFORMAT_LIBRARY NAMES avformat) target_link_libraries(taqtie PRIVATE ${FFMPEG_AVUTIL_LIBRARY} ${FFMPEG_AVCODEC_LIBRARY} ${FFMPEG_AVFORMAT_LIBRARY} )
And this is the crash report from MacOS: https://justpaste.it/ap67u.
Sorry for the long post, but I can post every 5 minutes only, that is why I put all information I have here.
-
Ok, just to finalize this. Instead of the cmake code I attached above to link FFmpeg libraries, I used the same FindFFmpeg.cmake file that used by OBS Studio project on GitHub, and it worked as expected!
I don't know what is the difference yet, I need to read through it carefully and find the differences.