Skip to content

Commit f51d283

Browse files
committed
Fix colorspace
1 parent dae30f1 commit f51d283

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/torchcodec/decoders/_core/CudaDevice.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,24 @@ void convertAVFrameToDecodedOutputOnCuda(
223223
Npp8u* input[2] = {src->data[0], src->data[1]};
224224

225225
auto start = std::chrono::high_resolution_clock::now();
226-
NppStatus status = nppiNV12ToRGB_8u_P2C3R(
227-
input,
228-
src->linesize[0],
229-
static_cast<Npp8u*>(dst.data_ptr()),
230-
dst.stride(0),
231-
oSizeROI);
226+
NppStatus status;
227+
if (src->colorspace == AVColorSpace::AVCOL_SPC_BT709) {
228+
status = nppiNV12ToRGB_709HDTV_8u_P2C3R(
229+
input,
230+
src->linesize[0],
231+
static_cast<Npp8u*>(dst.data_ptr()),
232+
dst.stride(0),
233+
oSizeROI);
234+
} else {
235+
status = nppiNV12ToRGB_8u_P2C3R(
236+
input,
237+
src->linesize[0],
238+
static_cast<Npp8u*>(dst.data_ptr()),
239+
dst.stride(0),
240+
oSizeROI);
241+
}
232242
TORCH_CHECK(status == NPP_SUCCESS, "Failed to convert NV12 frame.");
243+
233244
// Make the pytorch stream wait for the npp kernel to finish before using the
234245
// output.
235246
at::cuda::CUDAEvent nppDoneEvent;

0 commit comments

Comments
 (0)