Skip to content

Commit a322334

Browse files
authored
Align high-level decoding entry points names with Python (#473)
1 parent ad3049b commit a322334

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ void VideoDecoder::convertAVFrameToFrameOutputOnCPU(
10621062
}
10631063
}
10641064

1065-
VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAtTimestampNoDemux(
1065+
VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAtNoDemux(
10661066
double seconds) {
10671067
for (auto& [streamIndex, streamInfo] : streamInfos_) {
10681068
double frameStartTime =
@@ -1316,7 +1316,7 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesAtIndices(
13161316
return frameBatchOutput;
13171317
}
13181318

1319-
VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedByTimestamps(
1319+
VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedAt(
13201320
int streamIndex,
13211321
const std::vector<double>& timestamps) {
13221322
validateUserProvidedStreamIndex(streamIndex);
@@ -1385,7 +1385,7 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesInRange(
13851385
return frameBatchOutput;
13861386
}
13871387

1388-
VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedByTimestampInRange(
1388+
VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedInRange(
13891389
int streamIndex,
13901390
double startSeconds,
13911391
double stopSeconds) {

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class VideoDecoder {
219219
// duration of 1.0s, it will be visible in the timestamp range [5.0, 6.0).
220220
// i.e. it will be returned when this function is called with seconds=5.0 or
221221
// seconds=5.999, etc.
222-
FrameOutput getFramePlayedAtTimestampNoDemux(double seconds);
222+
FrameOutput getFramePlayedAtNoDemux(double seconds);
223223

224224
FrameOutput getFrameAtIndex(int streamIndex, int64_t frameIndex);
225225
// This is morally private but needs to be exposed for C++ tests. Once
@@ -236,7 +236,7 @@ class VideoDecoder {
236236
int streamIndex,
237237
const std::vector<int64_t>& frameIndices);
238238

239-
FrameBatchOutput getFramesPlayedByTimestamps(
239+
FrameBatchOutput getFramesPlayedAt(
240240
int streamIndex,
241241
const std::vector<double>& timestamps);
242242

@@ -265,7 +265,7 @@ class VideoDecoder {
265265
// Valid values for startSeconds and stopSeconds are:
266266
//
267267
// [minPtsSecondsFromScan, maxPtsSecondsFromScan)
268-
FrameBatchOutput getFramesPlayedByTimestampInRange(
268+
FrameBatchOutput getFramesPlayedInRange(
269269
int streamIndex,
270270
double startSeconds,
271271
double stopSeconds);

src/torchcodec/decoders/_core/VideoDecoderOps.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ OpsFrameOutput get_next_frame(at::Tensor& decoder) {
245245

246246
OpsFrameOutput get_frame_at_pts(at::Tensor& decoder, double seconds) {
247247
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
248-
auto result = videoDecoder->getFramePlayedAtTimestampNoDemux(seconds);
248+
auto result = videoDecoder->getFramePlayedAtNoDemux(seconds);
249249
return makeOpsFrameOutput(result);
250250
}
251251

@@ -287,8 +287,7 @@ OpsFrameBatchOutput get_frames_by_pts(
287287
at::ArrayRef<double> timestamps) {
288288
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
289289
std::vector<double> timestampsVec(timestamps.begin(), timestamps.end());
290-
auto result =
291-
videoDecoder->getFramesPlayedByTimestamps(stream_index, timestampsVec);
290+
auto result = videoDecoder->getFramesPlayedAt(stream_index, timestampsVec);
292291
return makeOpsFrameBatchOutput(result);
293292
}
294293

@@ -298,7 +297,7 @@ OpsFrameBatchOutput get_frames_by_pts_in_range(
298297
double start_seconds,
299298
double stop_seconds) {
300299
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
301-
auto result = videoDecoder->getFramesPlayedByTimestampInRange(
300+
auto result = videoDecoder->getFramesPlayedInRange(
302301
stream_index, start_seconds, stop_seconds);
303302
return makeOpsFrameBatchOutput(result);
304303
}

test/decoders/VideoDecoderTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,18 @@ TEST_P(VideoDecoderTest, GetsFramePlayedAtTimestamp) {
267267
std::unique_ptr<VideoDecoder> ourDecoder =
268268
createDecoderFromPath(path, GetParam());
269269
ourDecoder->addVideoStreamDecoder(-1);
270-
auto output = ourDecoder->getFramePlayedAtTimestampNoDemux(6.006);
270+
auto output = ourDecoder->getFramePlayedAtNoDemux(6.006);
271271
EXPECT_EQ(output.ptsSeconds, 6.006);
272272
// The frame's duration is 0.033367 according to ffprobe,
273273
// so the next frame is played at timestamp=6.039367.
274274
const double kNextFramePts = 6.039366666666667;
275275
// The frame that is played a microsecond before the next frame is still
276276
// the previous frame.
277-
output = ourDecoder->getFramePlayedAtTimestampNoDemux(kNextFramePts - 1e-6);
277+
output = ourDecoder->getFramePlayedAtNoDemux(kNextFramePts - 1e-6);
278278
EXPECT_EQ(output.ptsSeconds, 6.006);
279279
// The frame that is played at the exact pts of the frame is the next
280280
// frame.
281-
output = ourDecoder->getFramePlayedAtTimestampNoDemux(kNextFramePts);
281+
output = ourDecoder->getFramePlayedAtNoDemux(kNextFramePts);
282282
EXPECT_EQ(output.ptsSeconds, kNextFramePts);
283283

284284
// This is the timestamp of the last frame in this video.
@@ -288,8 +288,8 @@ TEST_P(VideoDecoderTest, GetsFramePlayedAtTimestamp) {
288288
kPtsOfLastFrameInVideoStream + kDurationOfLastFrameInVideoStream;
289289
// Sanity check: make sure duration is strictly positive.
290290
EXPECT_GT(kPtsPlusDurationOfLastFrame, kPtsOfLastFrameInVideoStream);
291-
output = ourDecoder->getFramePlayedAtTimestampNoDemux(
292-
kPtsPlusDurationOfLastFrame - 1e-6);
291+
output =
292+
ourDecoder->getFramePlayedAtNoDemux(kPtsPlusDurationOfLastFrame - 1e-6);
293293
EXPECT_EQ(output.ptsSeconds, kPtsOfLastFrameInVideoStream);
294294
}
295295

0 commit comments

Comments
 (0)