MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / __call__

Method __call__

bench/python/nvcodec_utils.py:83–144  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

81
82 # docs_tag: begin_call_videobatchdecoder_pyvideocodec
83 def __call__(self):
84 self.cvcuda_perf.push_range("decoder.pyVideoCodec")
85
86 # docs_tag: begin_alloc_videobatchdecoder_pyvideocodec
87 # Check if we need to allocate the decoder for its first use.
88 if self.decoder is None:
89 self.decoder = nvVideoDecoder(
90 self.input_path, self.device_id, self.cuda_ctx, self.cuda_stream
91 )
92 # docs_tag: end_alloc_videobatchdecoder_pyvideocodec
93
94 # docs_tag: begin_decode_videobatchdecoder_pyvideocodec
95 # Get the NHWC YUV tensor from the decoder
96 cvcuda_YUVtensor = self.decoder.get_next_frames(self.batch_size)
97
98 # Check if we are done decoding
99 if cvcuda_YUVtensor is None:
100 self.cvcuda_perf.pop_range()
101 return None
102
103 # Check the code for the color conversion based in the pixel format
104 cvcuda_code = pixel_format_to_cvcuda_code.get(self.decoder.pixelFormat)
105 if cvcuda_code is None:
106 raise ValueError(f"Unsupported pixel format: {self.decoder.pixelFormat}")
107
108 # Check layout to make sure it is what we expected
109 if cvcuda_YUVtensor.layout != "NHWC":
110 raise ValueError("Unexpected tensor layout, NHWC expected.")
111
112 # this may be different than batch size since last frames may not be a multiple of batch size
113 actual_batch_size = cvcuda_YUVtensor.shape[0]
114
115 # docs_tag: end_decode_videobatchdecoder_pyvideocodec
116
117 # docs_tag: begin_convert_videobatchdecoder_pyvideocodec
118 # Create a CVCUDA tensor for color conversion YUV->RGB
119 # Allocate only for the first time or for the last batch.
120 if not self.cvcuda_RGBtensor_batch or actual_batch_size != self.batch_size:
121 self.cvcuda_RGBtensor_batch = cvcuda.Tensor(
122 (actual_batch_size, self.decoder.h, self.decoder.w, 3),
123 cvcuda.Type.U8,
124 cvcuda.TensorLayout.NHWC,
125 )
126
127 # Convert from YUV to RGB. Conversion code is based on the pixel format.
128 cvcuda.cvtcolor_into(self.cvcuda_RGBtensor_batch, cvcuda_YUVtensor, cvcuda_code)
129
130 self.total_decoded += actual_batch_size
131 # docs_tag: end_convert_videobatchdecoder_pyvideocodec
132
133 # docs_tag: begin_batch_videobatchdecoder_pyvideocodec
134 # Create a batch instance and set its properties.
135 batch = Batch(
136 batch_idx=self.batch_idx,
137 data=self.cvcuda_RGBtensor_batch,
138 fileinfo=self.input_path,
139 )
140 self.batch_idx += 1

Callers

nothing calls this directly

Calls 7

BatchClass · 0.90
nvVideoDecoderClass · 0.85
push_rangeMethod · 0.80
get_next_framesMethod · 0.80
pop_rangeMethod · 0.80
getMethod · 0.45
TensorMethod · 0.45

Tested by

no test coverage detected