Skip to content

Commit

Permalink
Indexes -> Indices
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasHug committed Oct 10, 2024
1 parent 21aef92 commit 64242fb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions benchmarks/decoders/benchmark_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ def get_frames_from_video(self, video_file, pts_list):
metadata = json.loads(get_json_metadata(decoder))
average_fps = metadata["averageFps"]
best_video_stream = metadata["bestVideoStreamIndex"]
indexes_list = [int(pts * average_fps) for pts in pts_list]
indices_list = [int(pts * average_fps) for pts in pts_list]
frames = []
frames = get_frames_at_indices(
decoder, stream_index=best_video_stream, frame_indices=indexes_list
decoder, stream_index=best_video_stream, frame_indices=indices_list
)
return frames

Expand Down
10 changes: 5 additions & 5 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,19 +967,19 @@ VideoDecoder::DecodedOutput VideoDecoder::getFrameAtIndex(
return getNextDecodedOutputNoDemux();
}

VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesAtIndexes(
VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesAtIndices(
int streamIndex,
const std::vector<int64_t>& frameIndexes) {
const std::vector<int64_t>& frameIndices) {
validateUserProvidedStreamIndex(streamIndex);
validateScannedAllStreams("getFramesAtIndexes");
validateScannedAllStreams("getFramesAtIndices");

const auto& streamMetadata = containerMetadata_.streams[streamIndex];
const auto& options = streams_[streamIndex].options;
BatchDecodedOutput output(frameIndexes.size(), options, streamMetadata);
BatchDecodedOutput output(frameIndices.size(), options, streamMetadata);

int i = 0;
const auto& stream = streams_[streamIndex];
for (int64_t frameIndex : frameIndexes) {
for (int64_t frameIndex : frameIndices) {
if (frameIndex < 0 || frameIndex >= stream.allFrames.size()) {
throw std::runtime_error(
"Invalid frame index=" + std::to_string(frameIndex));
Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/decoders/_core/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ class VideoDecoder {
const VideoStreamDecoderOptions& options,
const StreamMetadata& metadata);
};
// Returns frames at the given indexes for a given stream as a single stacked
// Returns frames at the given indices for a given stream as a single stacked
// Tensor.
BatchDecodedOutput getFramesAtIndexes(
BatchDecodedOutput getFramesAtIndices(
int streamIndex,
const std::vector<int64_t>& frameIndexes);
const std::vector<int64_t>& frameIndices);
// Returns frames within a given range for a given stream as a single stacked
// Tensor. The range is defined by [start, stop). The values retrieved from
// the range are:
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/decoders/_core/VideoDecoderOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ at::Tensor get_frames_at_indices(
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
std::vector<int64_t> frameIndicesVec(
frame_indices.begin(), frame_indices.end());
auto result = videoDecoder->getFramesAtIndexes(stream_index, frameIndicesVec);
auto result = videoDecoder->getFramesAtIndices(stream_index, frameIndicesVec);
return result.frames;
}

Expand Down
4 changes: 2 additions & 2 deletions test/decoders/VideoDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TEST_P(VideoDecoderTest, DecodesFramesInABatchInNCHW) {
*ourDecoder->getContainerMetadata().bestVideoStreamIndex;
ourDecoder->addVideoStreamDecoder(bestVideoStreamIndex);
// Frame with index 180 corresponds to timestamp 6.006.
auto output = ourDecoder->getFramesAtIndexes(bestVideoStreamIndex, {0, 180});
auto output = ourDecoder->getFramesAtIndices(bestVideoStreamIndex, {0, 180});
auto tensor = output.frames;
EXPECT_EQ(tensor.sizes(), std::vector<long>({2, 3, 270, 480}));

Expand All @@ -234,7 +234,7 @@ TEST_P(VideoDecoderTest, DecodesFramesInABatchInNHWC) {
bestVideoStreamIndex,
VideoDecoder::VideoStreamDecoderOptions("dimension_order=NHWC"));
// Frame with index 180 corresponds to timestamp 6.006.
auto output = ourDecoder->getFramesAtIndexes(bestVideoStreamIndex, {0, 180});
auto output = ourDecoder->getFramesAtIndices(bestVideoStreamIndex, {0, 180});
auto tensor = output.frames;
EXPECT_EQ(tensor.sizes(), std::vector<long>({2, 270, 480, 3}));

Expand Down

0 comments on commit 64242fb

Please sign in to comment.