Skip to content

Commit e0af147

Browse files
committed
Revert "[torchcodec] Add a NoDemux suffix to functions that do not demux (#147)"
This reverts commit 2d02b85.
1 parent 0a06c3d commit e0af147

File tree

5 files changed

+35
-37
lines changed

5 files changed

+35
-37
lines changed

benchmarks/decoders/BenchmarkDecodersMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void runNDecodeIterations(
6363
decoder->addVideoStreamDecoder(-1);
6464
for (double pts : ptsList) {
6565
decoder->setCursorPtsInSeconds(pts);
66-
torch::Tensor tensor = decoder->getNextDecodedOutputNoDemux().frame;
66+
torch::Tensor tensor = decoder->getNextDecodedOutput().frame;
6767
}
6868
if (i + 1 == warmupIterations) {
6969
start = std::chrono::high_resolution_clock::now();
@@ -95,7 +95,7 @@ void runNdecodeIterationsGrabbingConsecutiveFrames(
9595
VideoDecoder::createFromFilePath(videoPath);
9696
decoder->addVideoStreamDecoder(-1);
9797
for (int j = 0; j < consecutiveFrameCount; ++j) {
98-
torch::Tensor tensor = decoder->getNextDecodedOutputNoDemux().frame;
98+
torch::Tensor tensor = decoder->getNextDecodedOutput().frame;
9999
}
100100
if (i + 1 == warmupIterations) {
101101
start = std::chrono::high_resolution_clock::now();

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ VideoDecoder::DecodedOutput VideoDecoder::getDecodedOutputWithFilter(
771771
if (activeStreamIndices_.size() == 0) {
772772
throw std::runtime_error("No active streams configured.");
773773
}
774-
VLOG(9) << "Starting getNextDecodedOutputNoDemux()";
774+
VLOG(9) << "Starting getNextDecodedOutput()";
775775
resetDecodeStats();
776776
if (maybeDesiredPts_.has_value()) {
777777
VLOG(9) << "maybeDesiredPts_=" << *maybeDesiredPts_;
@@ -932,7 +932,7 @@ VideoDecoder::DecodedOutput VideoDecoder::convertAVFrameToDecodedOutput(
932932
return output;
933933
}
934934

935-
VideoDecoder::DecodedOutput VideoDecoder::getFrameDisplayedAtTimestampNoDemux(
935+
VideoDecoder::DecodedOutput VideoDecoder::getFrameDisplayedAtTimestamp(
936936
double seconds) {
937937
for (auto& [streamIndex, stream] : streams_) {
938938
double frameStartTime = ptsToSeconds(stream.currentPts, stream.timeBase);
@@ -1007,7 +1007,7 @@ VideoDecoder::DecodedOutput VideoDecoder::getFrameAtIndex(
10071007

10081008
int64_t pts = stream.allFrames[frameIndex].pts;
10091009
setCursorPtsInSeconds(ptsToSeconds(pts, stream.timeBase));
1010-
return getNextDecodedOutputNoDemux();
1010+
return getNextDecodedOutput();
10111011
}
10121012

10131013
VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesAtIndexes(
@@ -1160,7 +1160,7 @@ VideoDecoder::getFramesDisplayedByTimestampInRange(
11601160
return output;
11611161
}
11621162

1163-
VideoDecoder::DecodedOutput VideoDecoder::getNextDecodedOutputNoDemux() {
1163+
VideoDecoder::DecodedOutput VideoDecoder::getNextDecodedOutput() {
11641164
return getDecodedOutputWithFilter(
11651165
[this](int frameStreamIndex, AVFrame* frame) {
11661166
StreamInfo& activeStream = streams_[frameStreamIndex];

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ class VideoDecoder {
153153

154154
// ---- SINGLE FRAME SEEK AND DECODING API ----
155155
// Places the cursor at the first frame on or after the position in seconds.
156-
// Calling getNextDecodedOutputNoDemux() will return the first frame at or
157-
// after this position.
156+
// Calling getNextFrameAsTensor() will return the first frame at or after this
157+
// position.
158158
void setCursorPtsInSeconds(double seconds);
159159
struct DecodedOutput {
160160
// The actual decoded output as a Tensor.
@@ -180,14 +180,13 @@ class VideoDecoder {
180180
};
181181
// Decodes the frame where the current cursor position is. It also advances
182182
// the cursor to the next frame.
183-
DecodedOutput getNextDecodedOutputNoDemux();
184-
// Decodes the first frame in any added stream that is visible at a given
185-
// timestamp. Frames in the video have a presentation timestamp and a
186-
// duration. For example, if a frame has presentation timestamp of 5.0s and a
187-
// duration of 1.0s, it will be visible in the timestamp range [5.0, 6.0).
188-
// i.e. it will be returned when this function is called with seconds=5.0 or
189-
// seconds=5.999, etc.
190-
DecodedOutput getFrameDisplayedAtTimestampNoDemux(double seconds);
183+
DecodedOutput getNextDecodedOutput();
184+
// Decodes the frame that is visible at a given timestamp. Frames in the video
185+
// have a presentation timestamp and a duration. For example, if a frame has
186+
// presentation timestamp of 5.0s and a duration of 1.0s, it will be visible
187+
// in the timestamp range [5.0, 6.0). i.e. it will be returned when this
188+
// function is called with seconds=5.0 or seconds=5.999, etc.
189+
DecodedOutput getFrameDisplayedAtTimestamp(double seconds);
191190
DecodedOutput getFrameAtIndex(int streamIndex, int64_t frameIndex);
192191
struct BatchDecodedOutput {
193192
torch::Tensor frames;

src/torchcodec/decoders/_core/VideoDecoderOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ OpsDecodedOutput get_next_frame(at::Tensor& decoder) {
147147
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
148148
VideoDecoder::DecodedOutput result;
149149
try {
150-
result = videoDecoder->getNextDecodedOutputNoDemux();
150+
result = videoDecoder->getNextDecodedOutput();
151151
} catch (const VideoDecoder::EndOfFileException& e) {
152152
throw pybind11::stop_iteration(e.what());
153153
}
@@ -161,7 +161,7 @@ OpsDecodedOutput get_next_frame(at::Tensor& decoder) {
161161

162162
OpsDecodedOutput get_frame_at_pts(at::Tensor& decoder, double seconds) {
163163
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
164-
auto result = videoDecoder->getFrameDisplayedAtTimestampNoDemux(seconds);
164+
auto result = videoDecoder->getFrameDisplayedAtTimestamp(seconds);
165165
return makeOpsDecodedOutput(result);
166166
}
167167

test/decoders/VideoDecoderTest.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ TEST(VideoDecoderTest, RespectsWidthAndHeightFromOptions) {
152152
streamOptions.width = 100;
153153
streamOptions.height = 120;
154154
decoder->addVideoStreamDecoder(-1, streamOptions);
155-
torch::Tensor tensor = decoder->getNextDecodedOutputNoDemux().frame;
155+
torch::Tensor tensor = decoder->getNextDecodedOutput().frame;
156156
EXPECT_EQ(tensor.sizes(), std::vector<long>({3, 120, 100}));
157157
}
158158

@@ -163,7 +163,7 @@ TEST(VideoDecoderTest, RespectsOutputTensorDimensionOrderFromOptions) {
163163
VideoDecoder::VideoStreamDecoderOptions streamOptions;
164164
streamOptions.dimensionOrder = "NHWC";
165165
decoder->addVideoStreamDecoder(-1, streamOptions);
166-
torch::Tensor tensor = decoder->getNextDecodedOutputNoDemux().frame;
166+
torch::Tensor tensor = decoder->getNextDecodedOutput().frame;
167167
EXPECT_EQ(tensor.sizes(), std::vector<long>({270, 480, 3}));
168168
}
169169

@@ -172,12 +172,12 @@ TEST_P(VideoDecoderTest, ReturnsFirstTwoFramesOfVideo) {
172172
std::unique_ptr<VideoDecoder> ourDecoder =
173173
createDecoderFromPath(path, GetParam());
174174
ourDecoder->addVideoStreamDecoder(-1);
175-
auto output = ourDecoder->getNextDecodedOutputNoDemux();
175+
auto output = ourDecoder->getNextDecodedOutput();
176176
torch::Tensor tensor0FromOurDecoder = output.frame;
177177
EXPECT_EQ(tensor0FromOurDecoder.sizes(), std::vector<long>({3, 270, 480}));
178178
EXPECT_EQ(output.ptsSeconds, 0.0);
179179
EXPECT_EQ(output.pts, 0);
180-
output = ourDecoder->getNextDecodedOutputNoDemux();
180+
output = ourDecoder->getNextDecodedOutput();
181181
torch::Tensor tensor1FromOurDecoder = output.frame;
182182
EXPECT_EQ(tensor1FromOurDecoder.sizes(), std::vector<long>({3, 270, 480}));
183183
EXPECT_EQ(output.ptsSeconds, 1'001. / 30'000);
@@ -219,12 +219,12 @@ TEST(GPUVideoDecoderTest, ReturnsFirstTwoFramesOfVideo) {
219219
ASSERT_TRUE(streamOptions.device.is_cuda());
220220
ASSERT_EQ(streamOptions.device.type(), torch::DeviceType::CUDA);
221221
ourDecoder->addVideoStreamDecoder(-1, streamOptions);
222-
auto output = ourDecoder->getNextDecodedOutputNoDemux();
222+
auto output = ourDecoder->getNextDecodedOutput();
223223
torch::Tensor tensor1FromOurDecoder = output.frame;
224224
EXPECT_EQ(tensor1FromOurDecoder.sizes(), std::vector<long>({3, 270, 480}));
225225
EXPECT_EQ(output.ptsSeconds, 0.0);
226226
EXPECT_EQ(output.pts, 0);
227-
output = ourDecoder->getNextDecodedOutputNoDemux();
227+
output = ourDecoder->getNextDecodedOutput();
228228
torch::Tensor tensor2FromOurDecoder = output.frame;
229229
EXPECT_EQ(tensor2FromOurDecoder.sizes(), std::vector<long>({3, 270, 480}));
230230
EXPECT_EQ(output.ptsSeconds, 1'001. / 30'000);
@@ -306,31 +306,30 @@ TEST_P(VideoDecoderTest, SeeksCloseToEof) {
306306
createDecoderFromPath(path, GetParam());
307307
ourDecoder->addVideoStreamDecoder(-1);
308308
ourDecoder->setCursorPtsInSeconds(388388. / 30'000);
309-
auto output = ourDecoder->getNextDecodedOutputNoDemux();
309+
auto output = ourDecoder->getNextDecodedOutput();
310310
EXPECT_EQ(output.ptsSeconds, 388'388. / 30'000);
311-
output = ourDecoder->getNextDecodedOutputNoDemux();
311+
output = ourDecoder->getNextDecodedOutput();
312312
EXPECT_EQ(output.ptsSeconds, 389'389. / 30'000);
313-
EXPECT_THROW(ourDecoder->getNextDecodedOutputNoDemux(), std::exception);
313+
EXPECT_THROW(ourDecoder->getNextDecodedOutput(), std::exception);
314314
}
315315

316316
TEST_P(VideoDecoderTest, GetsFrameDisplayedAtTimestamp) {
317317
std::string path = getResourcePath("nasa_13013.mp4");
318318
std::unique_ptr<VideoDecoder> ourDecoder =
319319
createDecoderFromPath(path, GetParam());
320320
ourDecoder->addVideoStreamDecoder(-1);
321-
auto output = ourDecoder->getFrameDisplayedAtTimestampNoDemux(6.006);
321+
auto output = ourDecoder->getFrameDisplayedAtTimestamp(6.006);
322322
EXPECT_EQ(output.ptsSeconds, 6.006);
323323
// The frame's duration is 0.033367 according to ffprobe,
324324
// so the next frame is displayed at timestamp=6.039367.
325325
const double kNextFramePts = 6.039366666666667;
326326
// The frame that is displayed a microsecond before the next frame is still
327327
// the previous frame.
328-
output =
329-
ourDecoder->getFrameDisplayedAtTimestampNoDemux(kNextFramePts - 1e-6);
328+
output = ourDecoder->getFrameDisplayedAtTimestamp(kNextFramePts - 1e-6);
330329
EXPECT_EQ(output.ptsSeconds, 6.006);
331330
// The frame that is displayed at the exact pts of the frame is the next
332331
// frame.
333-
output = ourDecoder->getFrameDisplayedAtTimestampNoDemux(kNextFramePts);
332+
output = ourDecoder->getFrameDisplayedAtTimestamp(kNextFramePts);
334333
EXPECT_EQ(output.ptsSeconds, kNextFramePts);
335334

336335
// This is the timestamp of the last frame in this video.
@@ -340,7 +339,7 @@ TEST_P(VideoDecoderTest, GetsFrameDisplayedAtTimestamp) {
340339
kPtsOfLastFrameInVideoStream + kDurationOfLastFrameInVideoStream;
341340
// Sanity check: make sure duration is strictly positive.
342341
EXPECT_GT(kPtsPlusDurationOfLastFrame, kPtsOfLastFrameInVideoStream);
343-
output = ourDecoder->getFrameDisplayedAtTimestampNoDemux(
342+
output = ourDecoder->getFrameDisplayedAtTimestamp(
344343
kPtsPlusDurationOfLastFrame - 1e-6);
345344
EXPECT_EQ(output.ptsSeconds, kPtsOfLastFrameInVideoStream);
346345
}
@@ -351,7 +350,7 @@ TEST_P(VideoDecoderTest, SeeksToFrameWithSpecificPts) {
351350
createDecoderFromPath(path, GetParam());
352351
ourDecoder->addVideoStreamDecoder(-1);
353352
ourDecoder->setCursorPtsInSeconds(6.0);
354-
auto output = ourDecoder->getNextDecodedOutputNoDemux();
353+
auto output = ourDecoder->getNextDecodedOutput();
355354
torch::Tensor tensor6FromOurDecoder = output.frame;
356355
EXPECT_EQ(output.ptsSeconds, 180'180. / 30'000);
357356
torch::Tensor tensor6FromFFMPEG =
@@ -367,7 +366,7 @@ TEST_P(VideoDecoderTest, SeeksToFrameWithSpecificPts) {
367366
EXPECT_GT(ourDecoder->getDecodeStats().numPacketsSentToDecoder, 180);
368367

369368
ourDecoder->setCursorPtsInSeconds(6.1);
370-
output = ourDecoder->getNextDecodedOutputNoDemux();
369+
output = ourDecoder->getNextDecodedOutput();
371370
torch::Tensor tensor61FromOurDecoder = output.frame;
372371
EXPECT_EQ(output.ptsSeconds, 183'183. / 30'000);
373372
torch::Tensor tensor61FromFFMPEG =
@@ -387,7 +386,7 @@ TEST_P(VideoDecoderTest, SeeksToFrameWithSpecificPts) {
387386
EXPECT_LT(ourDecoder->getDecodeStats().numPacketsSentToDecoder, 10);
388387

389388
ourDecoder->setCursorPtsInSeconds(10.0);
390-
output = ourDecoder->getNextDecodedOutputNoDemux();
389+
output = ourDecoder->getNextDecodedOutput();
391390
torch::Tensor tensor10FromOurDecoder = output.frame;
392391
EXPECT_EQ(output.ptsSeconds, 300'300. / 30'000);
393392
torch::Tensor tensor10FromFFMPEG =
@@ -404,7 +403,7 @@ TEST_P(VideoDecoderTest, SeeksToFrameWithSpecificPts) {
404403
EXPECT_GT(ourDecoder->getDecodeStats().numPacketsSentToDecoder, 60);
405404

406405
ourDecoder->setCursorPtsInSeconds(6.0);
407-
output = ourDecoder->getNextDecodedOutputNoDemux();
406+
output = ourDecoder->getNextDecodedOutput();
408407
tensor6FromOurDecoder = output.frame;
409408
EXPECT_EQ(output.ptsSeconds, 180'180. / 30'000);
410409
EXPECT_TRUE(torch::equal(tensor6FromOurDecoder, tensor6FromFFMPEG));
@@ -419,7 +418,7 @@ TEST_P(VideoDecoderTest, SeeksToFrameWithSpecificPts) {
419418

420419
constexpr double kPtsOfLastFrameInVideoStream = 389'389. / 30'000; // ~12.9
421420
ourDecoder->setCursorPtsInSeconds(kPtsOfLastFrameInVideoStream);
422-
output = ourDecoder->getNextDecodedOutputNoDemux();
421+
output = ourDecoder->getNextDecodedOutput();
423422
torch::Tensor tensor7FromOurDecoder = output.frame;
424423
EXPECT_EQ(output.ptsSeconds, 389'389. / 30'000);
425424
torch::Tensor tensor7FromFFMPEG =

0 commit comments

Comments
 (0)