Skip to content

Commit 72717bd

Browse files
committed
refac
1 parent f83ada9 commit 72717bd

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,10 @@ void VideoDecoder::convertAVFrameToDecodedOutputOnCPU(
893893
// TODO: check shape of preAllocatedOutputTensor?
894894
tensor = preAllocatedOutputTensor;
895895
} else {
896-
tensor = allocateOutputTensorFromRawOutput(rawOutput);
896+
int width = streamInfo.options.width.value_or(frame->width);
897+
int height = streamInfo.options.height.value_or(frame->height);
898+
tensor = torch::empty(
899+
{height, width, 3}, torch::TensorOptions().dtype({torch::kUInt8}));
897900
}
898901

899902
rawOutput.data = tensor.data_ptr<uint8_t>();
@@ -920,16 +923,6 @@ void VideoDecoder::convertAVFrameToDecodedOutputOnCPU(
920923
}
921924
}
922925

923-
torch::Tensor VideoDecoder::allocateOutputTensorFromRawOutput(
924-
RawDecodedOutput& rawOutput) {
925-
AVFrame* frame = rawOutput.frame.get();
926-
StreamInfo& streamInfo = streams_[rawOutput.streamIndex];
927-
int width = streamInfo.options.width.value_or(frame->width);
928-
int height = streamInfo.options.height.value_or(frame->height);
929-
return torch::empty(
930-
{height, width, 3}, torch::TensorOptions().dtype({torch::kUInt8}));
931-
}
932-
933926
VideoDecoder::DecodedOutput VideoDecoder::getFrameDisplayedAtTimestampNoDemux(
934927
double seconds) {
935928
for (auto& [streamIndex, stream] : streams_) {
@@ -963,7 +956,7 @@ VideoDecoder::DecodedOutput VideoDecoder::getFrameDisplayedAtTimestampNoDemux(
963956
return seconds >= frameStartTime && seconds < frameEndTime;
964957
});
965958
// Convert the frame to tensor.
966-
auto preAllocatedOutputTensor = allocateOutputTensorFromRawOutput(rawOutput);
959+
auto preAllocatedOutputTensor = torch::empty({0});
967960
return convertAVFrameToDecodedOutput(rawOutput, preAllocatedOutputTensor);
968961
}
969962

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ class VideoDecoder {
374374
RawDecodedOutput& rawOutput,
375375
DecodedOutput& output,
376376
torch::Tensor& preAllocatedOutputTensor);
377-
torch::Tensor allocateOutputTensorFromRawOutput(RawDecodedOutput& rawOutput);
378377

379378
DecoderOptions options_;
380379
ContainerMetadata containerMetadata_;

0 commit comments

Comments
 (0)