Skip to content

Commit 7cf3a3e

Browse files
committed
Handle getNextFrameNoDemux
1 parent 649401e commit 7cf3a3e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ VideoDecoder::RawDecodedOutput VideoDecoder::getDecodedOutputWithFilter(
850850

851851
VideoDecoder::DecodedOutput VideoDecoder::convertAVFrameToDecodedOutput(
852852
VideoDecoder::RawDecodedOutput& rawOutput,
853-
std::optional<torch::Tensor> preAllocatedOutputTensor) {
853+
torch::Tensor preAllocatedOutputTensor) {
854854
// Convert the frame to tensor.
855855
DecodedOutput output;
856856
int streamIndex = rawOutput.streamIndex;
@@ -986,7 +986,8 @@ VideoDecoder::DecodedOutput VideoDecoder::getFramePlayedAtTimestampNoDemux(
986986
auto height = options.height.value_or(*metadata.height);
987987
auto width = options.width.value_or(*metadata.width);
988988
auto preAllocatedOutputTensor = makeEmptyHWCTensor(height, width);
989-
auto output = convertAVFrameToDecodedOutput(rawOutput, preAllocatedOutputTensor);
989+
auto output =
990+
convertAVFrameToDecodedOutput(rawOutput, preAllocatedOutputTensor);
990991
output.frame = MaybePermuteHWC2CHW(output.streamIndex, output.frame);
991992
return output;
992993
}
@@ -1288,13 +1289,21 @@ VideoDecoder::RawDecodedOutput VideoDecoder::getNextRawDecodedOutputNoDemux() {
12881289
}
12891290

12901291
VideoDecoder::DecodedOutput VideoDecoder::getNextFrameNoDemux() {
1291-
auto output = getNextFrameOutputNoDemuxInternal();
1292+
auto rawOutput = getNextRawDecodedOutputNoDemux();
1293+
auto streamIndex = rawOutput.streamIndex;
1294+
auto metadata = containerMetadata_.streams[streamIndex];
1295+
auto options = streams_[streamIndex].options;
1296+
auto height = options.height.value_or(*metadata.height);
1297+
auto width = options.width.value_or(*metadata.width);
1298+
auto preAllocatedOutputTensor = makeEmptyHWCTensor(height, width);
1299+
auto output =
1300+
convertAVFrameToDecodedOutput(rawOutput, preAllocatedOutputTensor);
12921301
output.frame = MaybePermuteHWC2CHW(output.streamIndex, output.frame);
12931302
return output;
12941303
}
12951304

12961305
VideoDecoder::DecodedOutput VideoDecoder::getNextFrameOutputNoDemuxInternal(
1297-
std::optional<torch::Tensor> preAllocatedOutputTensor) {
1306+
torch::Tensor preAllocatedOutputTensor) {
12981307
auto rawOutput = getNextRawDecodedOutputNoDemux();
12991308
return convertAVFrameToDecodedOutput(rawOutput, preAllocatedOutputTensor);
13001309
}

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,14 @@ class VideoDecoder {
386386
void convertFrameToBufferUsingSwsScale(RawDecodedOutput& rawOutput);
387387
DecodedOutput convertAVFrameToDecodedOutput(
388388
RawDecodedOutput& rawOutput,
389-
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
389+
torch::Tensor preAllocatedOutputTensor);
390390
void convertAVFrameToDecodedOutputOnCPU(
391391
RawDecodedOutput& rawOutput,
392392
DecodedOutput& output,
393393
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
394394

395395
DecodedOutput getNextFrameOutputNoDemuxInternal(
396-
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
396+
torch::Tensor preAllocatedOutputTensor);
397397

398398
DecoderOptions options_;
399399
ContainerMetadata containerMetadata_;

0 commit comments

Comments
 (0)