提交 1688582d 编写于 作者: B BohaoWu

Check for complier.

上级 13c98ad8
add_subdirectory(hwvideoframe) add_subdirectory(hwvideoframe)
add_subdirectory(nvdec-extractframe)
...@@ -82,7 +82,7 @@ class ExtractFrameJpeg : public ExtractFrameBase { ...@@ -82,7 +82,7 @@ class ExtractFrameJpeg : public ExtractFrameBase {
int jpeg_encode(uint8_t* p_image, int jpeg_encode(uint8_t* p_image,
int width, int width,
int height, int height,
const FrameResult& result); FrameResult &result);
nvjpegHandle_t _nv_jpeg_handler; nvjpegHandle_t _nv_jpeg_handler;
nvjpegEncoderState_t _nv_enc_state; nvjpegEncoderState_t _nv_enc_state;
nvjpegEncoderParams_t _nv_enc_params; nvjpegEncoderParams_t _nv_enc_params;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
simplelogger::Logger* logger = simplelogger::Logger* logger =
simplelogger::LoggerFactory::CreateConsoleLogger(); simplelogger::LoggerFactory::CreateConsoleLogger();
PYBIND11_MODULE(hwextract, m) { PYBIND11_MODULE(libhwextract, m) {
pybind11::class_<baidu::xvision::ExtractFrameJpeg>(m, "HwExtractFrameJpeg") pybind11::class_<baidu::xvision::ExtractFrameJpeg>(m, "HwExtractFrameJpeg")
.def(pybind11::init<int>()) .def(pybind11::init<int>())
.def("init_handler", &baidu::xvision::ExtractFrameJpeg::init) .def("init_handler", &baidu::xvision::ExtractFrameJpeg::init)
......
// Copyright (c) 2020 PaddlePaddle Authors. 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
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstring>
#include <iomanip>
#include <memory>
#include <sstream>
#include <string>
#include "ExtractFrameBGRARaw.h"
#include "ExtractFrameJpeg.h"
simplelogger::Logger* g_logger =
simplelogger::LoggerFactory::CreateConsoleLogger();
/**
* @Name:
* image_file_writer
* @Feature:
* write image data to file
* @params
* img_data: image_data
* file_path: image_file stored path
* prefix: image_name prefix
* extension: image_file extension name
* @returns
* void
**/
void inline image_file_writer(const baidu::xvision::FrameResult& img_data,
std::string file_path,
std::string prefix,
std::string extension = "raw") {
std::ofstream f_out(file_path + "/" + prefix + "." + extension,
std::ios::binary | std::ios::out);
f_out.write(reinterpret_cast<char*>(img_data.get_frame()), img_data.len());
f_out.close();
}
bool parse_cmd_line(int argc, const char* const argv[]) {
if (argc <= 3) {
LOG(FATAL) << "params error, eg: ./hw_frame_extract /path/to/mp4.mp4 "
"/output/path bgra|jpeg";
return false;
}
if (!strcmp(argv[3], "bgra") && !strcmp(argv[3], "jpeg")) {
LOG(FATAL) << "unsupported output file format";
return false;
}
return true;
}
int main(int argc, char* argv[]) {
if (!parse_cmd_line(argc, argv)) {
return -1;
}
baidu::xvision::ExtractFrameBase* extract_frame_handler(nullptr);
if (strcmp("bgra", argv[3]) == 0) {
extract_frame_handler = new baidu::xvision::ExtractFrameBGRARaw();
} else {
extract_frame_handler = new baidu::xvision::ExtractFrameJpeg();
}
auto init_result = extract_frame_handler->init();
auto result = extract_frame_handler->extract_frame(argv[1], 1, 200);
int frame_index = 0;
std::stringstream ss;
for (auto result_iter = result.begin(); result_iter != result.end();
result_iter++) {
ss << std::setw(5) << std::setfill('0') << frame_index;
image_file_writer(*result_iter,
argv[2],
"image_" + std::to_string(result_iter->width()) + "_" +
std::to_string(result_iter->height()) + "_" +
ss.str(),
argv[3]);
result_iter->free_memory();
frame_index++;
ss.str("");
}
return 0;
}
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
import unittest import unittest
import sys import sys
import numpy as np import numpy as np
import cv2
from paddle_serving_app.reader import Sequential, Resize, File2Image from paddle_serving_app.reader import Sequential, Resize, File2Image
import libgpupreprocess as pp import libgpupreprocess as pp
import libhwextract
class TestOperators(unittest.TestCase): class TestOperators(unittest.TestCase):
""" """
...@@ -147,6 +148,29 @@ class TestOperators(unittest.TestCase): ...@@ -147,6 +148,29 @@ class TestOperators(unittest.TestCase):
img_resize_diff = img_vis - img img_resize_diff = img_vis - img
self.assertEqual(np.all(img_resize_diff == 0), True) self.assertEqual(np.all(img_resize_diff == 0), True)
def test_extract_frame(self):
handler = libhwextract.HwExtractFrameJpeg(0)
# 0, gpu card index
# if you want BGRA Raw Data, plz use HwExtractBGRARaw
handler.init_handler()
# init once can decode many videos
video_file_name = sys.argv[1]
# for now just support h264 codec
frame_list = []
try:
frame_list = handler.extract_frame(video_file_name, 1)
# specifiy file name and fps you want to extract, 0 for all frame
except Exception as e_frame:
print("Failed to cutframe, exception[%s]" % (e_frame))
sys.exit(1)
for item in frame_list:
print "i am a item in frame_list"
# do something, for instance
jpeg_array = np.array(item, copy=False)
img = cv2.imdecode(jpeg_array, cv2.IMREAD_COLOR)
cv2.imwrite('1.jpg', img)
item.free_memory()
# have to release memor
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册