当前位置: 首页 > news >正文

完整指南:CNStream流处理多路并发框架适配到NVIDIA Jetson Orin (三) 代码编译、各种问题解决、代码修改

目录

1 infer_server编译

1.1 infer_server/CMakeLists.txt修改

1.2 FindLibCompute.cmake编写

1.2 findLibCVCuda.cmake编写

1.3 ./3rdparty/config_lib_aarch64.sh修改

1.4 解决各种编译错误

1.4.1 /usr/include/c++/11/bits/algorithmfwd.h:259:5: error: ‘pair’ does not name a type

1.4.2 no matching function for call to ‘std::unique_ptr::unique_ptr(trt::trtnet_t*&, infer_server::M

1.4.3 /usr/include/c++/11/iosfwd:193:11: error: ‘basic_ostringstream’ does not name a type; did you mean ‘basic_ostream’?

1.4.4 error: no declaration matches ‘bool infer_server::DecodeFFmpeg::Create(VdecCreateParams*)’

1.4.5 error: ‘TRANSFORM_COMPUTE_CVCUDA’ was not declared in this scope; did you mean ‘TRANSFORM_COMPUTE_NVCUDA’?

1.4.6 error: ‘shared_ptr’ in namespace ‘std’ does not name a template type

1.4.7 error: ‘cuCreateStream’ was not declared in this scope

1.4.8 error: ‘BUF_MEMORY_DVPP’ was not declared in this scope; did you mean ‘BUF_MEMORY_HOST’?

2 整体工程cmake

2.1By not providing "FindLibAclLite.cmake" in CMAKE_MODULE_PATH this projec

3 编译framework

4 编译modules

4.1 atal error: cuda_runtime.h: No such file or directory

5 编译app

5.1 error: ‘BUF_MEMORY_NORMAL’ was not declared in this scope; did you mean ‘BUF_MEMORY_HOST’?

5.2 warning: libavformat.so.59, needed by /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so, not found (try using -rpath or -rpath-link)

5.3 undefined reference to `av_dict_free(AVDictionary**)'

5.4 /data/chw/nvstream/3rdparty/freetype/lib/linux_lib/libfreetype.so.6: undefined reference to `fstat@GLIBC_2.33'

参考文献:


记录下将CNStream流处理多路并发Pipeline框架适配到NVIDIA Jetson AGX Orin的过程,以及过程中遇到的问题,我的jetson盒子是用jetpack5.1.3重新刷机之后的,这是系列博客的第三篇。

这篇博客记录下编译步骤、编译过程中遇到的各种问题、问题解决步骤。中间特别简单的错误就不记录了,只记录稍微有点代表性的错误。

1 infer_server编译

先编译inferserver模块,一个模块一个模块的编译。

1.1 infer_server/CMakeLists.txt修改

cmake_minimum_required(VERSION 3.5)# ---[ nvis project
project(nvis C CXX)#######################################################################
# -- Build Flagsoption(NVIS_RECORD_PERF "Enable record performance" OFF)#######################################################################
set(NVIS_VERSION_MAJOR 1)
set(NVIS_VERSION_MINOR 0)
set(NVIS_VERSION_PATCH 0)
set(NVIS_VERSION "${NVIS_VERSION_MAJOR}.${NVIS_VERSION_MINOR}.${NVIS_VERSION_PATCH}")configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in${CMAKE_CURRENT_SOURCE_DIR}/include/nvis/config.h)set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")# set runtime path
set(CNSTREAM_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(CMAKE_MODULE_PATH "${CNSTREAM_ROOT_PATH}/cmake")# ---[ Compute
find_package(LibCompute)
if(NOT LibCompute_FOUND)message(FATAL_ERROR "LibCompute not found!")
endif()# ---[ CVC-CUDA
find_package(LibCVCuda)
if(NOT LibCVCuda_FOUND)message(FATAL_ERROR "LibCVCuda not found!")
endif()# ---[ Google-glog
find_package(Glog)
if(NOT Glog_FOUND)message(FATAL_ERROR "Glog not found!")
endif()# ---[ Google-gflags
find_package(GFlags)
if(NOT GFlags_FOUND)message(FATAL_ERROR "GFlags not found!")
endif()file(GLOB_RECURSE contrib_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE infer_server_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/core/*.cpp${CMAKE_CURRENT_SOURCE_DIR}/src/model/*.cpp${CMAKE_CURRENT_SOURCE_DIR}/src/processor/*.cpp${CMAKE_CURRENT_SOURCE_DIR}/src/nv/*.cpp${CMAKE_CURRENT_SOURCE_DIR}/src/util/*.cpp)set(LIBRARY_OUTPUT_PATH ${CNSTREAM_ROOT_PATH}/lib)
message(STATUS "@@@@@@@@@@@ Target : nvis")
add_library(nvis SHARED ${infer_server_srcs} ${contrib_srcs})if (NVIS_RECORD_PERF)target_compile_definitions(D PRIVATE NVIS_RECORD_PERF)
endif()target_include_directories(nvis PRIVATE${LibCompute_INCLUDE_DIRS}${LibCVCuda_INCLUDE_DIRS}${CMAKE_CURRENT_SOURCE_DIR}/include${CMAKE_CURRENT_SOURCE_DIR}/src${GLOG_INCLUDE_DIRS}${GFLAGS_INCLUDE_DIRS})target_link_libraries(nvis PRIVATE ${LibCompute_LIBRARIES} ${LibCVCuda_LIBRARIES} ${GLOG_LIBRARIES})set_target_properties(nvis PROPERTIES VERSION ${NVIS_VERSION})
set_target_properties(nvis PROPERTIES SOVERSION ${NVIS_VERSION_MAJOR})

然后还需要编写两个findxxx.cmake文件

1.2 FindLibCompute.cmake编写

# - Try to find Compute headers and libraries.
#
# Usage of this module as follows:
#
#     find_package(LibCompute)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
#  LibCompute_ROOT_DIR  Set this variable to the root installation of
#                    LibCompute if the module has problems finding
#                    the proper installation path.
#
# Variables defined by this module:
#
#  LibCompute_FOUND              System has LibCompute libs/headers
#  LibCompute_LIBRARIES          The LibCompute libraries
#  LibCompute_INCLUDE_DIRS        The location of LibCompute headersfind_path(LibCompute_ROOT_DIRNAMES include/export_funtions.hPATHS ${CNSTREAM_ROOT_PATH}/3rdparty/jetson/compute
)find_path(LibCompute_INCLUDE_DIRSNAMES export_funtions.hPATHS ${LibCompute_ROOT_DIR}/include
)find_path(LibCompute_CUDA_INCLUDE_DIRSNAMES cuda_runtime.hPATHS ${LibCompute_ROOT_DIR}/include/cuda
)set(LibCompute_LIBRARIES "")
set(COMPUTE_LIBS cudart trteng_exp cuda_utils)
foreach(lib ${COMPUTE_LIBS})find_library(LibCompute_LIBRARIES_${lib}NAMES ${lib}PATHS ${LibCompute_ROOT_DIR}/lib/linux_libNO_DEFAULT_PATH)if(LibCompute_LIBRARIES_${lib})list(APPEND LibCompute_LIBRARIES ${LibCompute_LIBRARIES_${lib}})endif()
endforeach()if (LibCompute_INCLUDE_DIRS)list(APPEND LibCompute_INCLUDE_DIRS ${LibCompute_CUDA_INCLUDE_DIRS})
endif ()if (LibCompute_LIBRARIES)set(LibCompute_FOUND TRUE)
endif ()

1.2 findLibCVCuda.cmake编写

# - Try to find CVCuda headers and libraries.
#
# Usage of this module as follows:
#
#     find_package(LibCVCuda)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
#  LibCVCuda_ROOT_DIR  Set this variable to the root installation of
#                    LibCVCuda if the module has problems finding
#                    the proper installation path.
#
# Variables defined by this module:
#
#  LibCVCuda_FOUND              System has LibCVCuda libs/headers
#  LibCVCuda_LIBRARIES          The LibCVCuda libraries
#  LibCVCuda_INCLUDE_DIRS        The location of LibCVCuda headersfind_path(LibCVCuda_ROOT_DIRNAMES include/cvcuda/Version.hPATHS ${CNSTREAM_ROOT_PATH}/3rdparty/jetson/cvcuda
)find_path(LibCVCuda_INCLUDE_DIRSNAMES cvcuda/Version.hPATHS ${LibCVCuda_ROOT_DIR}/include
)find_library(LibCVCuda_LIBRARIESNAMES cvcudaPATHS ${LibCVCuda_ROOT_DIR}/lib/linux_lib
)find_library(LibNVCV_Types_LIBRARIESNAMES nvcv_typesPATHS ${LibCVCuda_ROOT_DIR}/lib/linux_lib
)if (LibCVCuda_LIBRARIES)list(APPEND LibCVCuda_LIBRARIES ${LibNVCV_Types_LIBRARIES})set(LibCVCuda_FOUND TRUE)
endif ()

然后直接

cd /data/chw/nvstream/infer_server/build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j4

然后满屏幕的报错。。。。。。。。。。。。。,

1.3 ./3rdparty/config_lib_aarch64.sh修改

在里面增加cuda相关的库的软链接配置。

#!/bin/bash#创建软连接脚本
#------------------
root=$(pwd)
arch=aarch64#----------------------------------
# jetson: compute cuda
#----------------------------------
cd ${root}/jetson/compute/lib/linux_lib
\cp ../${arch}/* .#1> Cuda
ln -snf libcublas.so.11.6.6.84 libcublas.so.11
ln -snf libcublas.so.11 libcublas.soln -snf libcublasLt.so.11.6.6.84 libcublasLt.so.11
ln -snf libcublasLt.so.11 libcublasLt.soln -snf libcudart.so.11.4.298 libcudart.so.11.0
ln -snf libcudart.so.11.0 libcudart.so.11
ln -snf libcudart.so.11 libcudart.soln -snf libcurand.so.10.2.5.297 libcurand.so.10
ln -snf libcurand.so.10 libcurand.soln -snf libnvrtc.so.11.4.300 libnvrtc.so.11
ln -snf libnvrtc.so.11 libnvrtc.soln -snf libnvrtc-builtins.so.11.4.300 libnvrtc-builtins.so.11.4
ln -snf libnvrtc-builtins.so.11.4 libnvrtc-builtins.so.11
ln -snf libnvrtc-builtins.so.11 libnvrtc-builtins.soln -snf libcudnn_ops_infer.so.8.6.0 libcudnn_ops_infer.so.8
ln -snf libcudnn_ops_infer.so.8 libcudnn_ops_infer.soln -snf libcudnn_cnn_infer.so.8.6.0 libcudnn_cnn_infer.so.8
ln -snf libcudnn_cnn_infer.so.8 libcudnn_cnn_infer.soln -snf libcudnn.so.8.6.0 libcudnn.so.8
ln -snf libcudnn.so.8 libcudnn.so#2> TensorRT
ln -snf libnvinfer.so.8.5.2 libnvinfer.so.8
ln -snf libnvinfer.so.8 libnvinfer.soln -snf libnvinfer_plugin.so.8.5.2 libnvinfer_plugin.so.8
ln -snf libnvinfer_plugin.so.8 libnvinfer_plugin.so#----------------------------------
# jetson: cv-cuda
#----------------------------------
cd ${root}/jetson/cvcuda/lib/linux_lib
\cp ../${arch}/* .ln -snf libcvcuda.so.0.10.1 libcvcuda.so.0
ln -snf libcvcuda.so.0 libavcodec.soln -snf libnvcv_types.so.0.10.1 libnvcv_types.so.0
ln -snf libnvcv_types.so.0 libavdevice.so#----------------------------------
# ActiveMQ
#----------------------------------
cd ${root}/activemq/lib/linux_lib
\cp ../${arch}/* .cd ${root}/activemq/include
ln -snf apr-1_aarch64 apr-1#----------------------------------
# ffmpeg
#----------------------------------
cd ${root}/ffmpeg/lib/linux_lib
\cp ../${arch}/* .ln -snf libavcodec.so.58.134.100 libavcodec.so.58
ln -snf libavcodec.so.58 libavcodec.soln -snf libavdevice.so.58.13.100 libavdevice.so.58
ln -snf libavdevice.so.58 libavdevice.soln -snf libavfilter.so.7.110.100 libavfilter.so.7
ln -snf libavfilter.so.7 libavfilter.soln -snf libavformat.so.58.76.100 libavformat.so.58
ln -snf libavformat.so.58 libavformat.soln -snf libavutil.so.56.70.100 libavutil.so.56
ln -snf libavutil.so.56 libavutil.soln -snf libswresample.so.3.9.100 libswresample.so.3
ln -snf libswresample.so.3 libswresample.soln -snf libswscale.so.5.9.100 libswscale.so.5
ln -snf libswscale.so.5 libswscale.soln -snf libnvmpi.so.1.0.0 libnvmpi.so.1
ln -snf libnvmpi.so.1 libnvmpi.soln -snf libx264.so.164 libx264.so
ln -snf libx265.so.204 libx265.so#----------------------------------
# opencv
#----------------------------------
cd ${root}/opencv/lib/linux_lib
\cp ../${arch}/* .ln -snf libopencv_core.so.4.6.0 libopencv_core.so.406
ln -snf libopencv_core.so.406 libopencv_core.soln -snf libopencv_highgui.so.4.6.0 libopencv_highgui.so.406
ln -snf libopencv_highgui.so.406 libopencv_highgui.soln -snf libopencv_imgproc.so.4.6.0 libopencv_imgproc.so.406
ln -snf libopencv_imgproc.so.406 libopencv_imgproc.soln -snf libopencv_imgcodecs.so.4.6.0 libopencv_imgcodecs.so.406
ln -snf libopencv_imgcodecs.so.406 libopencv_imgcodecs.soln -snf libopencv_video.so.4.6.0 libopencv_video.so.406
ln -snf libopencv_video.so.406 libopencv_video.soln -snf libopencv_videoio.so.4.6.0 libopencv_videoio.so.406
ln -snf libopencv_videoio.so.406 libopencv_videoio.soln -snf libopencv_features2d.so.4.6.0 libopencv_features2d.so.406
ln -snf libopencv_features2d.so.406 libopencv_features2d.soln -snf libopencv_flann.so.4.6.0 libopencv_flann.so.406
ln -snf libopencv_flann.so.406 libopencv_flann.soln -snf libopencv_calib3d.so.4.6.0 libopencv_calib3d.so.406
ln -snf libopencv_calib3d.so.406 libopencv_calib3d.soln -snf libopencv_dnn.so.4.6.0 libopencv_dnn.so.406
ln -snf libopencv_dnn.so.406 libopencv_dnn.so#----------------------------------
# librdkafka
#----------------------------------
cd ${root}/librdkafka/lib/linux_lib
\cp ../${arch}/* .#----------------------------------
# mqtt
#----------------------------------
cd ${root}/mqtt/lib/linux_lib
\cp ../aarch64/* .
ln -snf libpaho-mqttpp3.so.1.2.0 libpaho-mqttpp3.so.1
ln -snf libpaho-mqttpp3.so.1 libpaho-mqttpp3.soln -snf libpaho-mqtt3a.so.1.3.8 libpaho-mqtt3a.so.1
ln -snf libpaho-mqtt3a.so.1 libpaho-mqtt3a.soln -snf libpaho-mqtt3as.so.1.3.8 libpaho-mqtt3as.so.1
ln -snf libpaho-mqtt3as.so.1 libpaho-mqtt3as.so#----------------------------------
# gflags
#----------------------------------
cd ${root}/gflags/lib/linux_lib
\cp ../${arch}/* .
ln -snf libgflags.so.2.2 libgflags.so.2
ln -snf libgflags.so.2 libgflags.so#----------------------------------
# glog
#----------------------------------
cd ${root}/glog/lib/linux_lib
\cp ../${arch}/* .
ln -snf libglog.so.0 libglog.so#----------------------------------
# uuid
#----------------------------------
cd ${root}/uuid/lib/linux_lib
\cp ../${arch}/* .
ln -snf libuuid.so.1.3.0 libuuid.so.1
ln -snf libuuid.so.1 libuuid.so#----------------------------------
# openssl
#----------------------------------
cd ${root}/openssl/lib/linux_lib
\cp ../${arch}/* .
ln -snf libssl.so.1.1 libssl.so
ln -snf libcrypto.so.1.1 libcrypto.so#----------------------------------
# freetype
#----------------------------------
cd ${root}/freetype/lib/linux_lib
\cp ../${arch}/* .
ln -snf libfreetype.so.6.18.1 libfreetype.so.6
ln -snf libfreetype.so.6 libfreetype.so#----------------------------------
# tcp_pubsub
#----------------------------------
cd ${root}/tcp_pubsub/lib/linux_lib
\cp ../${arch}/* .
ln -snf libtcp_pubsub.so.1.0.0 libtcp_pubsub.so.1
ln -snf libtcp_pubsub.so.1 libtcp_pubsub.so

1.4 解决各种编译错误

1.4.1 /usr/include/c++/11/bits/algorithmfwd.h:259:5: error: ‘pair’ does not name a type

In file included from /usr/include/c++/11/bits/stl_algo.h:60,from /usr/include/c++/11/algorithm:62,from /data/chw/nvstream/infer_server/src/core/data_type.cpp:23:
/usr/include/c++/11/bits/algorithmfwd.h:259:5: error: ‘pair’ does not name a type259 |     pair<_FIter, _FIter>|     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:264:5: error: ‘pair’ does not name a type264 |     pair<_FIter, _FIter>|     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:432:5: error: ‘pair’ does not name a type432 |     pair<const _Tp&, const _Tp&>|     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:437:5: error: ‘pair’ does not name a type437 |     pair<const _Tp&, const _Tp&>|     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:442:5: error: ‘pair’ does not name a type442 |     pair<_FIter, _FIter>|     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:447:5: error: ‘pair’ does not name a type447 |     pair<_FIter, _FIter>|     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:453:9: error: ‘template<class _Tp> _Tp infer_server::std::min’ conflicts with a previous declaration453 |     min(initializer_list<_Tp>);|         ^~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/algorithmfwd.h:425:5: note: previous declaration ‘namespace infer_server::std { }::min’425 |     min(const _Tp&, const _Tp&, _Compare);|     ^~~
/usr/include/c++/11/bits/algorithmfwd.h:453:9: error: ‘initializer_list’ was not declared in this scope; did you mean ‘std::initializer_list’?

这种在标准C++库的头文件中报错的不正常,网上搜都让我加上#include <utility>,但我觉得不应该是修改标准库文件,然后我仔细看了下报错,发现有个

那我觉得应该是这个文件里面哪里写错了,

修改方法

1.4.2 no matching function for call to ‘std::unique_ptr<trt::trtnet_t>::unique_ptr(trt::trtnet_t*&, infer_server::M

/data/chw/nvstream/infer_server/src/model/model.h:114:88: error: no matching function for call to ‘std::unique_ptr<trt::trtnet_t>::unique_ptr(trt::trtnet_t*&, infer_server::Model::GetRunner(int)::<lambda(trt::trtnet_t*)>)’114 |             TEngine engine = TEngine(net, [](trt::trtnet_t* n) { trt::release_net(n); });

修改代码

//using TEngine = std::unique_ptr<trt::trtnet_t>;
using TEngine = std::unique_ptr<trt::trtnet_t, std::function<void(trt::trtnet_t*)>>;

1.4.3 /usr/include/c++/11/iosfwd:193:11: error: ‘basic_ostringstream’ does not name a type; did you mean ‘basic_ostream’?

反正也是满屏幕的报错,

这个原因是因为我现在只是编译的inferser模块,但是里面的DEFER操作确实去找了外面的cnstream命令空间的东西,所以这里在infer_server的命名空间中也再定义一个DEFER

修改infer_server/include/common/utils.hpp

/************************************************************************** Copyright (C) [2022] by Cambricon, Inc. All rights reserved**  Licensed under the Apache License, Version 2.0 (the "License");*  you may not use this file except in compliance with the License.*  You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** The above copyright notice and this permission notice shall be included in* all copies or substantial portions of the Software.* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN* THE SOFTWARE.*************************************************************************/#ifndef COMMON_UTILS_HPP_
#define COMMON_UTILS_HPP_#include <string>
#include <map>
#include <functional>
#include <glog/logging.h>#include "buf_surface.h"#include "cuda_runtime.h"#include <nvcv/ImageFormat.h>namespace infer_server {// defer(xxx) like golang's defer
#define DEFER _DEFER_ACTION_MAKE /* ([&](){ ... }); */#define _DEFER_ACTION_MAKE auto \_DEFER_ACTION_VAR(_defer_action_line, __LINE__, _) = _DeferredActionCtor
#define _DEFER_ACTION_VAR(a, b, c) _DEFER_TOKEN_CONNECT(a, b, c)
#define _DEFER_TOKEN_CONNECT(a, b, c) a ## b ## cclass _DeferredAction {private:_DeferredAction(_DeferredAction const&) = delete;_DeferredAction& operator=(_DeferredAction const&) = delete;std::function<void()> func_;template<typename T>friend _DeferredAction _DeferredActionCtor(T&& p);template<typename T>_DeferredAction(T&& p) : func_(std::forward<T>(p)) {}public:_DeferredAction(_DeferredAction&& other) :func_(other.func_) {other.func_ = nullptr;}~_DeferredAction() {if (func_) { func_(); }}};template<typename T>_DeferredAction _DeferredActionCtor(T&& p) {return _DeferredAction(p);}
}/**
* @brief calculate aligned number
* @param [in]: num: the original number that to aligned
* @param [in]: align: the align factor
* @return the number after aligned
*/
#define ALIGN_UP(num, align) (((num) + (align) - 1) & ~((align) - 1))#define _SAFECALL(func, expected, msg, ret_val)                                                     \do {                                                                                              \int _ret = (func);                                                                              \if ((expected) != _ret) {                                                                       \LOG(ERROR) << "[InferServer] Call [" << #func << "] failed, ret = " << _ret << ". " << msg;        \return (ret_val);                                                                             \}                                                                                               \} while (0)#define CUDA_SAFECALL(func, msg, ret_val) _SAFECALL(func, cudaSuccess, msg, ret_val)#define _CALLFUNC(func, expected, msg)                                                     \do {                                                                                              \int _ret = (func);                                                                              \if ((expected) != _ret) {                                                                       \LOG(ERROR) << "[InferServer] Call [" << #func << "] failed, ret = " << _ret << ". " << msg;        \}                                                                                               \} while (0)#define CALL_CUDA_FUNC(func, msg) _CALLFUNC(func, cudaSuccess, msg)inline BufSurfaceMemType CastMemoryType(cudaMemoryType type) noexcept{switch (type) {case cudaMemoryTypeUnregistered:return BUF_MEMORY_UNREGISTERED;case cudaMemoryTypeHost:return BUF_MEMORY_HOST;case cudaMemoryTypeDevice:return BUF_MEMORY_DEVICE;case cudaMemoryTypeManaged:return BUF_MEMORY_MANAGED;default:LOG(ERROR) << "[InferServer] CastMemoryType(): Unsupported memory type";return BUF_MEMORY_HOST;}
}inline cudaMemoryType CastMemoryType(BufSurfaceMemType type) noexcept{switch (type) {case BUF_MEMORY_UNREGISTERED:return cudaMemoryTypeUnregistered;case BUF_MEMORY_HOST:return cudaMemoryTypeHost;case BUF_MEMORY_DEVICE:return cudaMemoryTypeDevice;case BUF_MEMORY_MANAGED:return cudaMemoryTypeManaged;default:LOG(ERROR) << "[InferServer] CastMemoryType(): Unsupported memory type";return cudaMemoryTypeHost;}
}inline BufSurfaceColorFormat CastColorFmt(NVCVImageFormat format) {static std::map<NVCVImageFormat, BufSurfaceColorFormat> color_map{{ NVCV_IMAGE_FORMAT_NV12, BUF_COLOR_FORMAT_NV12 },{ NVCV_IMAGE_FORMAT_NV21, BUF_COLOR_FORMAT_NV21 },{ NVCV_IMAGE_FORMAT_RGB8, BUF_COLOR_FORMAT_RGB },{ NVCV_IMAGE_FORMAT_BGR8, BUF_COLOR_FORMAT_BGR },};return color_map[format];
}inline NVCVImageFormat CastColorFmt(BufSurfaceColorFormat format) {static std::map<BufSurfaceColorFormat, NVCVImageFormat> color_map{{ BUF_COLOR_FORMAT_NV12, NVCV_IMAGE_FORMAT_NV12 },{ BUF_COLOR_FORMAT_NV21, NVCV_IMAGE_FORMAT_NV21 },{ BUF_COLOR_FORMAT_RGB, NVCV_IMAGE_FORMAT_RGB8 },{ BUF_COLOR_FORMAT_BGR, NVCV_IMAGE_FORMAT_BGR8 },};return color_map[format];
}#endif  // COMMON_UTILS_HPP_

