-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Return RGB frames as output of GPU decoder #5191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7ac67b9
d5ef8bc
7a472d1
8fb7e3c
b595d8a
73ab184
e43282e
ff09aac
eb63a8a
945c39b
7c85da9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -472,6 +472,7 @@ def get_extensions(): | |
"z", | ||
"pthread", | ||
"dl", | ||
"nppicc", | ||
], | ||
extra_compile_args=extra_compile_args, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include "decoder.h" | ||
#include <c10/util/Logging.h> | ||
#include <nppi_color_conversion.h> | ||
#include <cmath> | ||
#include <cstring> | ||
#include <unordered_map> | ||
|
@@ -138,38 +139,24 @@ int Decoder::handle_picture_display(CUVIDPARSERDISPINFO* disp_info) { | |
} | ||
|
||
auto options = torch::TensorOptions().dtype(torch::kU8).device(torch::kCUDA); | ||
torch::Tensor decoded_frame = torch::empty({get_frame_size()}, options); | ||
torch::Tensor decoded_frame = torch::empty({get_height(), width, 3}, options); | ||
uint8_t* frame_ptr = decoded_frame.data_ptr<uint8_t>(); | ||
const uint8_t* const source_arr[] = { | ||
(const uint8_t* const)source_frame, | ||
(const uint8_t* const)(source_frame + source_pitch * ((surface_height + 1) & ~1))}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like us to double-check this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. surface_height is different from luma_height which is directly related to the video dimensions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. luma height is aligned by 2, so the chroma offset should not be odd(chroma base address can't be odd memory location), hence the alignment. |
||
|
||
auto err = nppiNV12ToRGB_709CSC_8u_P2C3R( | ||
source_arr, | ||
source_pitch, | ||
frame_ptr, | ||
width * 3, | ||
{(int)decoded_frame.size(1), (int)decoded_frame.size(0)}); | ||
|
||
TORCH_CHECK( | ||
err == NPP_NO_ERROR, | ||
"Failed to convert from NV12 to RGB. Error code:", | ||
err); | ||
|
||
// Copy luma plane | ||
CUDA_MEMCPY2D m = {0}; | ||
m.srcMemoryType = CU_MEMORYTYPE_DEVICE; | ||
m.srcDevice = source_frame; | ||
m.srcPitch = source_pitch; | ||
m.dstMemoryType = CU_MEMORYTYPE_DEVICE; | ||
m.dstDevice = (CUdeviceptr)(m.dstHost = frame_ptr); | ||
m.dstPitch = get_width() * bytes_per_pixel; | ||
m.WidthInBytes = get_width() * bytes_per_pixel; | ||
m.Height = luma_height; | ||
check_for_cuda_errors(cuMemcpy2DAsync(&m, cuvidStream), __LINE__, __FILE__); | ||
|
||
// Copy chroma plane | ||
// NVDEC output has luma height aligned by 2. Adjust chroma offset by aligning | ||
// height | ||
m.srcDevice = | ||
(CUdeviceptr)((uint8_t*)source_frame + m.srcPitch * ((surface_height + 1) & ~1)); | ||
m.dstDevice = (CUdeviceptr)(m.dstHost = frame_ptr + m.dstPitch * luma_height); | ||
m.Height = chroma_height; | ||
check_for_cuda_errors(cuMemcpy2DAsync(&m, cuvidStream), __LINE__, __FILE__); | ||
|
||
if (num_chroma_planes == 2) { | ||
m.srcDevice = | ||
(CUdeviceptr)((uint8_t*)source_frame + m.srcPitch * ((surface_height + 1) & ~1) * 2); | ||
m.dstDevice = | ||
(CUdeviceptr)(m.dstHost = frame_ptr + m.dstPitch * luma_height * 2); | ||
m.Height = chroma_height; | ||
check_for_cuda_errors(cuMemcpy2DAsync(&m, cuvidStream), __LINE__, __FILE__); | ||
} | ||
check_for_cuda_errors(cuStreamSynchronize(cuvidStream), __LINE__, __FILE__); | ||
decoded_frames.push(decoded_frame); | ||
check_for_cuda_errors(cuCtxPopCurrent(NULL), __LINE__, __FILE__); | ||
|
Uh oh!
There was an error while loading. Please reload this page.