diff --git a/core/preprocess/nvdec-extractframe/CMakeLists.txt b/core/preprocess/nvdec-extractframe/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f92ace8e428277a5f67c292d3a0611e00c5882b --- /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 739e516bd3dbd482a104bc1f2b6d09a403caaaca..a52f035f155d0278c933a24bd443f6e1a1510c65 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 382aee6bbd1ae4406506f747a18428137808302d..5fdb12f4348f20c8b12d6bece5f788f404e15212 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 2c49a3cf49c00c7d53af7533454ae1e07e39b693..31c98444f9f7f3cbfeeebed98239680c2f34b1fc 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 c321eb2baf5bc6659b63ce672d3adf9433b73105..80bdd9e2f6780e97191c544d0867a1977ece24c7 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 87b648b348e16895ce7d4d744d8c32f2e56f5bd5..6342313045e7da040f7a87672f83ed0e39f0ed9d 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 1a2e6d378826ca66d51d2d25a836e4c3a8e765e1..87fa7c50c5335caea97e3243d366124a00b6667b 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 a3e245e6e7b04ad37bee002d184ab3c8f0153c74..c960c9d5e508e452a0d4e840a77750343639494e 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