@@ -71,8 +71,8 @@ UniqueAVBufferRef createHardwareDeviceContext(const torch::Device& device) {
7171
7272// RGB to NV12 color conversion matrices (inverse of YUV to RGB)
7373// Note: NPP's ColorTwist function apparently expects "limited range"
74- // coefficient format even when producing full range output. All matrices below
75- // use the limited range coefficient format (Y with +16 offset) for NPP
74+ // coefficient format even when producing full range output. The matrix below
75+ // uses the limited range coefficient format (Y with +16 offset) for NPP
7676// compatibility.
7777
7878// BT.601 limited range (matches FFmpeg default behavior)
@@ -83,7 +83,7 @@ const Npp32f defaultLimitedRangeRgbToNv12[3][4] = {
8383 {-0 .148f , -0 .291f , 0 .439f , 128 .0f },
8484 // V = 0.439*R - 0.368*G - 0.071*B + 128 (BT.601 coefficients)
8585 {0 .439f , -0 .368f , -0 .071f , 128 .0f }};
86- } // anonymous namespace
86+ } // namespace
8787
8888GpuEncoder::GpuEncoder (const torch::Device& device) : device_(device) {
8989 TORCH_CHECK (
@@ -122,7 +122,7 @@ void GpuEncoder::setupHardwareFrameContext(AVCodecContext* codecContext) {
122122
123123 // Always set pixel formats to options that support CUDA encoding.
124124 // TODO-VideoEncoder: Enable user set pixel formats to be set and properly
125- // converted with npp functions below
125+ // handled with NPP functions below
126126 codecContext->sw_pix_fmt = AV_PIX_FMT_NV12;
127127 codecContext->pix_fmt = AV_PIX_FMT_CUDA;
128128
@@ -150,20 +150,17 @@ UniqueAVFrame GpuEncoder::convertTensorToAVFrame(
150150 [[maybe_unused]] AVPixelFormat targetFormat,
151151 int frameIndex,
152152 AVCodecContext* codecContext) {
153- TORCH_CHECK (
154- tensor.is_cuda (),
155- " Frame tensor is not stored on GPU, but the GPU method convertTensorToAVFrame was called." );
156153 TORCH_CHECK (
157154 tensor.dim () == 3 && tensor.size (0 ) == 3 ,
158155 " Expected 3D RGB tensor (CHW format), got shape: " ,
159156 tensor.sizes ());
160157
161- // TODO-VideoEncoder: Unify AVFrame creation with CPU version of this method
162158 UniqueAVFrame avFrame (av_frame_alloc ());
163159 TORCH_CHECK (avFrame != nullptr , " Failed to allocate AVFrame" );
164160 int height = static_cast <int >(tensor.size (1 ));
165161 int width = static_cast <int >(tensor.size (2 ));
166162
163+ // TODO-VideoEncoder: Unify AVFrame creation with CPU version of this method
167164 avFrame->format = AV_PIX_FMT_CUDA;
168165 avFrame->height = height;
169166 avFrame->width = width;
0 commit comments