(self, tensor)
| 401 | # docs_tag: begin_imp_nvvideoencoder |
| 402 | |
| 403 | def encode_from_tensor(self, tensor): |
| 404 | |
| 405 | # Create a CUDA array interface object wit 2 planes one for luma and CrCb for NV12 |
| 406 | objCAI = [] |
| 407 | # Need to compute the address of the Y plane and the interleaved chroma plane |
| 408 | data = ( |
| 409 | tensor.storage().data_ptr() |
| 410 | + tensor.storage_offset() * tensor.element_size() |
| 411 | ) |
| 412 | objCAI.append( |
| 413 | AppCAI( |
| 414 | (self.avstream.height, self.avstream.width, 1), |
| 415 | (self.avstream.width, 1, 1), |
| 416 | "|u1", |
| 417 | data, |
| 418 | ) |
| 419 | ) |
| 420 | chromaAlloc = int(data) + self.avstream.width * self.avstream.height |
| 421 | objCAI.append( |
| 422 | AppCAI( |
| 423 | (int(self.avstream.height / 2), int(self.avstream.width / 2), 2), |
| 424 | (self.avstream.width, 2, 1), |
| 425 | "|u1", |
| 426 | chromaAlloc, |
| 427 | ) |
| 428 | ) |
| 429 | # Encode the frame takes CUDA array interface object as input |
| 430 | self.encoded_frame = self.nvEnc.Encode(objCAI) |
| 431 | self.write_frame( |
| 432 | self.encoded_frame, |
| 433 | self.pts_time, |
| 434 | self.fps, |
| 435 | self.avstream, |
| 436 | self.container, |
| 437 | ) |
| 438 | self.pts_time += self.delta_t |
| 439 | |
| 440 | # docs_tag: end_imp_nvvideoencoder |
| 441 |
no test coverage detected