From 13c98ad8e8f595ff8bdf8adb283edc52be76a89f Mon Sep 17 00:00:00 2001 From: BohaoWu <37072443+BohaoWu@users.noreply.github.com> Date: Mon, 12 Oct 2020 16:56:56 +0800 Subject: [PATCH] Adjust code for compilering nvdec-extractframe. --- .../nvdec-extractframe/CMakeLists.txt | 50 +++++++++++++++++++ .../include/ExtractFrameBGRARaw.h | 19 ++----- .../include/ExtractFrameBase.h | 15 +----- .../include/ExtractFrameJpeg.h | 19 ++----- .../pybind/pybind_frame_extract.cpp | 5 ++ .../src/ExtractFrameBGRARaw.cpp | 5 +- .../src/ExtractFrameJpeg.cpp | 5 +- .../nvdec-extractframe/src/main.cpp | 10 ---- 8 files changed, 67 insertions(+), 61 deletions(-) create mode 100644 core/preprocess/nvdec-extractframe/CMakeLists.txt diff --git a/core/preprocess/nvdec-extractframe/CMakeLists.txt b/core/preprocess/nvdec-extractframe/CMakeLists.txt new file mode 100644 index 00000000..1f92ace8 --- /dev/null +++ b/core/preprocess/nvdec-extractframe/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.2) +project(hw-extract) +include(cuda) +include(configure) + +#execute_process(COMMAND wget https://paddle-serving.bj.bcebos.com/external_code/preprocesslib.zip) +#execute_process(COMMAND mv preprocesslib.zip ${CMAKE_SOURCE_DIR}/core/preprocess/nvdec-extractframe/) +#execute_process(COMMAND unzip -oq ${CMAKE_SOURCE_DIR}/core/preprocess/nvdec-extractframe/preprocesslib.zip -d ../core/preprocess/nvdec-extractframe/) +#execute_process(COMMAND rm -rf ${CMAKE_SOURCE_DIR}/core/preprocess/nvdec-extractframe/__MACOSX) + +#C flags +set(CMAKE_C_FLAGS " -g -pipe -W -Wall -fPIC -Wmissing-field-initializers") + +#C++ flags. +set(CMAKE_CXX_FLAGS " -g -pipe -W -Wall -fPIC -std=c++11 -Wmissing-field-initializers") + +add_subdirectory(cuda) +set(CMAKE_CUDA_FLAGS "-ccbin -Xcompiler -fPIC --std=c++11") +set(CUDA_NVCC_FLAGS "-Xcompiler -fPIC --std=c++11") +set(EXTRA_LIBS ${EXTRA_LIBS} hwgpu) +set(CUDA_LIBRARIES ${CUDA_TOOLKIT_ROOT_DIR}/lib64) + +#release headers +include_directories(*.h) +include_directories(*.hpp) +include_directories(include/*.h) +include_directories(include/*.hpp) + +include_directories(.) +include_directories(./include) +include_directories(./codessdkinclude/include) +include_directories(./ffmpeginclude/include) +# include_directories(./pybind11/include) +include_directories(./pythoninclude/python2.7/) +include_directories(./Utils) +include_directories(${CUDA_INCLUDE_DIRS}) + +# Preprocessor libs. +file(GLOB LIB_FILES ${CMAKE_SOURCE_DIR}/core/preprocess/nvdec-extractframe/lib/*.so) +file(GLOB CUDA_LIB_FILES ${CUDA_LIBRARIES}/*.so) +file(GLOB NVJPEG_LIBS ${CMAKE_SOURCE_DIR}/core/preprocess/nvdec-extractframe/lib/libnvjpeg.*) +file(GLOB SOURCE_FILES src/*.cpp NvDecoder/*.cpp pybind/*.cpp) + +#.so +add_library(hwextract SHARED ${SOURCE_FILES}) +target_link_libraries(hwextract ${CMAKE_SOURCE_DIR}/core/preprocess/nvdec-extractframe/lib/libnvjpeg.so) +target_link_libraries(hwextract ${EXTRA_LIBS}) +target_link_libraries(hwextract ${LIB_FILES}) +target_link_libraries(hwextract ${CUDA_LIB_FILES}) +# execute_process(COMMAND rm ${CMAKE_SOURCE_DIR}/core/preprocess/nvdec-extractframe/preprocesslib.zip) diff --git a/core/preprocess/nvdec-extractframe/include/ExtractFrameBGRARaw.h b/core/preprocess/nvdec-extractframe/include/ExtractFrameBGRARaw.h index 739e516b..a52f035f 100644 --- a/core/preprocess/nvdec-extractframe/include/ExtractFrameBGRARaw.h +++ b/core/preprocess/nvdec-extractframe/include/ExtractFrameBGRARaw.h @@ -12,21 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -/******************************************* - * - * Copyright (c) 2020 Baidu.com, Inc. All Rights Reserved - * - ******************************************/ -/** - * @file ExtractFrameBGRARaw.h - * @author chengang06@baidu.com - * @date 2020-04-15 - **/ -#ifndef CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEBGRARAW_H_ -#define CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEBGRARAW_H_ #include #include "ExtractFrameBase.h" + +#ifndef CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEBGRARAW_H_ +#define CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEBGRARAW_H_ namespace baidu { namespace xvision { class ExtractFrameBGRARaw : public ExtractFrameBase { @@ -54,9 +45,7 @@ class ExtractFrameBGRARaw : public ExtractFrameBase { * @returns * IMGDataList **/ - IMGDataList extract_frame(const std::string &file_path, - int n = 1, - int count = 200); + IMGDataList extract_frame(const std::string &file_path, int n = 1); }; } // namespace xvision } // namespace baidu diff --git a/core/preprocess/nvdec-extractframe/include/ExtractFrameBase.h b/core/preprocess/nvdec-extractframe/include/ExtractFrameBase.h index 382aee6b..5fdb12f4 100644 --- a/core/preprocess/nvdec-extractframe/include/ExtractFrameBase.h +++ b/core/preprocess/nvdec-extractframe/include/ExtractFrameBase.h @@ -12,16 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/******************************************* - * - * Copyright (c) 2020 Baidu.com, Inc. All Rights Reserved - * - ******************************************/ -/** - * @file ExtractFrameBase.h - * @author chengang06@baidu.com - * @date 2020-04-15 - **/ #include #include @@ -29,8 +19,8 @@ #include #include "NvDecoder/NvDecoder.h" -#include "Utils/ColorSpace.h" #include "Utils/FFmpegDemuxer.h" +#include "cuda/ColorSpace.h" #ifndef CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEBASE_H_ #define CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEBASE_H_ namespace baidu { @@ -140,8 +130,7 @@ class ExtractFrameBase { } virtual int init(); virtual IMGDataList extract_frame(const std::string& file_path, - int n = 1, - int count = 200) = 0; + int n = 1) = 0; virtual ~ExtractFrameBase() { if (p_cu_context != nullptr) { cuCtxDestroy(p_cu_context); diff --git a/core/preprocess/nvdec-extractframe/include/ExtractFrameJpeg.h b/core/preprocess/nvdec-extractframe/include/ExtractFrameJpeg.h index 2c49a3cf..31c98444 100644 --- a/core/preprocess/nvdec-extractframe/include/ExtractFrameJpeg.h +++ b/core/preprocess/nvdec-extractframe/include/ExtractFrameJpeg.h @@ -12,23 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -/******************************************* - * - * Copyright (c) 2020 Baidu.com, Inc. All Rights Reserved - * - ******************************************/ -/** - * @file ExtractFrameJpeg.h - * @author chengang06@baidu.com - * @date 2020-04-20 - **/ -#ifndef CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEJPEG_H_ -#define CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEJPEG_H_ #include #include #include "ExtractFrameBase.h" +#ifndef CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEJPEG_H_ +#define CORE_PREPROCESS_NVDEC_EXTRACTFRAME_INCLUDE_EXTRACTFRAMEJPEG_H_ + namespace baidu { namespace xvision { class ExtractFrameJpeg : public ExtractFrameBase { @@ -57,9 +48,7 @@ class ExtractFrameJpeg : public ExtractFrameBase { * @returns * IMGDataList **/ - IMGDataList extract_frame(const std::string& file_path, - int n = 1, - int count = 200); + IMGDataList extract_frame(const std::string& file_path, int n = 1); int init(); virtual ~ExtractFrameJpeg() { diff --git a/core/preprocess/nvdec-extractframe/pybind/pybind_frame_extract.cpp b/core/preprocess/nvdec-extractframe/pybind/pybind_frame_extract.cpp index c321eb2b..80bdd9e2 100644 --- a/core/preprocess/nvdec-extractframe/pybind/pybind_frame_extract.cpp +++ b/core/preprocess/nvdec-extractframe/pybind/pybind_frame_extract.cpp @@ -28,6 +28,7 @@ PYBIND11_MODULE(hwextract, m) { pybind11::class_(m, "HwExtractFrameBGRARaw") .def(pybind11::init()) + .def("init_handler", &baidu::xvision::ExtractFrameBGRARaw::init) .def("extract_frame", &baidu::xvision::ExtractFrameBGRARaw::extract_frame); @@ -41,6 +42,10 @@ PYBIND11_MODULE(hwextract, m) { &baidu::xvision::FrameResult::free_memory) // for gcc 4.8.2 , this // must be called ,both // in cpp or python + // .def("__copy__", [](const baidu::xvision::FrameResult &self){return + // self.deepcopy();}) + // .def("__deepcopy__", [](const baidu::xvision::FrameResult &self, + // pybind11::dict){return baidu::xvision::FrameResult(self);}, "memo"_a) .def_buffer([](baidu::xvision::FrameResult& m) -> pybind11::buffer_info { return pybind11::buffer_info( m.get_frame(), diff --git a/core/preprocess/nvdec-extractframe/src/ExtractFrameBGRARaw.cpp b/core/preprocess/nvdec-extractframe/src/ExtractFrameBGRARaw.cpp index 87b648b3..63423130 100644 --- a/core/preprocess/nvdec-extractframe/src/ExtractFrameBGRARaw.cpp +++ b/core/preprocess/nvdec-extractframe/src/ExtractFrameBGRARaw.cpp @@ -17,7 +17,7 @@ #include #include baidu::xvision::IMGDataList baidu::xvision::ExtractFrameBGRARaw::extract_frame( - const std::string &file_path, int n, int count) { + const std::string &file_path, int n) { FFmpegDemuxer demuxer(file_path.c_str()); NvDecoder nvdec( p_cu_context, true, FFmpeg2NvCodecId(demuxer.GetVideoCodec())); @@ -111,9 +111,6 @@ baidu::xvision::IMGDataList baidu::xvision::ExtractFrameBGRARaw::extract_frame( nvdec.GetHeight() + (nvdec.GetChromaHeight() * nvdec.GetNumChromaPlanes()));*/ } - if (result_list.size() >= count) { - break; - } } while (n_video_bytes); cuMemFree(p_tmp_image); return result_list; diff --git a/core/preprocess/nvdec-extractframe/src/ExtractFrameJpeg.cpp b/core/preprocess/nvdec-extractframe/src/ExtractFrameJpeg.cpp index 1a2e6d37..87fa7c50 100644 --- a/core/preprocess/nvdec-extractframe/src/ExtractFrameJpeg.cpp +++ b/core/preprocess/nvdec-extractframe/src/ExtractFrameJpeg.cpp @@ -59,7 +59,7 @@ int baidu::xvision::ExtractFrameJpeg::init() { return 0; } baidu::xvision::IMGDataList baidu::xvision::ExtractFrameJpeg::extract_frame( - const std::string &file_path, int n, int count) { + const std::string &file_path, int n) { FFmpegDemuxer demuxer(file_path.c_str()); NvDecoder nvdec( p_cu_context, true, FFmpeg2NvCodecId(demuxer.GetVideoCodec())); @@ -143,9 +143,6 @@ baidu::xvision::IMGDataList baidu::xvision::ExtractFrameJpeg::extract_frame( fm_tmp); result_list.push_back(fm_tmp); } - if (result_list.size() >= count) { - break; - } } while (n_video_bytes); cuMemFree(p_tmp_image); return result_list; diff --git a/core/preprocess/nvdec-extractframe/src/main.cpp b/core/preprocess/nvdec-extractframe/src/main.cpp index a3e245e6..c960c9d5 100644 --- a/core/preprocess/nvdec-extractframe/src/main.cpp +++ b/core/preprocess/nvdec-extractframe/src/main.cpp @@ -12,16 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -/******************************************* - * - * Copyright (c) 2020 Baidu.com, Inc. All Rights Reserved - * - ******************************************/ -/** - * @file ExtractFrameBGRARaw.h - * @author chengang06@baidu.com - * @date 2020-04-16 - **/ #include #include #include -- GitLab