| 186 | |
| 187 | # frame iterator |
| 188 | def generate_decoded_frames(self): |
| 189 | for packet in self.nvDemux: |
| 190 | for decodedFrame in self.nvDec.Decode(packet): |
| 191 | cvcudaTensor = cvcuda.as_tensor( |
| 192 | cvcuda.as_image(decodedFrame.nvcv_image(), cvcuda.Format.U8) |
| 193 | ) |
| 194 | if cvcudaTensor.layout == "NCHW": |
| 195 | # This will re-format the NCHW tensor to a NHWC tensor which will create |
| 196 | # a copy in the CUDA device decoded frame will go out of scope and the |
| 197 | # backing memory will be available by the decoder. |
| 198 | yield cvcuda.reformat(cvcudaTensor, "NHWC") |
| 199 | else: |
| 200 | raise ValueError("Unexpected tensor layout, NCHW expected.") |
| 201 | |
| 202 | def get_next_frames(self, N): |
| 203 | decoded_frames = list(itertools.islice(self.generate_decoded_frames(), N)) |