Skip to content

Commit fedfeba

Browse files
authored
displayed -> played (#306)
1 parent f3814b7 commit fedfeba

File tree

12 files changed

+78
-79
lines changed

12 files changed

+78
-79
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ decoder.get_frames_in_range(start=10, stop=30, step=5)
7272
# duration_seconds: tensor([0.0400, 0.0400, 0.0400, 0.0400])
7373

7474
# Time-based indexing with PTS and duration info
75-
decoder.get_frame_displayed_at(pts_seconds=2)
75+
decoder.get_frame_played_at(pts_seconds=2)
7676
# Frame:
7777
# data (shape): torch.Size([3, 400, 640])
7878
# pts_seconds: 2.0

docs/source/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Glossary
44
.. glossary::
55

66
pts
7-
Presentation Time Stamp. The time at which a frame should be displayed.
7+
Presentation Time Stamp. The time at which a frame should be played.
88
In TorchCodec, pts are expressed in seconds.
99

1010
best stream

examples/basic_example.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,24 @@ def plot(frames: torch.Tensor, title : Optional[str] = None):
150150
# -------------------------
151151
#
152152
# So far, we have retrieved frames based on their index. We can also retrieve
153-
# frames based on *when* they are displayed with
154-
# :meth:`~torchcodec.decoders.VideoDecoder.get_frame_displayed_at` and
155-
# :meth:`~torchcodec.decoders.VideoDecoder.get_frames_displayed_in_range`, which
153+
# frames based on *when* they are played with
154+
# :meth:`~torchcodec.decoders.VideoDecoder.get_frame_played_at` and
155+
# :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`, which
156156
# also returns :class:`~torchcodec.Frame` and :class:`~torchcodec.FrameBatch`
157157
# respectively.
158158

159-
frame_at_2_seconds = decoder.get_frame_displayed_at(seconds=2)
159+
frame_at_2_seconds = decoder.get_frame_played_at(seconds=2)
160160
print(f"{type(frame_at_2_seconds) = }")
161161
print(frame_at_2_seconds)
162162

163163
# %%
164-
first_two_seconds = decoder.get_frames_displayed_in_range(
164+
first_two_seconds = decoder.get_frames_played_in_range(
165165
start_seconds=0,
166166
stop_seconds=2,
167167
)
168168
print(f"{type(first_two_seconds) = }")
169169
print(first_two_seconds)
170170

171171
# %%
172-
plot(frame_at_2_seconds.data, "Frame displayed at 2 seconds")
173-
plot(first_two_seconds.data, "Frames displayed during [0, 2) seconds")
172+
plot(frame_at_2_seconds.data, "Frame played at 2 seconds")
173+
plot(first_two_seconds.data, "Frames played during [0, 2) seconds")

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ void VideoDecoder::convertAVFrameToDecodedOutputOnCPU(
930930
}
931931
}
932932

933-
VideoDecoder::DecodedOutput VideoDecoder::getFrameDisplayedAtTimestampNoDemux(
933+
VideoDecoder::DecodedOutput VideoDecoder::getFramePlayedAtTimestampNoDemux(
934934
double seconds) {
935935
for (auto& [streamIndex, stream] : streams_) {
936936
double frameStartTime = ptsToSeconds(stream.currentPts, stream.timeBase);
@@ -1073,13 +1073,13 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesAtIndices(
10731073
return output;
10741074
}
10751075

1076-
VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesDisplayedByTimestamps(
1076+
VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesPlayedByTimestamps(
10771077
int streamIndex,
10781078
const std::vector<double>& timestamps) {
10791079
validateUserProvidedStreamIndex(streamIndex);
1080-
validateScannedAllStreams("getFramesDisplayedByTimestamps");
1080+
validateScannedAllStreams("getFramesPlayedByTimestamps");
10811081

1082-
// The frame displayed at timestamp t and the one displayed at timestamp `t +
1082+
// The frame played at timestamp t and the one played at timestamp `t +
10831083
// eps` are probably the same frame, with the same index. The easiest way to
10841084
// avoid decoding that unique frame twice is to convert the input timestamps
10851085
// to indices, and leverage the de-duplication logic of getFramesAtIndices.
@@ -1151,12 +1151,12 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesInRange(
11511151
}
11521152

11531153
VideoDecoder::BatchDecodedOutput
1154-
VideoDecoder::getFramesDisplayedByTimestampInRange(
1154+
VideoDecoder::getFramesPlayedByTimestampInRange(
11551155
int streamIndex,
11561156
double startSeconds,
11571157
double stopSeconds) {
11581158
validateUserProvidedStreamIndex(streamIndex);
1159-
validateScannedAllStreams("getFramesDisplayedByTimestampInRange");
1159+
validateScannedAllStreams("getFramesPlayedByTimestampInRange");
11601160

11611161
const auto& streamMetadata = containerMetadata_.streams[streamIndex];
11621162
double minSeconds = streamMetadata.minPtsSecondsFromScan.value();
@@ -1207,7 +1207,7 @@ VideoDecoder::getFramesDisplayedByTimestampInRange(
12071207
// abstract player displays frames starting at the pts for that frame until
12081208
// the pts for the next frame. There are two consequences:
12091209
//
1210-
// 1. We ignore the duration for a frame. A frame is displayed until the
1210+
// 1. We ignore the duration for a frame. A frame is played until the
12111211
// next frame replaces it. This model is robust to durations being 0 or
12121212
// incorrect; our source of truth is the pts for frames. If duration is
12131213
// accurate, the nextPts for a frame would be equivalent to pts + duration.

src/torchcodec/decoders/_core/VideoDecoder.h

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

227227
DecodedOutput getFrameAtIndex(
228228
int streamIndex,
@@ -244,7 +244,7 @@ class VideoDecoder {
244244
int streamIndex,
245245
const std::vector<int64_t>& frameIndices);
246246

247-
BatchDecodedOutput getFramesDisplayedByTimestamps(
247+
BatchDecodedOutput getFramesPlayedByTimestamps(
248248
int streamIndex,
249249
const std::vector<double>& timestamps);
250250

@@ -265,15 +265,15 @@ class VideoDecoder {
265265
// frame. Otherwise, the moment in time immediately before stopSeconds is in
266266
// the range, and that time maps to the same frame as stopSeconds.
267267
//
268-
// The frames returned are the frames that would be displayed by our abstract
268+
// The frames returned are the frames that would be played by our abstract
269269
// player. Our abstract player displays frames based on pts only. It displays
270270
// frame i starting at the pts for frame i, and stops at the pts for frame
271271
// i+1. This model ignores a frame's reported duration.
272272
//
273273
// Valid values for startSeconds and stopSeconds are:
274274
//
275275
// [minPtsSecondsFromScan, maxPtsSecondsFromScan)
276-
BatchDecodedOutput getFramesDisplayedByTimestampInRange(
276+
BatchDecodedOutput getFramesPlayedByTimestampInRange(
277277
int streamIndex,
278278
double startSeconds,
279279
double stopSeconds);

src/torchcodec/decoders/_core/VideoDecoderOps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ OpsDecodedOutput get_next_frame(at::Tensor& decoder) {
207207

208208
OpsDecodedOutput get_frame_at_pts(at::Tensor& decoder, double seconds) {
209209
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
210-
auto result = videoDecoder->getFrameDisplayedAtTimestampNoDemux(seconds);
210+
auto result = videoDecoder->getFramePlayedAtTimestampNoDemux(seconds);
211211
return makeOpsDecodedOutput(result);
212212
}
213213

@@ -249,7 +249,7 @@ OpsBatchDecodedOutput get_frames_by_pts(
249249
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
250250
std::vector<double> timestampsVec(timestamps.begin(), timestamps.end());
251251
auto result =
252-
videoDecoder->getFramesDisplayedByTimestamps(stream_index, timestampsVec);
252+
videoDecoder->getFramesPlayedByTimestamps(stream_index, timestampsVec);
253253
return makeOpsBatchDecodedOutput(result);
254254
}
255255

@@ -259,7 +259,7 @@ OpsBatchDecodedOutput get_frames_by_pts_in_range(
259259
double start_seconds,
260260
double stop_seconds) {
261261
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
262-
auto result = videoDecoder->getFramesDisplayedByTimestampInRange(
262+
auto result = videoDecoder->getFramesPlayedByTimestampInRange(
263263
stream_index, start_seconds, stop_seconds);
264264
return makeOpsBatchDecodedOutput(result);
265265
}

src/torchcodec/decoders/_core/_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class VideoStreamMetadata:
4646
"""End of the stream, in seconds (float or None).
4747
Conceptually, this corresponds to last_frame.pts + last_frame.duration. It
4848
is computed as max(frame.pts + frame.duration) across all frames in the
49-
stream. Note that no frame is displayed at this time value, so calling
50-
:meth:`~torchcodec.decoders.VideoDecoder.get_frame_displayed_at` with
49+
stream. Note that no frame is played at this time value, so calling
50+
:meth:`~torchcodec.decoders.VideoDecoder.get_frame_played_at` with
5151
this value would result in an error. Retrieving the last frame is best done
5252
by simply indexing the :class:`~torchcodec.decoders.VideoDecoder`
5353
object with ``[-1]``.

src/torchcodec/decoders/_video_decoder.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ def get_frames_in_range(self, start: int, stop: int, step: int = 1) -> FrameBatc
240240
)
241241
return FrameBatch(*frames)
242242

243-
def get_frame_displayed_at(self, seconds: float) -> Frame:
244-
"""Return a single frame displayed at the given timestamp in seconds.
243+
def get_frame_played_at(self, seconds: float) -> Frame:
244+
"""Return a single frame played at the given timestamp in seconds.
245245
246246
Args:
247-
seconds (float): The time stamp in seconds when the frame is displayed.
247+
seconds (float): The time stamp in seconds when the frame is played.
248248
249249
Returns:
250-
Frame: The frame that is displayed at ``seconds``.
250+
Frame: The frame that is played at ``seconds``.
251251
"""
252252
if not self._begin_stream_seconds <= seconds < self._end_stream_seconds:
253253
raise IndexError(
@@ -264,21 +264,21 @@ def get_frame_displayed_at(self, seconds: float) -> Frame:
264264
duration_seconds=duration_seconds.item(),
265265
)
266266

267-
def get_frames_displayed_at(self, seconds: list[float]) -> FrameBatch:
268-
"""Return frames displayed at the given timestamps in seconds.
267+
def get_frames_played_at(self, seconds: list[float]) -> FrameBatch:
268+
"""Return frames played at the given timestamps in seconds.
269269
270270
.. note::
271271
272272
Calling this method is more efficient that repeated individual calls
273-
to :meth:`~torchcodec.decoders.VideoDecoder.get_frame_displayed_at`.
273+
to :meth:`~torchcodec.decoders.VideoDecoder.get_frame_played_at`.
274274
This method makes sure not to decode the same frame twice, and also
275275
avoids "backwards seek" operations, which are slow.
276276
277277
Args:
278-
seconds (list of float): The timestamps in seconds when the frames are displayed.
278+
seconds (list of float): The timestamps in seconds when the frames are played.
279279
280280
Returns:
281-
FrameBatch: The frames that are displayed at ``seconds``.
281+
FrameBatch: The frames that are played at ``seconds``.
282282
"""
283283
data, pts_seconds, duration_seconds = core.get_frames_by_pts(
284284
self._decoder, timestamps=seconds, stream_index=self.stream_index
@@ -289,7 +289,7 @@ def get_frames_displayed_at(self, seconds: list[float]) -> FrameBatch:
289289
duration_seconds=duration_seconds,
290290
)
291291

292-
def get_frames_displayed_in_range(
292+
def get_frames_played_in_range(
293293
self, start_seconds: float, stop_seconds: float
294294
) -> FrameBatch:
295295
"""Returns multiple frames in the given range.

src/torchcodec/samplers/_time_based.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _generic_time_based_sampler(
209209
policy_fun=_POLICY_FUNCTIONS[policy],
210210
)
211211

212-
frames = decoder.get_frames_displayed_at(seconds=all_clips_timestamps)
212+
frames = decoder.get_frames_played_at(seconds=all_clips_timestamps)
213213
return _reshape_4d_framebatch_into_5d(
214214
frames=frames,
215215
num_clips=num_clips,

test/decoders/VideoDecoderTest.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,24 +261,23 @@ TEST_P(VideoDecoderTest, SeeksCloseToEof) {
261261
EXPECT_THROW(ourDecoder->getNextDecodedOutputNoDemux(), std::exception);
262262
}
263263

264-
TEST_P(VideoDecoderTest, GetsFrameDisplayedAtTimestamp) {
264+
TEST_P(VideoDecoderTest, GetsFramePlayedAtTimestamp) {
265265
std::string path = getResourcePath("nasa_13013.mp4");
266266
std::unique_ptr<VideoDecoder> ourDecoder =
267267
createDecoderFromPath(path, GetParam());
268268
ourDecoder->addVideoStreamDecoder(-1);
269-
auto output = ourDecoder->getFrameDisplayedAtTimestampNoDemux(6.006);
269+
auto output = ourDecoder->getFramePlayedAtTimestampNoDemux(6.006);
270270
EXPECT_EQ(output.ptsSeconds, 6.006);
271271
// The frame's duration is 0.033367 according to ffprobe,
272-
// so the next frame is displayed at timestamp=6.039367.
272+
// so the next frame is played at timestamp=6.039367.
273273
const double kNextFramePts = 6.039366666666667;
274-
// The frame that is displayed a microsecond before the next frame is still
274+
// The frame that is played a microsecond before the next frame is still
275275
// the previous frame.
276-
output =
277-
ourDecoder->getFrameDisplayedAtTimestampNoDemux(kNextFramePts - 1e-6);
276+
output = ourDecoder->getFramePlayedAtTimestampNoDemux(kNextFramePts - 1e-6);
278277
EXPECT_EQ(output.ptsSeconds, 6.006);
279-
// The frame that is displayed at the exact pts of the frame is the next
278+
// The frame that is played at the exact pts of the frame is the next
280279
// frame.
281-
output = ourDecoder->getFrameDisplayedAtTimestampNoDemux(kNextFramePts);
280+
output = ourDecoder->getFramePlayedAtTimestampNoDemux(kNextFramePts);
282281
EXPECT_EQ(output.ptsSeconds, kNextFramePts);
283282

284283
// This is the timestamp of the last frame in this video.
@@ -288,7 +287,7 @@ TEST_P(VideoDecoderTest, GetsFrameDisplayedAtTimestamp) {
288287
kPtsOfLastFrameInVideoStream + kDurationOfLastFrameInVideoStream;
289288
// Sanity check: make sure duration is strictly positive.
290289
EXPECT_GT(kPtsPlusDurationOfLastFrame, kPtsOfLastFrameInVideoStream);
291-
output = ourDecoder->getFrameDisplayedAtTimestampNoDemux(
290+
output = ourDecoder->getFramePlayedAtTimestampNoDemux(
292291
kPtsPlusDurationOfLastFrame - 1e-6);
293292
EXPECT_EQ(output.ptsSeconds, kPtsOfLastFrameInVideoStream);
294293
}

0 commit comments

Comments
 (0)