提交 13c98ad8 编写于 作者: B BohaoWu

Adjust code for compilering nvdec-extractframe.

上级 730bdcd5
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)
......@@ -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 <string>
#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
......
......@@ -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 <cuda.h>
#include <list>
......@@ -29,8 +19,8 @@
#include <string>
#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);
......
......@@ -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 <nvjpeg.h>
#include <string>
#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() {
......
......@@ -28,6 +28,7 @@ PYBIND11_MODULE(hwextract, m) {
pybind11::class_<baidu::xvision::ExtractFrameBGRARaw>(m,
"HwExtractFrameBGRARaw")
.def(pybind11::init<int>())
.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(),
......
......@@ -17,7 +17,7 @@
#include <memory>
#include <string>
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;
......
......@@ -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;
......
......@@ -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 <cstring>
#include <iomanip>
#include <memory>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册