1.4.4 error: no declaration matches ‘bool infer_server::DecodeFFmpeg::Create(VdecCreateParams*)’

这是因为声明和定义的地方,返回值不一致。修改源文件中函数定义,

#include <iostream>
#include "glog/logging.h"
#include "decode_impl_nv.hpp"
#include "transform.h"
#include "common/utils.hpp"namespace infer_server {int DecodeFFmpeg::Create(VdecCreateParams *params) {create_params_ = *params;switch (params->type) {case VDEC_TYPE_H264:av_codec_ = avcodec_find_decoder(AV_CODEC_ID_H264);break;case VDEC_TYPE_H265:av_codec_ = avcodec_find_decoder(AV_CODEC_ID_H265);break;case VDEC_TYPE_JPEG:default:LOG(ERROR) << "[InferServer] [DecodeFFmpeg] Create(): Unsupported codec type: " << create_params_.type;return -1;}if (!av_codec_) {LOG(ERROR) << "[InferServer] [DecodeFFmpeg] avcodec_find_decoder failed";return -1;}codec_context_ = avcodec_alloc_context3(av_codec_);if (!codec_context_) {LOG(ERROR) << "[InferServer] [DecodeFFmpeg] Failed to do avcodec_alloc_context3";return -1;}codec_context_->pix_fmt = AV_PIX_FMT_CUDA;AVDictionary *decoder_opts = nullptr;DEFER([&decoder_opts] {if (decoder_opts) av_dict_free(&decoder_opts);});av_dict_set_int(&decoder_opts, "device_id", 0, 0);if (avcodec_open2(codec_context_, av_codec_,  &decoder_opts) < 0) {LOG(ERROR) << "[InferServer] [DecodeFFmpeg] Failed to open codec";return -1;}av_frame_ = av_frame_alloc();if (!av_frame_) {LOG(ERROR) << "[InferServer] [DecodeFFmpeg] Could not alloc frame";return -1;} ResetFlags();if (transformer_ == nullptr) {TransformConfigParams config;config.compute_mode = TRANSFORM_COMPUTE_CVCUDA;config.device_id = create_params_.device_id;if (TransformCreate(&transformer_, &config) != 0) return -1;}created_ = true;return 0;}int DecodeFFmpeg::SendStream(const VdecStream *stream, int timeout_ms) {if (!created_) {LOG(ERROR) << "[InferServer] [DecodeFFmpeg] SendStream(): Decoder is not created";return -1;}if (nullptr == stream || nullptr == stream->bits) {if (eos_sent_) {LOG(WARNING) << "[InferServer] [DecodeFFmpeg] SendStream(): EOS packet has been send";return 0;}AVPacket framePacket = {};av_init_packet(&framePacket);framePacket.data = nullptr;framePacket.size = 0;avcodec_send_packet(codec_context_, &framePacket);// flush all frames ...int ret = 0;do {ret = avcodec_receive_frame(codec_context_, av_frame_);if(ret >= 0){OnFrame(av_frame_, stream->pts);}} while (ret >= 0);eos_sent_ = true;OnEos();}else{if (eos_sent_) {LOG(ERROR) << "[InferServer] [DecodeFFmpeg] SendStream(): EOS has been sent, process packet failed, pts:"<< stream->pts;return -1;}AVPacket framePacket = {};av_init_packet(&framePacket);framePacket.data = stream->bits;framePacket.size = stream->len;//开始解码int ret = avcodec_send_packet(codec_context_, &framePacket);if (ret < 0) {LOG(ERROR) << "[InferServer] [DecodeFFmpeg] avcodec_send_packet failed, data ptr, size:"<< framePacket.data << ", " << framePacket.size;return ret;}while (ret >= 0) {av_frame_unref(av_frame_);ret = avcodec_receive_frame(codec_context_, av_frame_);if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))return ret;else if (ret < 0) {continue;}OnFrame(av_frame_, stream->pts);}}return 0;}void DecodeFFmpeg::OnFrame(AVFrame *av_frame_, uint32_t frame_id) {BufSurface *surf = nullptr;if (create_params_.GetBufSurf(&surf, av_frame_->width, av_frame_->height, CastColorFmt(NVCV_IMAGE_FORMAT_BGR8),//这里得按照bgr去getbufsurf.create_params_.surf_timeout_ms, create_params_.userdata) < 0) {LOG(ERROR) << "[InferServer] [DecoderAcl] OnFrame(): Get BufSurface failed";OnError(-1);return;}if (surf->mem_type != BUF_MEMORY_MANAGED) {LOG(ERROR) << "[InferServer] [DecoderAcl] OnFrame(): BufSurface memory type must be BUF_MEMORY_MANAGED";return;}//switch (av_frame_->format) {//case AV_PIX_FMT_YUV420P://case AV_PIX_FMT_YVU420P://    //由于cvcuda不支持yuv的resize,所以先统一转成BGR,然后如果宽高不相等就resize,如果宽高相等就直接拷贝。//    BufSurface transform_src;//    BufSurfaceParams src_param;//    memset(&transform_src, 0, sizeof(BufSurface));//    memset(&src_param, 0, sizeof(BufSurfaceParams));//    src_param.color_format = CastColorFmt(av_frame_->format);//    //src_param.data_size = static_cast<uint32_t>(av_frame_->linesize);//    src_param.data_ptr = reinterpret_cast<void *>(av_frame_->data);//    VLOG(5) << "[InferServer] [DecoderAcl] OnFrame(): codec_frame: "//        << " width = " << av_frame_->width//        << ", height = " << av_frame_->height//        << ", width stride = " << av_frame_->linesize//        << ", height stride = " << av_frame_->height;//    VLOG(5) << "[InferServer] [DecoderAcl] OnFrame(): surf->surface_list[0]: "//        << " width = " << surf->surface_list[0].width//        << ", height = " << surf->surface_list[0].height//        << ", width stride = " << surf->surface_list[0].width_stride//        << ", height stride = " << surf->surface_list[0].height_stride;//    src_param.width = av_frame_->width;//    src_param.height = av_frame_->height;//    //src_param.width_stride = static_cast<uint32_t>(av_frame_->linesize);//    src_param.height_stride = av_frame_->height;//待修改。//    transform_src.batch_size = 1;//    transform_src.num_filled = 1;//    transform_src.device_id = create_params_.device_id;//    transform_src.mem_type = BUF_MEMORY_MANAGED;//    transform_src.surface_list = &src_param;//    BufSurface transform_temp;//    BufSurfaceParams temp_param;//    memset(&transform_temp, 0, sizeof(BufSurface));//    memset(&temp_param, 0, sizeof(BufSurfaceParams));//    temp_param.color_format = CastColorFmt(NVCV_IMAGE_FORMAT_BGR8);//    temp_param.data_size = av_frame_->linesize[0]*av_frame_->height*3;//   // std::unique_ptr<char[]> temp_param_data(new char[temp_param.data_size]);//   // temp_param.data_ptr = temp_param_data.get();//    VLOG(5) << "[InferServer] [DecoderAcl] OnFrame(): codec_frame: "//        << " width = " << av_frame_->width//        << ", height = " << av_frame_->height//        << ", width stride = " << av_frame_->linesize//        << ", height stride = " << av_frame_->height;//    VLOG(5) << "[InferServer] [DecoderAcl] OnFrame(): surf->surface_list[0]: "//        << " width = " << surf->surface_list[0].width//        << ", height = " << surf->surface_list[0].height//        << ", width stride = " << surf->surface_list[0].width_stride//        << ", height stride = " << surf->surface_list[0].height_stride;//    temp_param.width = av_frame_->width;//    temp_param.height = av_frame_->height;//    temp_param.width_stride = av_frame_->linesize[0];//    temp_param.height_stride = av_frame_->height;//待修改。//    transform_temp.batch_size = 1;//    transform_temp.num_filled = 1;//    transform_temp.device_id = create_params_.device_id;//    transform_temp.mem_type = BUF_MEMORY_MANAGED;//    transform_temp.surface_list = &temp_param;//    TransformParams trans_params;//    memset(&trans_params, 0, sizeof(trans_params));//    trans_params.transform_flag = TRANSFORM_CONVERT_FORMAT;//TRANSFORM_RESIZE_SRC;//    //YUV-BGR//    if (Transform(transformer_, &transform_src, &transform_temp, &trans_params) < 0) {//        LOG(ERROR) << "[InferServer] [height] OnFrame(): Transfrom failed";//        break;//    }//    //resize//    if (surf->surface_list[0].width != av_frame_->width || surf->surface_list[0].height != av_frame_->height) {//        surf->surface_list[0].data_size = surf->surface_list[0].width * surf->surface_list[0].height * 3;//        if (Transform(transformer_, &transform_temp, surf, &trans_params) < 0) {//            LOG(ERROR) << "[InferServer] [height] OnFrame(): Transfrom failed";//            break;//        }//    }//    else {//        //std::chrono::high_resolution_clock::time_point tnow = std::chrono::high_resolution_clock::now();//      //  CALL_ACL_FUNC(MemcpyHD(surf->surface_list[0].data_ptr, codec_image->size, codec_image->data.get(), codec_image->size, codec_image->deviceId)//     //      , "[height] OnFrame(): copy codec buffer data to surf failed");//                     //       // std::chrono::high_resolution_clock::time_point tpost = std::chrono::high_resolution_clock::now();//        //std::cout << "<<<<<<================================ CopyDataToHostEx time = " << std::chrono::duration_cast<std::chrono::duration<double>>(tpost - tnow).count() * 1000 << " ms" << std::endl;//    }//    break;//default://    break;//}surf->pts = frame_id;//std::chrono::high_resolution_clock::time_point tnow = std::chrono::high_resolution_clock::now();create_params_.OnFrame(surf, create_params_.userdata);//std::chrono::high_resolution_clock::time_point tpost = std::chrono::high_resolution_clock::now();//std::cout << "<<<<<<================================ create_params_.OnFrame time = " << std::chrono::duration_cast<std::chrono::duration<double>>(tpost - tnow).count() * 1000 << " ms" << std::endl;}int DecodeFFmpeg::Destroy() {if (!created_) {LOG(WARNING) << "[InferServer] [DecoderAcl] Destroy(): Decoder is not created";return 0;}// if error happened, destroy directly, eos maybe not be transmitted from the decoderif (!eos_sent_) {SendStream(nullptr, 10000);}ResetFlags();if (av_frame_) {av_frame_free(&av_frame_);av_frame_ = nullptr;}if (codec_context_) {avcodec_close(codec_context_);avcodec_free_context(&codec_context_);codec_context_ = nullptr;}if (transformer_ != nullptr) {TransformDestroy(transformer_);}return 0;}void DecodeFFmpeg::ResetFlags() {eos_sent_ = false;created_ = false;}void DecodeFFmpeg::OnEos() {create_params_.OnEos(create_params_.userdata);}void DecodeFFmpeg::OnError(int errcode) {//convert the error codecreate_params_.OnError(static_cast<int>(errcode), create_params_.userdata);}}  // namespace 

