@@ -362,7 +362,9 @@ std::string CudaDeviceInterface::getDetails() {
362362 (usingCPUFallback_ ? " CPU fallback." : " NVDEC." );
363363}
364364
365- // Below are methods for video encoding:
365+ // --------------------------------------------------------------------------
366+ // Below are methods exclusive to video encoding:
367+ // --------------------------------------------------------------------------
366368namespace {
367369// RGB to NV12 color conversion matrix for BT.601 limited range.
368370// NPP ColorTwist function used below expects the limited range
@@ -378,7 +380,6 @@ const Npp32f defaultLimitedRangeRgbToNv12[3][4] = {
378380
379381std::optional<UniqueAVFrame> CudaDeviceInterface::convertTensorToAVFrame (
380382 const torch::Tensor& tensor,
381- [[maybe_unused]] AVPixelFormat targetFormat,
382383 int frameIndex,
383384 AVCodecContext* codecContext) {
384385 TORCH_CHECK (
@@ -447,6 +448,9 @@ std::optional<UniqueAVFrame> CudaDeviceInterface::convertTensorToAVFrame(
447448 return avFrame;
448449}
449450
451+ // Allocates and initializes AVHWFramesContext, and sets pixel format fields
452+ // to enable encoding with CUDA device. The hw_frames_ctx field is needed by
453+ // FFmpeg to allocate frames on GPU's memory.
450454void CudaDeviceInterface::setupHardwareFrameContext (
451455 AVCodecContext* codecContext) {
452456 TORCH_CHECK (codecContext != nullptr , " codecContext is null" );
@@ -458,10 +462,10 @@ void CudaDeviceInterface::setupHardwareFrameContext(
458462 hwFramesCtxRef != nullptr ,
459463 " Failed to allocate hardware frames context for codec" );
460464
461- // Always set pixel formats to options that support CUDA encoding.
462- // TODO-VideoEncoder: Enable user set pixel formats to be set and properly
463- // handled with NPP functions below
465+ // TODO-VideoEncoder: Enable user set pixel formats to be set
466+ // (outPixelFormat_) and handled with the appropriate NPP function
464467 codecContext->sw_pix_fmt = AV_PIX_FMT_NV12;
468+ // Always set pixel format to support CUDA encoding.
465469 codecContext->pix_fmt = AV_PIX_FMT_CUDA;
466470
467471 AVHWFramesContext* hwFramesCtx =
@@ -479,7 +483,6 @@ void CudaDeviceInterface::setupHardwareFrameContext(
479483 " Failed to initialize CUDA frames context for codec: " ,
480484 getFFMPEGErrorStringFromErrorCode (ret));
481485 }
482-
483486 codecContext->hw_frames_ctx = hwFramesCtxRef;
484487}
485488
0 commit comments