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

news2024/11/15 14:05:38

目录

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 Flags

option(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 headers

find_path(LibCompute_ROOT_DIR
    NAMES include/export_funtions.h
    PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/jetson/compute
)

find_path(LibCompute_INCLUDE_DIRS
    NAMES export_funtions.h
    PATHS ${LibCompute_ROOT_DIR}/include
)

find_path(LibCompute_CUDA_INCLUDE_DIRS
    NAMES cuda_runtime.h
    PATHS ${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_lib
    NO_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 headers

find_path(LibCVCuda_ROOT_DIR
    NAMES include/cvcuda/Version.h
    PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/jetson/cvcuda
)

find_path(LibCVCuda_INCLUDE_DIRS
    NAMES cvcuda/Version.h
    PATHS ${LibCVCuda_ROOT_DIR}/include
)

find_library(LibCVCuda_LIBRARIES
	NAMES cvcuda
	PATHS ${LibCVCuda_ROOT_DIR}/lib/linux_lib
)

find_library(LibNVCV_Types_LIBRARIES
	NAMES nvcv_types
	PATHS ${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.so

ln -snf libcublasLt.so.11.6.6.84 libcublasLt.so.11
ln -snf libcublasLt.so.11 libcublasLt.so

ln -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.so

ln -snf libcurand.so.10.2.5.297 libcurand.so.10
ln -snf libcurand.so.10 libcurand.so

ln -snf libnvrtc.so.11.4.300 libnvrtc.so.11
ln -snf libnvrtc.so.11 libnvrtc.so

ln -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.so

ln -snf libcudnn_ops_infer.so.8.6.0 libcudnn_ops_infer.so.8
ln -snf libcudnn_ops_infer.so.8 libcudnn_ops_infer.so

ln -snf libcudnn_cnn_infer.so.8.6.0 libcudnn_cnn_infer.so.8
ln -snf libcudnn_cnn_infer.so.8 libcudnn_cnn_infer.so

ln -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.so

ln -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.so

ln -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.so

ln -snf libavdevice.so.58.13.100 libavdevice.so.58
ln -snf libavdevice.so.58 libavdevice.so

ln -snf libavfilter.so.7.110.100 libavfilter.so.7
ln -snf libavfilter.so.7 libavfilter.so

ln -snf libavformat.so.58.76.100 libavformat.so.58
ln -snf libavformat.so.58 libavformat.so

ln -snf libavutil.so.56.70.100 libavutil.so.56
ln -snf libavutil.so.56 libavutil.so

ln -snf libswresample.so.3.9.100 libswresample.so.3
ln -snf libswresample.so.3 libswresample.so

ln -snf libswscale.so.5.9.100 libswscale.so.5
ln -snf libswscale.so.5 libswscale.so

ln -snf libnvmpi.so.1.0.0 libnvmpi.so.1
ln -snf libnvmpi.so.1 libnvmpi.so

ln -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.so

ln -snf libopencv_highgui.so.4.6.0 libopencv_highgui.so.406
ln -snf libopencv_highgui.so.406 libopencv_highgui.so

ln -snf libopencv_imgproc.so.4.6.0 libopencv_imgproc.so.406
ln -snf libopencv_imgproc.so.406 libopencv_imgproc.so

ln -snf libopencv_imgcodecs.so.4.6.0 libopencv_imgcodecs.so.406
ln -snf libopencv_imgcodecs.so.406 libopencv_imgcodecs.so

ln -snf libopencv_video.so.4.6.0 libopencv_video.so.406
ln -snf libopencv_video.so.406 libopencv_video.so

ln -snf libopencv_videoio.so.4.6.0 libopencv_videoio.so.406
ln -snf libopencv_videoio.so.406 libopencv_videoio.so

ln -snf libopencv_features2d.so.4.6.0 libopencv_features2d.so.406
ln -snf libopencv_features2d.so.406 libopencv_features2d.so

ln -snf libopencv_flann.so.4.6.0 libopencv_flann.so.406
ln -snf libopencv_flann.so.406 libopencv_flann.so

ln -snf libopencv_calib3d.so.4.6.0 libopencv_calib3d.so.406
ln -snf libopencv_calib3d.so.406 libopencv_calib3d.so

ln -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.so

ln -snf libpaho-mqtt3a.so.1.3.8 libpaho-mqtt3a.so.1
ln -snf libpaho-mqtt3a.so.1 libpaho-mqtt3a.so

ln -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 type
  259 |     pair<_FIter, _FIter>
      |     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:264:5: error: ‘pair’ does not name a type
  264 |     pair<_FIter, _FIter>
      |     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:432:5: error: ‘pair’ does not name a type
  432 |     pair<const _Tp&, const _Tp&>
      |     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:437:5: error: ‘pair’ does not name a type
  437 |     pair<const _Tp&, const _Tp&>
      |     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:442:5: error: ‘pair’ does not name a type
  442 |     pair<_FIter, _FIter>
      |     ^~~~
/usr/include/c++/11/bits/algorithmfwd.h:447:5: error: ‘pair’ does not name a type
  447 |     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 declaration
  453 |     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 ## c

    class _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 decoder
        if (!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 code
        create_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 project
  has 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 directory
   31 | #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.so

ln -snf libopencv_highgui.so.4.5.4 libopencv_highgui.so.4.5
ln -snf libopencv_highgui.so.4.5 libopencv_highgui.so

ln -snf libopencv_imgproc.so.4.5.4 libopencv_imgproc.so.4.5
ln -snf libopencv_imgproc.so.4.5 libopencv_imgproc.so

ln -snf libopencv_imgcodecs.so.4.5.4 libopencv_imgcodecs.so.4.5
ln -snf libopencv_imgcodecs.so.4.5 libopencv_imgcodecs.so

ln -snf libopencv_video.so.4.5.4 libopencv_video.so.4.5
ln -snf libopencv_video.so.4.5 libopencv_video.so

ln -snf libopencv_videoio.so.4.5.4 libopencv_videoio.so.4.5
ln -snf libopencv_videoio.so.4.5 libopencv_videoio.so

ln -snf libopencv_features2d.so.4.5.4 libopencv_features2d.so.4.5
ln -snf libopencv_features2d.so.4.5 libopencv_features2d.so

ln -snf libopencv_flann.so.4.5.4 libopencv_flann.so.4.5
ln -snf libopencv_flann.so.4.5 libopencv_flann.so

ln -snf libopencv_calib3d.so.4.5.4 libopencv_calib3d.so.4.5
ln -snf libopencv_calib3d.so.4.5 libopencv_calib3d.so

ln -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 already
    set(FFMPEG_FOUND TRUE)
else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)

    find_path(
            FFMPEG_AVCODEC_INCLUDE_DIR
            NAMES libavcodec/avcodec.h
            PATHS ${_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_LIBAVCODEC
            NAMES avcodec
            PATHS ${_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_LIBAVFORMAT
            NAMES avformat
            PATHS ${_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_LIBSWRESAMPLE
            NAMES swresample
            PATHS ${_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_LIBAVUTIL
            NAMES avutil
            PATHS ${_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_LIBSWSCALE
            NAMES swscale
            PATHS ${_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_LIBAVFILTER
            NAMES avfilter
            PATHS ${_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_LIBAVDEVICE
            NAMES avdevice
            PATHS ${_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 already
    set(FFMPEG_FOUND TRUE)
else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIRS)

   	find_path(LibFFMPEG_ROOT_DIR
		NAMES include/libavcodec/avcodec.h
		PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg
		NO_DEFAULT_PATH
	)	
   
    find_path(LibFFMEPG_INCLUDE_DIR
        NAMES libavcodec/avcodec.h
        PATHS ${LibFFMPEG_ROOT_DIR}/include
        NO_DEFAULT_PATH
    )

    find_library(FFMPEG_LIBAVCODEC
            NAMES avcodec
            PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib
            NO_DEFAULT_PATH
    )
  
    find_library(
            FFMPEG_LIBAVFORMAT
            NAMES avformat
            PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib
            NO_DEFAULT_PATH
    )
  
    find_library(
            FFMPEG_LIBSWRESAMPLE
            NAMES swresample
            PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib
            NO_DEFAULT_PATH
    )
 
    find_library(
            FFMPEG_LIBAVUTIL
            NAMES avutil
            PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib
            NO_DEFAULT_PATH
    )

    find_library(
            FFMPEG_LIBSWSCALE
            NAMES swscale
            PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib
            NO_DEFAULT_PATH
    )

    find_library(
            FFMPEG_LIBAVFILTER
            NAMES avfilter
            PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib
            NO_DEFAULT_PATH
    )
    find_library(
            FFMPEG_LIBAVDEVICE
            NAMES avdevice
            PATHS ${CNSTREAM_ROOT_PATH}/3rdparty/ffmpeg/lib/linux_lib
            NO_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_DIR
   used as include directory in directory /data/chw/nvstream/infer_server
   used as include directory in directory /data/chw/nvstream/infer_server
   used as include directory in directory /data/chw/nvstream/infer_server

CMake 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博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2110038.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

最值得信赖的10款电脑监控软件推荐

随着信息时代的飞速发展&#xff0c;电脑监控软件在企业管理、家庭安全以及个人隐私保护等多个领域中发挥了重要作用。选择一款功能强大且值得信赖的电脑监控软件&#xff0c;能够帮助用户实现对电脑使用情况的全面监控&#xff0c;保障数据安全并提高工作效率。本文将为您推荐…

FPGA随记——OSERDESE2和IERDESE2

http://t.csdnimg.cn/yNvxf---看这个篇吧 这个挺好的 OSERDESE2 模块要求复位信号高电平有效&#xff0c;并且 需要将异步复位信号同步到串行时钟域。 除了用原语调用&#xff0c;还可以用High Speed SelectIO Wizard这个IP 进行调用 针对具体select IO这个IP的使用和介绍&…

期末C语言基本算法

期末C语言基本算法 题型一 输入两个学生a和b的成绩&#xff0c;输出其中高的成绩 # include <studio.h> void main() {float a,b,max;printf("please enter a and b:");scanf("%f,%f",&a&#xff0c;&b);if(a>b) max a;else max b;pri…

代码随想录:474. 一和零

474. 一和零 二维费用背包问题 class Solution { public:int findMaxForm(vector<string>& strs, int m, int n) {int l strs.size();int dp[110][110] {0};//dp[i][j]表示有i个0&#xff0c;j个1的子集长度for (int i 0; i < l; i) {//遍历字符数组int one …

「漏洞复现」蜂信物联 FastBee 开源物联网平台 download 任意文件读取漏洞

0x01 免责声明 请勿利用文章内的相关技术从事非法测试&#xff0c;由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失&#xff0c;均由使用者本人负责&#xff0c;作者不为此承担任何责任。工具来自网络&#xff0c;安全性自测&#xff0c;如有侵权请联系删…

数据库知识回忆

1、关系型数据库与非关系型数据库 数据库类型数据模型扩展性性能举例关系型数据库基于严格的关系模型->表格较差查询时要优化电商网站的商品信息非关系型数据库相对灵活 比如键值对(redis) 文档数据库(MongoDB)较好较好用户行为日志 2、DBS DBMS OS 关系 用户通过DBMS接口…

怎么将mp4转换为mp3?教你8种值得收藏的转换方法!

怎么将mp4转换为mp3&#xff1f;在日常的数字娱乐与工作中&#xff0c;MP4视频文件因其无所不在的兼容性成为了大众的首选&#xff0c;但与此同时&#xff0c;它们也悄然带来了一些不便&#xff0c;比如面对一个视频&#xff0c;其中的视觉内容或许并不吸引你&#xff0c;但你却…

Xmind思维导图领衔,三款常备神器助你2024年思维升级!

到了2024年&#xff0c;信息多得让人眼花&#xff0c;新东西学都学不完。要在这么多信息里保持清醒&#xff0c;快速学东西&#xff0c;对大家来说是个考验。好在&#xff0c;科技帮了我们大忙&#xff0c;比如思维导图软件&#xff0c;它们直观又灵活&#xff0c;帮我们提高思…

COD论文笔记 ECCV2024 Just a Hint: Point-Supervised Camouflaged Object Detection

这篇论文的主要动机、现有方法的不足、拟解决的问题、主要贡献和创新点&#xff1a; 1. 动机 伪装物体检测&#xff08;Camouflaged Object Detection, COD&#xff09;旨在检测隐藏在环境中的伪装物体&#xff0c;这是一个具有挑战性的任务。由于伪装物体与背景的细微差别和…

Simulink:循环计数器 Counter Free-Running

原文&#xff1a;Matlab生成stm32代码_matlab stm32-CSDN博客 使用“Counter Free-Running”模块进行计数&#xff0c;参数配置如下 此配置的意思为每0.5秒计数一次&#xff0c;计数的最大值为2^Nbits – 1&#xff0c;其中Nbits为所填的2&#xff0c;所以这里最大值为3。 示波…

Prometheus + Grafana + nVisual 实现运维监控全面可视化

Prometheus主要实现采集、存储、查询设备数据指标、告警等功能&#xff1b;Grafana通过Prometheus的API以仪表板的形展示数据&#xff0c;同时在线提供了大量监测数据展示模版。然而&#xff0c;实际运维中我们不仅需要实时监测数据&#xff0c;还需要了解设备的物理位置、拓扑…

如何在Centos7安装“Grafana“?

一、下载 下载地址&#xff1a;https://dl.grafana.com/oss/release/grafana-9.0.0.linux-amd64.tar.gz 二、上传 到对应目录 三、解压文件 tar -zxvf grafana-9.0.0.linux-amd64.tar.gz 四、进入解压后的文件夹&#xff0c; cd grafana-9.0.0五、启动 1、前台启动&#…

LaTeX中算法环境横线/宽度调整(Algorithm)

在 LaTeX 中&#xff0c;Algorithm 环境默认会占据整栏的宽度。如果你想调整算法的宽度&#xff0c;可以使用 minipage 环境来控制其占用的空间。 原程序&#xff1a; \begin{center} % center algorithm % \begin{minipage}{.7\linewidth} \begin{algorithm}[H]\caption{The…

吃尽时代“黑利”,地信、测绘、城规专业00后,该走那条路?

00后&#xff0c;出生就享受到了互联网带来的便捷生活。 同时&#xff0c;也接收到来自四面八方的信息&#xff0c;包括负面消息。 高考改革&#xff0c;成为第一批吃螃蟹的人。大学入校疫情封闭&#xff0c;未能享受到美好校园生活。毕业那年&#xff0c;解封后又面临着离校&…

还得是苏州!!诚意满满大手笔!!!看电影免费游江南

中秋临近&#xff0c;根据康锐原创小说《月落姑苏》改编的爱情电影《江南&#xff1a;在爱开始的地方等你》即将开始点映。9 月 7 日和 8 日&#xff0c;影片在长三角的江苏、浙江、上海、安徽四省市率先开启限时超前点映&#xff0c;紧接着9 月 14 日&#xff0c;全国限时点映…

传统CV算法——角点特征点提取匹配算法实战

harris角点 角点可以是两个边缘的角点&#xff1b;角点是邻域内具有两个主方向的特征点&#xff1b;角点通常被定义为两条边的交点&#xff0c;更严格的说&#xff0c;角点的局部邻域应该具有两个不同区域的不同方向的边界。或者说&#xff0c;角点就是多条轮廓线之间的交点。…

“释放CPU多核潜能,Linux线程技术助你一臂之力,创新无限!“#Linux系统编程之线程

"释放CPU多核潜能&#xff0c;Linux线程技术助你一臂之力&#xff0c;创新无限&#xff01;"#Linux系统编程之线程 前言预备知识一、 线程概述&#xff08;与进程的区别及线程的优势&#xff09;1.1 进程与线程的联系图1.2 进程与线程1.3 使用线程的理由 二、 线程创…

【在Linux世界中追寻伟大的One Piece】数据链路层

目录 1 -> 数据链路层 2 -> 对比理解“数据链路层”和“网络层” 3 -> 以太网 3.1 -> 以太网的帧格式 4 -> 认识MAC地址 4.1 -> 对比理解MAC地址和IP地址 5 -> 认识MTU 5.1 -> MTU对IP协议的影响 5.2 -> MTU对UDP协议的影响 5.3 -> MT…

如何用涡街流量计计量检测焦炉煤气?

涡街流量计在焦炉煤气计量检测之中仍广泛使用&#xff0c;但也存在一些问题。让我们谈谈这些问题的原因和解决办法。 现场计量检测系统发生故障的原因可归纳为两大原因&#xff0c;一是由流量计或其关联设备引起的。第二种是非流量仪表原因&#xff0c;即流量仪表正常&#xff…

递归求解斐波那契数列的时间复杂度——几种简洁证明

李春葆《算法设计与分析》绿皮--题库版---61页特征方程法&#xff1a;