Skip to content

Commit b538d13

Browse files
committed
comments
1 parent 939240b commit b538d13

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/torchcodec/_core/CudaDeviceInterface.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ std::string CudaDeviceInterface::getDetails() {
373373
// Below are methods exclusive to video encoding:
374374
// --------------------------------------------------------------------------
375375
namespace {
376-
// RGB to YUV conversion matrices organized by color range and color space
376+
// RGB to YUV conversion matrices to use in NPP color conversion functions
377377
struct ColorConversionMatrices {
378378
static constexpr Npp32f BT601_LIMITED[3][4] = {
379379
{0.257f, 0.504f, 0.098f, 16.0f},
@@ -406,19 +406,17 @@ struct ColorConversionMatrices {
406406
{0.5f, -0.459786f, -0.040214f, 128.0f}};
407407
};
408408

409-
// Returns the appropriate conversion matrix based on codec context color space
410-
// and range
409+
// Returns conversion matrix based on codec context color space and range
411410
const Npp32f (*getConversionMatrix(AVCodecContext* codecContext))[4] {
412-
// Limited range (TV/Video range 16-235) - default if unspecified
413-
if (codecContext->color_range == AVCOL_RANGE_MPEG ||
411+
if (codecContext->color_range == AVCOL_RANGE_MPEG || // limited range
414412
codecContext->color_range == AVCOL_RANGE_UNSPECIFIED) {
415413
if (codecContext->colorspace == AVCOL_SPC_BT470BG) {
416414
return ColorConversionMatrices::BT601_LIMITED;
417415
} else if (codecContext->colorspace == AVCOL_SPC_BT709) {
418416
return ColorConversionMatrices::BT709_LIMITED;
419417
} else if (codecContext->colorspace == AVCOL_SPC_BT2020_NCL) {
420418
return ColorConversionMatrices::BT2020_LIMITED;
421-
} else { // AVCOL_SPC_UNSPECIFIED or unknown - default to BT.601
419+
} else { // default to BT.601
422420
return ColorConversionMatrices::BT601_LIMITED;
423421
}
424422
} else if (codecContext->color_range == AVCOL_RANGE_JPEG) { // full range
@@ -428,7 +426,7 @@ const Npp32f (*getConversionMatrix(AVCodecContext* codecContext))[4] {
428426
return ColorConversionMatrices::BT709_FULL;
429427
} else if (codecContext->colorspace == AVCOL_SPC_BT2020_NCL) {
430428
return ColorConversionMatrices::BT2020_FULL;
431-
} else { // AVCOL_SPC_UNSPECIFIED or unknown - default to BT.601
429+
} else { // default to BT.601
432430
return ColorConversionMatrices::BT601_FULL;
433431
}
434432
}

src/torchcodec/_core/Encoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ void VideoEncoder::initializeEncoder(
787787
validatePixelFormat(*avCodec, videoStreamOptions.pixelFormat.value());
788788
} else {
789789
if (frames_.device().is_cuda()) {
790+
// Default to YUV420P for CUDA encoding if unset.
790791
outPixelFormat_ = AV_PIX_FMT_YUV420P;
791792
} else {
792793
const AVPixelFormat* formats = getSupportedPixelFormats(*avCodec);

test/test_encoders.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,17 +1455,10 @@ def test_nvenc_against_ffmpeg_cli(
14551455
)
14561456

14571457
if method == "to_file":
1458-
metadata_fields = ["pix_fmt", "color_range", "color_space"]
1458+
metadata_fields = ["color_range", "color_space"]
14591459
ffmpeg_metadata = self._get_video_metadata(
14601460
ffmpeg_encoded_path, metadata_fields
14611461
)
14621462
encoder_metadata = self._get_video_metadata(encoder_output, metadata_fields)
14631463
assert encoder_metadata["color_range"] == ffmpeg_metadata["color_range"]
14641464
assert encoder_metadata["color_space"] == ffmpeg_metadata["color_space"]
1465-
1466-
encoder_fmt = encoder_metadata["pix_fmt"]
1467-
ffmpeg_fmt = ffmpeg_metadata["pix_fmt"]
1468-
# Accept yuv420p (modern) as equivalent to yuvj420p (deprecated full range)
1469-
assert (encoder_fmt == ffmpeg_fmt) or (
1470-
encoder_fmt == "yuv420p" and ffmpeg_fmt == "yuvj420p"
1471-
)

0 commit comments

Comments
 (0)