videodecodeRGB sample re-org for rocPyDecode (#343)
* re-org videodecodeRGB sample * minor fix * removed un-necessary include * minor fix
Αυτή η υποβολή περιλαμβάνεται σε:
1 γονέας
1943aad663
υποβολή
95f90982eb
5 files changed
+157
-143
No files matched your search
@@ -884,9 +884,10 @@ bool RocVideoDecoder::ReleaseInternalFrames() {
|
||||
}
|
||||
|
||||
|
||||
void RocVideoDecoder::SaveFrameToFile(std::string output_file_name, void *surf_mem, OutputSurfaceInfo *surf_info) {
|
||||
void RocVideoDecoder::SaveFrameToFile(std::string output_file_name, void *surf_mem, OutputSurfaceInfo *surf_info, size_t rgb_image_size) {
|
||||
uint8_t *hst_ptr = nullptr;
|
||||
uint64_t output_image_size = surf_info->output_surface_size_in_bytes;
|
||||
bool is_rgb = (rgb_image_size != 0);
|
||||
uint64_t output_image_size = is_rgb ? rgb_image_size : surf_info->output_surface_size_in_bytes;
|
||||
if (surf_info->mem_type == OUT_SURFACE_MEM_DEV_INTERNAL || surf_info->mem_type == OUT_SURFACE_MEM_DEV_COPIED) {
|
||||
if (hst_ptr == nullptr) {
|
||||
hst_ptr = new uint8_t [output_image_size];
|
||||
@@ -901,10 +902,6 @@ void RocVideoDecoder::SaveFrameToFile(std::string output_file_name, void *surf_m
|
||||
} else
|
||||
hst_ptr = static_cast<uint8_t *> (surf_mem);
|
||||
|
||||
uint8_t *tmp_hst_ptr = hst_ptr;
|
||||
if (surf_info->mem_type == OUT_SURFACE_MEM_DEV_INTERNAL) {
|
||||
tmp_hst_ptr += ((disp_rect_.top + crop_rect_.top) * surf_info->output_pitch) + (disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel;
|
||||
}
|
||||
|
||||
if (current_output_filename.empty()) {
|
||||
current_output_filename = output_file_name;
|
||||
@@ -936,39 +933,47 @@ void RocVideoDecoder::SaveFrameToFile(std::string output_file_name, void *surf_m
|
||||
fp_out_ = fopen(output_file_name.c_str(), "wb");
|
||||
}
|
||||
if (fp_out_) {
|
||||
int img_width = surf_info->output_width;
|
||||
int img_height = surf_info->output_height;
|
||||
int output_stride = surf_info->output_pitch;
|
||||
if (img_width * surf_info->bytes_per_pixel == output_stride && img_height == surf_info->output_vstride) {
|
||||
fwrite(hst_ptr, 1, output_image_size, fp_out_);
|
||||
} else {
|
||||
uint32_t width = surf_info->output_width * surf_info->bytes_per_pixel;
|
||||
if (surf_info->bit_depth <= 16) {
|
||||
for (int i = 0; i < surf_info->output_height; i++) {
|
||||
fwrite(tmp_hst_ptr, 1, width, fp_out_);
|
||||
tmp_hst_ptr += output_stride;
|
||||
}
|
||||
// dump chroma
|
||||
uint8_t *uv_hst_ptr = hst_ptr + output_stride * surf_info->output_vstride;
|
||||
if (surf_info->mem_type == OUT_SURFACE_MEM_DEV_INTERNAL) {
|
||||
uv_hst_ptr += (num_chroma_planes_ == 1) ? (((disp_rect_.top + crop_rect_.top) >> 1) * surf_info->output_pitch) + ((disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel):
|
||||
((disp_rect_.top + crop_rect_.top) * surf_info->output_pitch) + ((disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel);
|
||||
}
|
||||
for (int i = 0; i < chroma_height_; i++) {
|
||||
fwrite(uv_hst_ptr, 1, width, fp_out_);
|
||||
uv_hst_ptr += output_stride;
|
||||
}
|
||||
if (num_chroma_planes_ == 2) {
|
||||
uv_hst_ptr = hst_ptr + output_stride * (surf_info->output_vstride + chroma_vstride_);
|
||||
if (!is_rgb) {
|
||||
uint8_t *tmp_hst_ptr = hst_ptr;
|
||||
if (surf_info->mem_type == OUT_SURFACE_MEM_DEV_INTERNAL) {
|
||||
tmp_hst_ptr += ((disp_rect_.top + crop_rect_.top) * surf_info->output_pitch) + (disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel;
|
||||
}
|
||||
int img_width = surf_info->output_width;
|
||||
int img_height = surf_info->output_height;
|
||||
int output_stride = surf_info->output_pitch;
|
||||
if (img_width * surf_info->bytes_per_pixel == output_stride && img_height == surf_info->output_vstride) {
|
||||
fwrite(hst_ptr, 1, output_image_size, fp_out_);
|
||||
} else {
|
||||
uint32_t width = surf_info->output_width * surf_info->bytes_per_pixel;
|
||||
if (surf_info->bit_depth <= 16) {
|
||||
for (int i = 0; i < surf_info->output_height; i++) {
|
||||
fwrite(tmp_hst_ptr, 1, width, fp_out_);
|
||||
tmp_hst_ptr += output_stride;
|
||||
}
|
||||
// dump chroma
|
||||
uint8_t *uv_hst_ptr = hst_ptr + output_stride * surf_info->output_vstride;
|
||||
if (surf_info->mem_type == OUT_SURFACE_MEM_DEV_INTERNAL) {
|
||||
uv_hst_ptr += ((disp_rect_.top + crop_rect_.top) * surf_info->output_pitch) + ((disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel);
|
||||
uv_hst_ptr += (num_chroma_planes_ == 1) ? (((disp_rect_.top + crop_rect_.top) >> 1) * surf_info->output_pitch) + ((disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel):
|
||||
((disp_rect_.top + crop_rect_.top) * surf_info->output_pitch) + ((disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel);
|
||||
}
|
||||
for (int i = 0; i < chroma_height_; i++) {
|
||||
fwrite(uv_hst_ptr, 1, width, fp_out_);
|
||||
uv_hst_ptr += output_stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num_chroma_planes_ == 2) {
|
||||
uv_hst_ptr = hst_ptr + output_stride * (surf_info->output_vstride + chroma_vstride_);
|
||||
if (surf_info->mem_type == OUT_SURFACE_MEM_DEV_INTERNAL) {
|
||||
uv_hst_ptr += ((disp_rect_.top + crop_rect_.top) * surf_info->output_pitch) + ((disp_rect_.left + crop_rect_.left) * surf_info->bytes_per_pixel);
|
||||
}
|
||||
for (int i = 0; i < chroma_height_; i++) {
|
||||
fwrite(uv_hst_ptr, 1, width, fp_out_);
|
||||
uv_hst_ptr += output_stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fwrite(hst_ptr, 1, rgb_image_size, fp_out_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -319,8 +319,9 @@ class RocVideoDecoder {
|
||||
* @param output_file_name - Output file name
|
||||
* @param dev_mem - pointer to surface memory
|
||||
* @param surf_info - surface info
|
||||
* @param rgb_image_size - image size for rgb (optional). A non_zero value indicates the surf_mem holds an rgb interleaved image and the entire size will be dumped to file
|
||||
*/
|
||||
void SaveFrameToFile(std::string output_file_name, void *surf_mem, OutputSurfaceInfo *surf_info);
|
||||
void SaveFrameToFile(std::string output_file_name, void *surf_mem, OutputSurfaceInfo *surf_info, size_t rgb_image_size = 0);
|
||||
|
||||
/**
|
||||
* @brief Helper funtion to close a existing file and dump to new file in case of multiple files using same decoder
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
Copyright (c) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "colorspace_kernels.h"
|
||||
#include "resize_kernels.h"
|
||||
#include "rocvideodecode/roc_video_dec.h" //for OutputSurfaceInfo
|
||||
|
||||
enum OutputFormatEnum {
|
||||
native = 0, bgr, bgr48, rgb, rgb48, bgra, bgra64, rgba, rgba64
|
||||
};
|
||||
|
||||
class VideoPostProcess {
|
||||
public:
|
||||
VideoPostProcess(){};
|
||||
~VideoPostProcess(){};
|
||||
|
||||
void ColorConvertYUV2RGB(uint8_t *p_src, OutputSurfaceInfo *surf_info, uint8_t *rgb_dev_mem_ptr, OutputFormatEnum e_output_format, hipStream_t hip_stream) {
|
||||
int rgb_width = (surf_info->output_width + 1) & ~1; // has to be a multiple of 2 for hip colorconvert kernels
|
||||
// todo:: get color standard from the decoder
|
||||
if (surf_info->surface_format == rocDecVideoSurfaceFormat_YUV444) {
|
||||
if (e_output_format == bgr)
|
||||
YUV444ToColor24<BGR24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == bgra)
|
||||
YUV444ToColor32<BGRA32>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 4 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgb)
|
||||
YUV444ToColor24<RGB24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgba)
|
||||
YUV444ToColor32<RGBA32>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 4 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
} else if (surf_info->surface_format == rocDecVideoSurfaceFormat_NV12) {
|
||||
if (e_output_format == bgr)
|
||||
Nv12ToColor24<BGR24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == bgra)
|
||||
Nv12ToColor32<BGRA32>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 4 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgb)
|
||||
Nv12ToColor24<RGB24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgba)
|
||||
Nv12ToColor32<RGBA32>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 4 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
}
|
||||
if (surf_info->surface_format == rocDecVideoSurfaceFormat_YUV444_16Bit) {
|
||||
if (e_output_format == bgr)
|
||||
YUV444P16ToColor24<BGR24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgb)
|
||||
YUV444P16ToColor24<RGB24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == bgr48)
|
||||
YUV444P16ToColor48<BGR48>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 6 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgb48)
|
||||
YUV444P16ToColor48<RGB48>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 6 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == bgra64)
|
||||
YUV444P16ToColor64<BGRA64>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 8 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgba64)
|
||||
YUV444P16ToColor64<RGBA64>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 8 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
} else if (surf_info->surface_format == rocDecVideoSurfaceFormat_P016) {
|
||||
if (e_output_format == bgr)
|
||||
P016ToColor24<BGR24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgb)
|
||||
P016ToColor24<RGB24>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 3 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == bgr48)
|
||||
P016ToColor48<BGR48>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 6 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgb48)
|
||||
P016ToColor48<RGB48>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 6 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == bgra64)
|
||||
P016ToColor64<BGRA64>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 8 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
else if (e_output_format == rgba64)
|
||||
P016ToColor64<RGBA64>(p_src, surf_info->output_pitch, static_cast<uint8_t *>(rgb_dev_mem_ptr), 8 * rgb_width, surf_info->output_width,
|
||||
surf_info->output_height, surf_info->output_vstride, 0, hip_stream);
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user