1.4.5 error: ‘TRANSFORM_COMPUTE_CVCUDA’ was not declared in this scope; did you mean ‘TRANSFORM_COMPUTE_NVCUDA’?

写错了,修改一下定义

typedef enum {/** Specifies VPP as a compute device for Ascendxxxx. */TRANSFORM_COMPUTE_DEFAULT,/** Specifies that the acl is the compute device. */TRANSFORM_COMPUTE_CVCUDA,/** Specifies the number of compute modes. */TRANSFORM_COMPUTE_NUM
} TransformComputeMode;

1.4.6 error: ‘shared_ptr’ in namespace ‘std’ does not name a template type

这是因为定义错了,新版本的叫Tensor,没有I

修改整个infer_server/src/nv/transform_impl_nv.hpp


#ifndef TRANSFORM_IMPL_NV_HPP_
#define TRANSFORM_IMPL_NV_HPP_#include <algorithm>
#include <cstring> 
#include <atomic>
#include <memory>#include "../transform_impl.hpp"
#include "transform.h"
#include "common/utils.hpp"#include <nvcv/Tensor.hpp>#include <cvcuda/OpCvtColor.hpp>
#include <cvcuda/OpResize.hpp>
#include <cvcuda/OpCustomCrop.hpp>
#include <cvcuda/OpCopyMakeBorder.hpp>namespace infer_server {class TransformerNV : public ITransformer {public:TransformerNV() {}~TransformerNV() = default;int Create(TransformConfigParams *params) override;int Destroy() override;int Transform(BufSurface *src, BufSurface *dst, TransformParams *transform_params) override;private:int DoNVTransform(BufSurface *src, BufSurface *dst, TransformParams *transform_params);int NVResize(BufSurface *src, BufSurface *dst, TransformParams *transform_params);int NVCrop(BufSurface *src, BufSurface *dst, TransformParams *transform_params);int NVCropResize(BufSurface *src, BufSurface *dst, TransformParams *transform_params);int NVCropResizePaste(BufSurface *src, BufSurface *dst, TransformParams *transform_params);int NVConvertFormat(BufSurface *src, BufSurface *dst, TransformParams *transform_params);private:TransformConfigParams create_params_;void* cu_stream_{nullptr};std::shared_ptr<nvcv::Tensor> crop_tensor_;std::shared_ptr<nvcv::Tensor> resized_tensor_;std::shared_ptr<nvcv::Tensor> cvtcolor_tensor_;std::shared_ptr<nvcv::Tensor> copymakeborder_tensor_;std::shared_ptr<cvcuda::CustomCrop> crop_op_;    std::shared_ptr<cvcuda::Resize> resize_op_;std::shared_ptr<cvcuda::CvtColor> cvtcolor_op_;std::shared_ptr<cvcuda::CopyMakeBorder> copymakeborder_op_;std::atomic<bool> created_{};};}  // namespace #endif  // TRANSFORM_IMPL_MLU370_HPP_

