ffmpeg - 将ffmpeg添加到clion项目

标签 ffmpeg cmake clion

我想将 ffmpeg 添加到 Clion,但我有一些问题。
我的 MakeLists.txt 看起来像这样:

cmake_minimum_required(VERSION 3.10)
project(ffmpeg)

set(CMAKE_CXX_STANDARD 11)

include_directories(libs/ffmpeg/)
include_directories(libs/ffmpeg/include/libavutil/)
include_directories(libs/ffmpeg/include/libaccodec/)
include_directories(libs/ffmpeg/include/libavdevice/)
include_directories(libs/ffmpeg/include/libavfilter/)
include_directories(libs/ffmpeg/include/libavformat/)

include_directories(libs/ffmpeg/include/)
link_directories(libs/ffmpeg/lib/)

set(SOURCE_FILES main.cpp)


add_executable(ffmpeg main.cpp)

target_link_libraries(
        ffmpeg
        avcodec
        avdevice
        avfilter
        avformat
        avresample
        avutil
        postproc
        swresample
        swscale
)

我不确定我是否以正确的方式添加了库和包含,因为在我的简单 main.cpp 中它无法解析 avcodec_configuration()。
我的项目布局如下所示:
  ffmpeg
    -libs
      -include
        -libavcodec
        .
        .
        .
      -lib
        -avcodec.lib
    -main.cpp

编辑:
现在所有包含都被编译器找到了。但是,如果我编译我会收到以下错误:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lavresample
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [ffmpeg.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/ffmpeg.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
CMakeFiles\ffmpeg.dir\build.make:96: recipe for target 'ffmpeg.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/ffmpeg.dir/all' failed
Makefile:82: recipe for target 'all' failed

最佳答案

我不建议在 CMakeLists.txt 中硬编码指向 header /库的路径。 ;这不是可移植的。

  • 搜索准备好的FindFFmpeg.cmake (也许 this one 会起作用?),
  • 将其添加到您的项目目录(例如,添加到 cmake/ 子目录),
  • connect itCMAKE_MODULE_PATH .例如。 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") .
  • 然后引用${FFMPEG_LIBRARIES} , ${FFMPEG_INCLUDE_DIRS}${FFMPEG_DEFINITIONS} .

  • 有时您必须修复 FindXXX.cmake模块。

    关于ffmpeg - 将ffmpeg添加到clion项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50676532/

    相关文章:

    ffmpeg - 具有 4 channel 音频 : how to create proxies (high quality/small file size) and preserve the audio mapping 的 MXF

    video - ffmpeg 在另一个视频上叠加视频

    c++ - 无法包含 Clion 库中的文件

    php - 从 php shell_exec 运行 ffmpeg 时如何添加空格

    objective-c - Flac 转换器 Objective-C?

    opencv - 在 Ubuntu/Linux 上用 C++ 编译 OpenCV 代码的 Makefile

    python - OpenCV Python 链接器错误

    c++ - 从自定义目录运行 ctest

    c - 在 Windows 上使用 Cmake/CLion 编译 lzma 库的一种简单方法?

    c++ - CLion 中的 undefined reference