修正libavfilter相关的编译问题和transcode内的错误 (#4587)

1. 最近提交的libavfilter相关的代码,没有充分测试cmake编译问题,提交了修正。
2. transcode内存在一个c++11的兼容性问题和运算符优先级问题,提交了修正。
This commit is contained in:
Robo
2025-12-09 15:34:15 +08:00
committed by GitHub
parent 1da300cf3e
commit 5f0edeed6a
4 changed files with 64 additions and 8 deletions

View File

@@ -44,6 +44,7 @@ option(ENABLE_FFMPEG "Enable FFmpeg" OFF)
option(ENABLE_HLS "Enable HLS" ON)
option(ENABLE_JEMALLOC_STATIC "Enable static linking to the jemalloc library" OFF)
option(ENABLE_JEMALLOC_DUMP "Enable jemalloc to dump malloc statistics" OFF)
option(ENABLE_TCMALLOC "Enable linking to the tcmalloc library" OFF)
option(ENABLE_MEM_DEBUG "Enable Memory Debug" OFF)
option(ENABLE_MP4 "Enable MP4" ON)
option(ENABLE_MSVC_MT "Enable MSVC Mt/Mtd lib" ON)
@@ -256,8 +257,8 @@ endif()
# Multiple modules depend on ffmpeg related libraries, unified search
if(ENABLE_FFMPEG)
find_package(PkgConfig QUIET)
# 查找 ffmpeg/libutil 是否安装
# find ffmpeg/libutil installed
# 查找 ffmpeg/libavutil 是否安装
# find ffmpeg/libavutil installed
if(PKG_CONFIG_FOUND)
pkg_check_modules(AVUTIL QUIET IMPORTED_TARGET libavutil)
if(AVUTIL_FOUND)
@@ -296,8 +297,19 @@ if(ENABLE_FFMPEG)
endif()
endif()
# 查找 ffmpeg/libutil 是否安装
# find ffmpeg/libutil installed
# 查找 ffmpeg/libavfilter 是否安装
# find ffmpeg/libavfilter installed
if(PKG_CONFIG_FOUND)
pkg_check_modules(AVFILTER QUIET IMPORTED_TARGET libavfilter)
if(AVFILTER_FOUND)
update_cached_list(MK_LINK_LIBRARIES PkgConfig::AVFILTER)
message(STATUS "found library: ${AVFILTER_LIBRARIES}")
endif()
endif()
# 查找 ffmpeg/libavutil 是否安装
# find ffmpeg/libavutil installed
if(NOT AVUTIL_FOUND)
find_package(AVUTIL QUIET)
if(AVUTIL_FOUND)
@@ -349,7 +361,6 @@ if(ENABLE_FFMPEG)
endif()
endif()
if(AVUTIL_FOUND AND AVCODEC_FOUND AND SWSCALE_FOUND AND SWRESAMPLE_FOUND AND AVFILTER_FOUND)
update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_FFMPEG)
update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS})
@@ -411,6 +422,19 @@ if(JEMALLOC_FOUND)
endif ()
endif()
# 查找 tcmalloc 是否安装
# find tcmalloc installed
if(ENABLE_TCMALLOC)
find_package(TCMALLOC QUIET)
if(TCMALLOC_FOUND)
message(STATUS "Link with tcmalloc library: ${TCMALLOC_LIBRARIES}")
update_cached_list(MK_LINK_LIBRARIES ${TCMALLOC_LIBRARIES})
else()
set(ENABLE_TCMALLOC OFF)
message(WARNING "tcmalloc 相关功能未找到")
endif()
endif()
# 查找 openssl 是否安装
# find openssl installed
find_package(OpenSSL QUIET)

16
cmake/FindAVFILTER.cmake Normal file
View File

@@ -0,0 +1,16 @@
find_path(AVFILTER_INCLUDE_DIR
NAMES libavfilter/avfilter.h
HINTS ${FFMPEG_PATH_ROOT}
PATH_SUFFIXES include)
find_library(AVFILTER_LIBRARY
NAMES avfilter
HINTS ${FFMPEG_PATH_ROOT}
PATH_SUFFIXES bin lib)
set(AVFILTER_LIBRARIES ${AVFILTER_LIBRARY})
set(AVFILTER_INCLUDE_DIRS ${AVFILTER_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(AVFILTER DEFAULT_MSG AVFILTER_LIBRARY AVFILTER_INCLUDE_DIR)

16
cmake/FindTCMALLOC.cmake Normal file
View File

@@ -0,0 +1,16 @@
find_path(Tcmalloc_INCLUDE_DIR
NAMES google/tcmalloc.h
)
find_library(Tcmalloc_LIBRARY
NAMES tcmalloc_minimal tcmalloc
)
set(TCMALLOC_LIBRARIES ${Tcmalloc_LIBRARY})
set(TCMALLOC_INCLUDE_DIRS ${Tcmalloc_INCLUDE_DIR})
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TCMALLOC
DEFAULT_MSG
TCMALLOC_LIBRARIES TCMALLOC_INCLUDE_DIRS
)

View File

@@ -239,7 +239,7 @@ AVFrame *FFmpegFrame::get() const {
void FFmpegFrame::fillPicture(AVPixelFormat target_format, int target_width, int target_height) {
auto buffer_size = av_image_get_buffer_size(target_format, target_width, target_height, 32);
_data = std::make_unique<char[]>(buffer_size);
_data = std::unique_ptr<char[]>(new char[buffer_size]);
av_image_fill_arrays(_frame->data, _frame->linesize, (uint8_t *)_data.get(), target_format, target_width, target_height, 32);
}
@@ -839,14 +839,14 @@ std::tuple<bool, std::string> FFmpegUtils::saveFrame(const FFmpegFrame::Ptr &fra
buffersrc = avfilter_get_by_name("buffer");
if (ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, _filter_graph.get()) < 0) {
if ((ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", args, NULL, _filter_graph.get())) < 0) {
ss << "avfilter_graph_create_filter buffersrc failed: " << ret << " " << ffmpeg_err(ret);
DebugL << ss;
return make_tuple<bool, std::string>(false, ss.data());
}
buffersink = avfilter_get_by_name("buffersink");
if (ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, _filter_graph.get()) < 0) {
if ((ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", NULL, NULL, _filter_graph.get())) < 0) {
ss << "avfilter_graph_create_filter buffersink failed: " << ret << " " << ffmpeg_err(ret);
return make_tuple<bool, std::string>(false, ss.data());
}