1.4.7 error: ‘cuCreateStream’ was not declared in this scope

增加头文件 #include "cuda_utils_sdk.h"

1.4.8 error: ‘BUF_MEMORY_DVPP’ was not declared in this scope; did you mean ‘BUF_MEMORY_HOST’?

if (src->mem_type != BUF_MEMORY_MANAGED)

修改为

 if (src->mem_type != BUF_MEMORY_MANAGED) {

2 整体工程cmake

2.1By not providing "FindLibAclLite.cmake" in CMAKE_MODULE_PATH this projec

CMake Warning at framework/CMakeLists.txt:22 (find_package):By not providing "FindLibAclLite.cmake" in CMAKE_MODULE_PATH this projecthas asked CMake to find a package configuration file provided by"LibAclLite", but CMake did not find one.

直接删掉

不写笔记了,中间又修改了很多个CMakeLists.txt

3 编译framework

framework是框架的东西,这个几乎没修改代码,编译没报错。 

root@ubuntu:/data/chw/nvstream/build/framework# ll
total 44
drwxrwxrwx 3 root root  4096 9月   5 20:34 ./
drwxrwxrwx 7 root root  4096 9月   5 20:34 ../
drwxrwxrwx 3 root root  4096 9月   5 20:34 CMakeFiles/
-rw-rw-rw- 1 root root  1273 9月   5 20:34 cmake_install.cmake
-rw-rw-rw- 1 root root 28336 9月   5 20:34 Makefile
root@ubuntu:/data/chw/nvstream/build/framework# make -j8
[ 13%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_collection.cpp.o
[ 26%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_graph.cpp.o
[ 26%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_frame.cpp.o
[ 13%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_config.cpp.o
[ 20%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_eventbus.cpp.o
[ 33%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_module.cpp.o
[ 40%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_source.cpp.o
[ 46%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_pipeline.cpp.o
[ 46%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/cnstream_version.cpp.o
[ 53%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/connector.cpp.o
[ 60%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/conveyor.cpp.o
[ 66%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/profiler/module_profiler.cpp.o
[ 73%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/profiler/pipeline_profiler.cpp.o
[ 73%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/profiler/pipeline_tracer.cpp.o
[ 80%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/profiler/process_profiler.cpp.o
[ 86%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/profiler/stream_profiler.cpp.o
[ 93%] Building CXX object framework/CMakeFiles/tnvstream_core.dir/src/profiler/trace_serialize_helper.cpp.o
[100%] Linking CXX shared library /data/chw/nvstream/lib/libtnvstream_core.so
[100%] Built target tnvstream_core

4 编译modules

4.1 atal error: cuda_runtime.h: No such file or directory

In file included from /data/chw/nvstream/modules/../infer_server/include/buf_surface_util.hpp:30,from /data/chw/nvstream/modules/../infer_server/include/nvis/processor.h:29,from /data/chw/nvstream/modules/cnstream_preproc.hpp:37,from /data/chw/nvstream/modules/cnstream_preproc.cpp:21:
/data/chw/nvstream/modules/../infer_server/include/common/utils.hpp:31:10: fatal error: cuda_runtime.h: No such file or directory31 | #include "cuda_runtime.h"

修改modules/CMakeLists.txt

里面增加

# ---[ Compute
find_package(LibCompute)
if(NOT LibCompute_FOUND)message(FATAL_ERROR "LibCompute not found!")
endif()include_directories(${LibCompute_INCLUDE_DIRS})

5 编译app

首先也还是cuda_runtime找不到的问题,修改cmake就可以了

5.1 error: ‘BUF_MEMORY_NORMAL’ was not declared in this scope; did you mean ‘BUF_MEMORY_HOST’?

/data/chw/nvstream/app/preprocess/preprocess_common.cpp: In function ‘void SaveResult(const string&, int, uint32_t, infer_server::BufSurfWrapperPtr, const PreprocNetworkInfo&)’:
/data/chw/nvstream/app/preprocess/preprocess_common.cpp:109:52: error: ‘BUF_MEMORY_NORMAL’ was not declared in this scope; did you mean ‘BUF_MEMORY_HOST’?109 |         if (infer_server::MemcpyHD(cpu_data.get(), BUF_MEMORY_NORMAL, dev_addr, dst_buf->GetMemType(), data_size) != 0) {|                                                    ^~~~~~~~~~~~~~~~~|                                                    BUF_MEMORY_HOST

这个直接修改代码

5.2 warning: libavformat.so.59, needed by /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so, not found (try using -rpath or -rpath-link)

      |                     ^~~~~~~~~
[100%] Linking CXX executable /data/chw/nvstream/app/bin/app
/usr/bin/ld: warning: libavformat.so.59, needed by /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libavcodec.so.59, needed by /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libswscale.so.6, needed by /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libavutil.so.57, needed by /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_receive_packet@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `sws_getCachedContext@LIBSWSCALE_6'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_dict_free(AVDictionary**)'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_codec_iterate@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_parameters_copy@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_write_frame@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avio_close@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_frame_alloc@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_bsf_free@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `sws_freeContext@LIBSWSCALE_6'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_write_trailer@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_bsf_alloc@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_find_encoder@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_free@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avformat_get_riff_video_tags@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_send_packet@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_get_name@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_hwframe_transfer_data@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_packet_free@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_malloc@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avformat_network_init@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_hwframe_ctx_alloc@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_init_packet(AVPacket*)'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_hwframe_ctx_init@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_freep@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_opt_set@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_log_get_level@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_hwdevice_get_type_name@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_bsf_send_packet@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_read_frame@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_mallocz@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avformat_new_stream@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_bsf_init@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avformat_close_input@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_hwframe_ctx_create_derived@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_receive_frame(AVCodecContext*, AVFrame*)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_close(AVCodecContext*)'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_hwframe_constraints_free@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_dict_free@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_guess_format@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_packet_unref@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_log_set_callback@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_guess_sample_aspect_ratio@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_frame_unref@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_send_frame@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_sub_q@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_pix_fmt_to_codec_tag@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_codec_get_id@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_dict_get@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_buffer_unref@LIBAVUTIL_57'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avformat_find_stream_info@LIBAVFORMAT_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_find_decoder@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `sws_scale@LIBSWSCALE_6'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `avcodec_free_context@LIBAVCODEC_59'
/usr/bin/ld: /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/libopencv_videoio.so: undefined reference to `av_hwdevice_ctx_create_derived@LIBAVUTIL_57'

这是因为我编译的jetson-ffmpeg里面ffmpeg库的版本和opencv所需要的ffmpeg库版本有差异造成的,下面图中红框的是opencv需要的,但是我的jetson-ffmpeg比他低一个版本

然后我发现系统根目录的opencv是4.5,然后他用的ffmpeg版本低一个,所以直接用系统根目录下的

cp -drf /usr/include/opencv4/opencv2 /data/chw/nvstream/3rdparty/opencv/include/
cd /usr/lib/aarch64-linux-gnu/
mkdir -p  /data/chw/nvstream/3rdparty/opencv/lib/linux_lib
cp -drf libopencv* /data/chw/nvstream/3rdparty/opencv/lib/linux_lib/

然后config脚本里面也修改一下

cd ${root}/opencv/lib/linux_lib
\cp ../${arch}/* .ln -snf libopencv_core.so.4.5.4 libopencv_core.so.4.5
ln -snf libopencv_core.so.4.5 libopencv_core.soln -snf libopencv_highgui.so.4.5.4 libopencv_highgui.so.4.5
ln -snf libopencv_highgui.so.4.5 libopencv_highgui.soln -snf libopencv_imgproc.so.4.5.4 libopencv_imgproc.so.4.5
ln -snf libopencv_imgproc.so.4.5 libopencv_imgproc.soln -snf libopencv_imgcodecs.so.4.5.4 libopencv_imgcodecs.so.4.5
ln -snf libopencv_imgcodecs.so.4.5 libopencv_imgcodecs.soln -snf libopencv_video.so.4.5.4 libopencv_video.so.4.5
ln -snf libopencv_video.so.4.5 libopencv_video.soln -snf libopencv_videoio.so.4.5.4 libopencv_videoio.so.4.5
ln -snf libopencv_videoio.so.4.5 libopencv_videoio.soln -snf libopencv_features2d.so.4.5.4 libopencv_features2d.so.4.5
ln -snf libopencv_features2d.so.4.5 libopencv_features2d.soln -snf libopencv_flann.so.4.5.4 libopencv_flann.so.4.5
ln -snf libopencv_flann.so.4.5 libopencv_flann.soln -snf libopencv_calib3d.so.4.5.4 libopencv_calib3d.so.4.5
ln -snf libopencv_calib3d.so.4.5 libopencv_calib3d.soln -snf libopencv_dnn.so.4.5.4 libopencv_dnn.so.4.5
ln -snf libopencv_dnn.so.4.5 libopencv_dnn.so

5.3 undefined reference to `av_dict_free(AVDictionary**)'

/usr/bin/ld: warning: libopencv_core.so.406, needed by /data/chw/nvstream/app/../biz_sdk/lib/linux_lib/libbiz_sdk.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_dict_free(AVDictionary**)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_init_packet(AVPacket*)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_receive_frame(AVCodecContext*, AVFrame*)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_close(AVCodecContext*)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_send_packet(AVCodecContext*, AVPacket const*)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_alloc_context3(AVCodec const*)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_find_decoder(AVCodecID)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_dict_set_int(AVDictionary**, char const*, long, int)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `avcodec_free_context(AVCodecContext**)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_frame_unref(AVFrame*)'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `av_frame_alloc()'
/usr/bin/ld: /data/chw/nvstream/3rdparty/freetype/lib/linux_lib/libfreetype.so.6: undefined reference to `fstat@GLIBC_2.33'
/usr/bin/ld: /data/chw/nvstream/lib/libnvis.so.1.0.0: undefined reference to `infer_server::AllocHostMem(unsigned long)'
collect2: error: ld returned 1 exit status

这是因为我编译libnvis.so的时候,没有加ffmepg,我在infer_server/CMakeLists.txt中增加

# ---[ ffmpeg
find_package(FFmpeg REQUIRED)
if (FFMPEG_FOUND)include_directories(${FFMPEG_INCLUDE_DIRS})list(APPEND 3RDPARTY_LIBS ${FFMPEG_LIBRARIES})message(STATUS "FFmpeg include: ${FFMPEG_INCLUDE_DIRS}")message(STATUS "FFmpeg libraries: ${FFMPEG_LIBRARIES}")
else ()message(FATAL_ERROR "FFmpeg not found!")
endif ().....其他内容......target_include_directories(nvis PRIVATE${LibCompute_INCLUDE_DIRS}${LibCVCuda_INCLUDE_DIRS}${CMAKE_CURRENT_SOURCE_DIR}/include${CMAKE_CURRENT_SOURCE_DIR}/src${GLOG_INCLUDE_DIRS}${GFLAGS_INCLUDE_DIRS}${FFMPEG_INCLUDE_DIRS}  # 添加FFmpeg头文件路径)target_link_libraries(nvis PRIVATE ${LibCompute_LIBRARIES} ${LibCVCuda_LIBRARIES} ${GLOG_LIBRARIES} ${FFMPEG_LIBRARIES})

再次编译我看到

-- FFmpeg include: /usr/local/include
-- FFmpeg libraries: /usr/local/lib/libavcodec.so;/usr/local/lib/libavformat.so;/usr/local/lib/libavutil.so;/usr/local/lib/libswscale.so;/usr/local/lib/libswresample.so
-- @@@@@@@@@@@ Target : nvis

不对,我不是想让他找系统路径下的,我要让他找我自己的工程路径下的,我看了下cmake/FindFFmpeg.cmake的内容,这个写的有问题

# ==============================================
# Try to find FFmpeg libraries:
# - avcodec
# - avformat
# - avdevice
# - avutil
# - swscale
# - avfilter
#
# FFMPEG_FOUND - system has FFmpeg
# FFMPEG_INCLUDE_DIRS - the FFmpeg inc directory
# FFMPEG_LIBRARIES - Link these to use FFmpeg
# ==============================================
# Notice: this original script is from internet.if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)# in cache alreadyset(FFMPEG_FOUND TRUE)
else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)find_path(FFMPEG_AVCODEC_INCLUDE_DIRNAMES libavcodec/avcodec.hPATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS}/usr/include/ffmpeg/usr/local/include/usr/include/x86_64-linux-gnu ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/include)find_library(FFMPEG_LIBAVCODECNAMES avcodecPATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS}/usr/lib64/usr/local/lib/usr/lib/x86_64-linux-gnu${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib)find_library(FFMPEG_LIBAVFORMATNAMES avformatPATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS}/usr/lib64/usr/local/lib/usr/lib/x86_64-linux-gnu${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib)find_library(FFMPEG_LIBSWRESAMPLENAMES swresamplePATHS ${_FFMPEG_SWRESAMPLE_LIBRARY_DIRS}/usr/lib64/usr/local/lib/usr/lib/x86_64-linux-gnu${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib)find_library(FFMPEG_LIBAVUTILNAMES avutilPATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS}/usr/lib64/usr/local/lib/usr/lib/x86_64-linux-gnu${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib)find_library(FFMPEG_LIBSWSCALENAMES swscalePATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS}/usr/lib64/usr/local/lib/usr/lib/x86_64-linux-gnu${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib)find_library(FFMPEG_LIBAVFILTERNAMES avfilterPATHS ${_FFMPEG_AVFILTER_LIBRARY_DIRS}/usr/lib64/usr/local/lib/usr/lib/x86_64-linux-gnu${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib)find_library(FFMPEG_LIBAVDEVICENAMES avdevicePATHS ${_FFMPEG_AVDEVICE_LIBRARY_DIRS}/usr/lib64/usr/local/lib/usr/lib/x86_64-linux-gnu${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib)if (WITH_FFMPEG_AVDEVICE AND NOT FFMPEG_LIBAVDEVICE)message(FATAL_ERROR "Not find FFmpeg LIBAVDEVICE ")endif ()if (FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE AND FFMPEG_LIBSWRESAMPLE AND (FFMPEG_LIBAVDEVICE OR NOT WITH_FFMPEG_AVDEVICE))set(FFMPEG_FOUND TRUE)endif ()if (FFMPEG_FOUND)set(FFMPEG_INCLUDE_DIRS ${FFMPEG_AVCODEC_INCLUDE_DIR})set(FFMPEG_LIBRARIES${FFMPEG_LIBAVCODEC}${FFMPEG_LIBAVFORMAT}${FFMPEG_LIBAVUTIL}${FFMPEG_LIBSWSCALE}${FFMPEG_LIBSWRESAMPLE})if (WITH_FFMPEG_AVDEVICE)list(APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBAVDEVICE})endif (WITH_FFMPEG_AVDEVICE)else (FFMPEG_FOUND)message(FATAL_ERROR "Could not find FFmpeg libraries!")endif (FFMPEG_FOUND)endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)

这里面直接就是系统路径下的,那不对,我要让他找我自己路径下的,于是修改它

# ==============================================
# Try to find FFmpeg libraries:
# - avcodec
# - avformat
# - avdevice
# - avutil
# - swscale
# - avfilter
#
# FFMPEG_FOUND - system has FFmpeg
# FFMPEG_INCLUDE_DIRS - the FFmpeg inc directory
# FFMPEG_LIBRARIES - Link these to use FFmpeg
# ==============================================
# Notice: this original script is from internet.if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)# in cache alreadyset(FFMPEG_FOUND TRUE)
else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)find_path(LibFFMPEG_ROOT_DIRNAMES include/libavcodec/avcodec.hPATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpegNO_DEFAULT_PATH)	find_path(LibFFMEPG_INCLUDE_DIRNAMES libavcodec/avcodec.hPATHS ${LibFFMPEG_ROOT_DIR}/includeNO_DEFAULT_PATH)find_library(FFMPEG_LIBAVCODECNAMES avcodecPATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_libNO_DEFAULT_PATH)find_library(FFMPEG_LIBAVFORMATNAMES avformatPATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_libNO_DEFAULT_PATH)find_library(FFMPEG_LIBSWRESAMPLENAMES swresamplePATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_libNO_DEFAULT_PATH)find_library(FFMPEG_LIBAVUTILNAMES avutilPATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_libNO_DEFAULT_PATH)find_library(FFMPEG_LIBSWSCALENAMES swscalePATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_libNO_DEFAULT_PATH)find_library(FFMPEG_LIBAVFILTERNAMES avfilterPATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_libNO_DEFAULT_PATH)find_library(FFMPEG_LIBAVDEVICENAMES avdevicePATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_libNO_DEFAULT_PATH)if (WITH_FFMPEG_AVDEVICE AND NOT FFMPEG_LIBAVDEVICE)message(FATAL_ERROR "Not find FFmpeg LIBAVDEVICE ")endif ()if (FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT AND FFMPEG_LIBAVUTIL AND FFMPEG_LIBSWSCALE AND FFMPEG_LIBSWRESAMPLE AND (FFMPEG_LIBAVDEVICE OR NOT WITH_FFMPEG_AVDEVICE))set(FFMPEG_FOUND TRUE)endif ()if (FFMPEG_FOUND)set(FFMPEG_INCLUDE_DIRS ${LibFFMEPG_INCLUDE_DIR})set(FFMPEG_LIBRARIES${FFMPEG_LIBAVCODEC}${FFMPEG_LIBAVFORMAT}${FFMPEG_LIBAVUTIL}${FFMPEG_LIBSWSCALE}${FFMPEG_LIBSWRESAMPLE})if (WITH_FFMPEG_AVDEVICE)list(APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBAVDEVICE})endif (WITH_FFMPEG_AVDEVICE)else (FFMPEG_FOUND)message(FATAL_ERROR "Could not find FFmpeg libraries!")endif (FFMPEG_FOUND)endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)

这里面最开始还有下面的

-- FFmpeg include: LibFFMEPG_INCLUDE_DIR-NOTFOUND
-- FFmpeg libraries: /data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavcodec.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavformat.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavutil.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libswscale.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libswresample.so
-- @@@@@@@@@@@ Target : nvis
-- Configuring done (1.2s)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LibFFMEPG_INCLUDE_DIRused as include directory in directory /data/chw/nvstream/infer_serverused as include directory in directory /data/chw/nvstream/infer_serverused as include directory in directory /data/chw/nvstream/infer_serverCMake Error in CMakeLists.txt:Found relative path while evaluating include directories of "nvis":"LibFFMEPG_INCLUDE_DIR-NOTFOUND"

这是因为cmake/FindFFmpeg.cmake里面NAMES include/libavcodec/avcodec.h写成了NAMES inculde/libavcodec/avcodec.h

我这样修改之后再次编译,然后发现

cmake -DCMAKE_BUILD_TYPE=Debug ..
-- FFmpeg include: /data/chw/nvstream/3rdparty/ffmpeg/include
-- FFmpeg libraries: /data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavcodec.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavformat.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavutil.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libswscale.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libswresample.so
-- @@@@@@@@@@@ Target : nvis
-- FFmpeg libraries: /data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavcodec.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavformat.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libavutil.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libswscale.so;/data/chw/nvstream/3rdparty/ffmpeg/lib/linux_lib/libswresample.so
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /data/chw/nvstream/infer_server/build

已经能找到我自己路径下的库了,可是我编译完之后

ldd  /data/chw/nvstream/lib/libnvis.so.1.0.0 linux-vdso.so.1 (0x0000ffff99206000)libcudart.so.11.0 => /data/chw/nvstream/3rdparty/jetson/compute/lib/linux_lib/libcudart.so.11.0 (0x0000ffff98ef4000)libtrteng_exp.so => /data/chw/nvstream/3rdparty/jetson/compute/lib/linux_lib/libtrteng_exp.so (0x0000ffff98c35000)libcuda_utils.so => /data/chw/nvstream/3rdparty/jetson/compute/lib/linux_lib/libcuda_utils.so (0x0000ffff98b7f000)libcvcuda.so.0 => /opt/nvidia/cvcuda0/lib/aarch64-linux-gnu/libcvcuda.so.0 (0x0000ffff91e07000)libnvcv_types.so.0 => /opt/nvidia/cvcuda0/lib/aarch64-linux-gnu/libnvcv_types.so.0 (0x0000ffff91c61000)libglog.so.0 => /data/chw/nvstream/3rdparty/glog/lib/linux_lib/libglog.so.0 (0x0000ffff91c21000)libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000ffff919ba000)libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000ffff91991000)libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff9181e000)/lib/ld-linux-aarch64.so.1 (0x0000ffff991d6000)libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffff9180a000)libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffff917d9000)librt.so.1 => /lib/aarch64-linux-gnu/librt.so.1 (0x0000ffff917c1000)libnvinfer.so.8 => /lib/aarch64-linux-gnu/libnvinfer.so.8 (0x0000ffff84668000)libnvinfer_plugin.so.8 => /lib/aarch64-linux-gnu/libnvinfer_plugin.so.8 (0x0000ffff83245000)libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffff8319a000)libcusolver.so.11 => /usr/local/cuda/targets/aarch64-linux/lib/libcusolver.so.11 (0x0000ffff7603c000)libnvdla_compiler.so => /usr/lib/aarch64-linux-gnu/tegra/libnvdla_compiler.so (0x0000ffff75901000)libcudla.so.1 => /usr/local/cuda/targets/aarch64-linux/lib/libcudla.so.1 (0x0000ffff758c4000)libcublas.so.11 => /usr/local/cuda/targets/aarch64-linux/lib/libcublas.so.11 (0x0000ffff6b7eb000)libcublasLt.so.11 => /usr/local/cuda/targets/aarch64-linux/lib/libcublasLt.so.11 (0x0000ffff5424a000)libcudnn.so.8 => /lib/aarch64-linux-gnu/libcudnn.so.8 (0x0000ffff54213000)libnvos.so => /usr/lib/aarch64-linux-gnu/tegra/libnvos.so (0x0000ffff541f3000)libnvdla_runtime.so => /usr/lib/aarch64-linux-gnu/tegra/libnvdla_runtime.so (0x0000ffff53b9b000)libcuda.so.1 => /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1 (0x0000ffff52544000)libnvrm_host1x.so => /usr/lib/aarch64-linux-gnu/tegra/libnvrm_host1x.so (0x0000ffff52523000)libnvrm_mem.so => /usr/lib/aarch64-linux-gnu/tegra/libnvrm_mem.so (0x0000ffff5250b000)libnvsocsys.so => /usr/lib/aarch64-linux-gnu/tegra/libnvsocsys.so (0x0000ffff524f7000)libnvrm_gpu.so => /usr/lib/aarch64-linux-gnu/tegra/libnvrm_gpu.so (0x0000ffff5248a000)libnvrm_sync.so => /usr/lib/aarch64-linux-gnu/tegra/libnvrm_sync.so (0x0000ffff52473000)libnvrm_chip.so => /usr/lib/aarch64-linux-gnu/tegra/libnvrm_chip.so (0x0000ffff5245f000)libnvsciipc.so => /usr/lib/aarch64-linux-gnu/tegra/libnvsciipc.so (0x0000ffff5243a000)

根本就没有ffmepg的库呀。原因在于我的代码中,包含头文件的时候,没有加extern C,改成下面这样的

#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#ifdef __cplusplus
}
#endif

然后再次编译出来的库就会依赖FFmpeg了。

5.4 /data/chw/nvstream/3rdparty/freetype/lib/linux_lib/libfreetype.so.6: undefined reference to `fstat@GLIBC_2.33'

这种错误很明显就是版本问题了,我现在的工程目录下的文件是6.18的

/data/chw/nvstream/3rdparty/freetype/lib/aarch64/libfreetype.so.6.18.1
/data/chw/nvstream/3rdparty/freetype/lib/aarch64/libfreetype.so.6.14.0_backup
/data/chw/nvstream/3rdparty/freetype/lib/linux_lib/libfreetype.so.6
/data/chw/nvstream/3rdparty/freetype/lib/linux_lib/libfreetype.so.6.18.1
/data/chw/nvstream/3rdparty/freetype/lib/linux_lib/libfreetype.so.6.14.0

但是系统目录下的是6.17的

/usr/lib/aarch64-linux-gnu/libfreetype.so.6
/usr/lib/aarch64-linux-gnu/libfreetype.so.6.17.1

所以把系统路径的拷贝过来,

cp  /usr/lib/aarch64-linux-gnu/libfreetype.so.6.17.1 /data/chw/nvstream/3rdparty/freetype/lib/aarch64/

并且修改config脚本的内容

ln -snf libfreetype.so.6.17.1 libfreetype.so.6
ln -snf libfreetype.so.6 libfreetype.so

参考文献:

在NVIDIA Jetson AGX Orin中使用jetson-ffmpeg调用硬件编解码加速处理-CSDN博客

NVIDIA Jetson AGX Orin源码编译安装CV-CUDA-CSDN博客

GitHub - Cambricon/CNStream: CNStream is a streaming framework for building Cambricon machine learning pipelines http://forum.cambricon.com https://gitee.com/SolutionSDK/CNStream

easydk/samples/simple_demo/common/video_decoder.cpp at master · Cambricon/easydk · GitHub

aclStream流处理多路并发Pipeline框架中 视频解码 代码调用流程整理、类的层次关系整理、回调函数赋值和调用流程整理-CSDN博客

aclStream流处理多路并发Pipeline框架中VEncode Module代码调用流程整理、类的层次关系整理、回调函数赋值和调用流程整理-CSDN博客

FFmpeg/doc/examples at master · FFmpeg/FFmpeg · GitHub

GitHub - CVCUDA/CV-CUDA: CV-CUDA™ is an open-source, GPU accelerated library for cloud-scale image processing and computer vision.

如何使用FFmpeg的解码器—FFmpeg API教程 · FFmpeg原理

C++ API — CV-CUDA Beta documentation (cvcuda.github.io)

CV-CUDA/tests/cvcuda/system at main · CVCUDA/CV-CUDA · GitHub

Resize — CV-CUDA Beta documentation

CUDA Runtime API :: CUDA Toolkit Documentation

CUDA Toolkit Documentation 12.6 Update 1

完整指南:CNStream流处理多路并发框架适配到NVIDIA Jetson Orin (一) 依赖库编译、第三方库编译安装-CSDN博客

完整指南:CNStream流处理多路并发框架适配到NVIDIA Jetson Orin (二) 源码架构流程梳理、代码编写-CSDN博客

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Oracle VM VirtualBox 下 Ubuntu22 虚拟机配置双网络
  • Ubuntu20.04+ros-noetic配置Cartographer
  • sqli-lab靶场学习(一)——Less1-4
  • Java小程序案例:电子日历记事本
  • Win11下面的StartAllBack的安装、使用流程
  • 传统CV算法——特征匹配算法
  • 瑜伽馆预约系统小程序搭建,全民健身下的市场机遇
  • VMware命令
  • 缓存类型以及读写策略
  • SSH远程连接服务
  • 关于Netty详细介绍,Netty原理架构解析
  • 【word导出带图片】使用docxtemplater导出word,通知书形式的word
  • LoRA微调模型结构可训参数和配置详解
  • SpringBoot 拦截请求打印日志
  • 读书笔记--阅读费孝通先生一生学术历程的记录与感悟
  • hexo+github搭建个人博客
  • 「面试题」如何实现一个圣杯布局?
  • 【跃迁之路】【699天】程序员高效学习方法论探索系列(实验阶段456-2019.1.19)...
  • flutter的key在widget list的作用以及必要性
  • JavaScript工作原理(五):深入了解WebSockets,HTTP/2和SSE,以及如何选择
  • Laravel核心解读--Facades
  • LeetCode算法系列_0891_子序列宽度之和
  • React-flux杂记
  • windows下使用nginx调试简介
  • 百度地图API标注+时间轴组件
  • 批量截取pdf文件
  • 使用 @font-face
  • 系统认识JavaScript正则表达式
  • 项目实战-Api的解决方案
  • 学习JavaScript数据结构与算法 — 树
  • 异常机制详解
  • zabbix3.2监控linux磁盘IO
  • 好程序员web前端教程分享CSS不同元素margin的计算 ...
  • ​十个常见的 Python 脚本 (详细介绍 + 代码举例)
  • #Spring-boot高级
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • #在线报价接单​再坚持一下 明天是真的周六.出现货 实单来谈
  • (1)(1.19) TeraRanger One/EVO测距仪
  • (12)目标检测_SSD基于pytorch搭建代码
  • (4)(4.6) Triducer
  • (C语言)fread与fwrite详解
  • (Redis使用系列) SpringBoot 中对应2.0.x版本的Redis配置 一
  • (编译到47%失败)to be deleted
  • (回溯) LeetCode 131. 分割回文串
  • (七)c52学习之旅-中断
  • (转)h264中avc和flv数据的解析
  • . Flume面试题
  • .net core 6 集成和使用 mongodb
  • .NET Core中的去虚
  • .NET Framework 3.5安装教程
  • .net php 通信,flash与asp/php/asp.net通信的方法
  • .Net 垃圾回收机制原理(二)
  • .NET学习教程二——.net基础定义+VS常用设置
  • /tmp目录下出现system-private文件夹解决方法
  • @RestControllerAdvice异常统一处理类失效原因