gpt4 book ai didi

c++ - 如何在 Linux 上的 Flutter 插件中使用 CMake 正确链接 ffmpeg?

转载 作者:行者123 更新时间:2023-12-04 23:18:24 25 4
gpt4 key购买 nike

我为 Linux 编写了一个 Flutter 插件,它使用 ffmpeg而且我在构建使用该插件的示例应用程序时遇到了麻烦。我不断收到错误,提示没有对多个 ffmpeg 的匹配调用功能,我实际上可以点击查看。为什么会发生这种情况,我能做些什么来解决它?
这是我的插件的CMakeLists.txt :

cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME "thumblr_linux")
project(${PROJECT_NAME} LANGUAGES CXX)

# This value is used when generating builds using this plugin, so it must
# not be changed
set(PLUGIN_NAME "thumblr_linux_plugin")

add_subdirectory(FFmpeg)

add_library(${PLUGIN_NAME} SHARED
"thumblr_linux_plugin.cc"
)
apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK FFmpgeg)

# List of absolute paths to libraries that should be bundled with the plugin
set(thumblr_linux_bundled_libraries
""
PARENT_SCOPE
)
这是我的 FFmpeg/CMakeLists.txt :
cmake_minimum_required(VERSION 3.14)
project(FFmpeg)

find_package(PkgConfig REQUIRED)
pkg_check_modules(AVCODEC REQUIRED IMPORTED_TARGET libavcodec)
pkg_check_modules(AVFORMAT REQUIRED IMPORTED_TARGET libavformat)
pkg_check_modules(AVFILTER REQUIRED IMPORTED_TARGET libavfilter)
pkg_check_modules(AVDEVICE REQUIRED IMPORTED_TARGET libavdevice)
pkg_check_modules(AVUTIL REQUIRED IMPORTED_TARGET libavutil)
pkg_check_modules(SWRESAMPLE REQUIRED IMPORTED_TARGET libswresample)
pkg_check_modules(SWSCALE REQUIRED IMPORTED_TARGET libswscale)

add_library(FFmpeg INTERFACE IMPORTED GLOBAL)

target_link_libraries(FFmpeg INTERFACE
PkgConfig::AVCODEC
PkgConfig::AVFORMAT
PkgConfig::AVFILTER
PkgConfig::AVDEVICE
PkgConfig::AVUTIL
PkgConfig::SWRESAMPLE
PkgConfig::SWSCALE
)
这是我在构建时收到的错误消息:
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:80:9: error: no matching function for call to 'avformat_open_input'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:84:9: error: no matching function for call to 'avformat_find_stream_info'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:88:5: error: no matching function for call to 'av_dump_format'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:102:61: error: assigning to 'AVCodecContext *' from incompatible type 'AVCodecParameters *'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:111:9: error: use of undeclared identifier 'avcodec_open'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:119:14: error: use of undeclared identifier 'avcodec_alloc_frame'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:122:17: error: use of undeclared identifier 'avcodec_alloc_frame'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:127:16: error: no matching function for call to 'atk_image_get_image_size'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:133:5: error: use of undeclared identifier 'av_image_fill_arrays'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:144:9: error: use of undeclared identifier 'avcodec_decode_video'
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:179:15: error: unused variable 'ret' [-Werror,-Wunused-variable]
/home/parallels/flutter_projects/thumblr/thumblr_linux/example/linux/flutter/ephemeral/.plugin_symlinks/thumblr_linux/linux/thumblr_linux_plugin.cc:211:5: error: no matching function for call to 'avformat_close_input'
插件本身的 C++ 代码可以在这里找到: https://github.com/GroovinChip/thumblr/blob/main/thumblr_linux/linux/thumblr_linux_plugin.cc

最佳答案

ffmpeg 是用 C 编写的,因此对于 C++,您需要包含如下标题:

extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libswscale/swscale.h>
}

关于c++ - 如何在 Linux 上的 Flutter 插件中使用 CMake 正确链接 ffmpeg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71782871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com