Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align high-level decoding entry points names with Python #473

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ void VideoDecoder::convertAVFrameToFrameOutputOnCPU(
}
}

VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAtTimestampNoDemux(
VideoDecoder::FrameOutput VideoDecoder::getFramePlayedAtNoDemux(
double seconds) {
for (auto& [streamIndex, streamInfo] : streamInfos_) {
double frameStartTime =
Expand Down Expand Up @@ -1316,7 +1316,7 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesAtIndices(
return frameBatchOutput;
}

VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedByTimestamps(
VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedAt(
int streamIndex,
const std::vector<double>& timestamps) {
validateUserProvidedStreamIndex(streamIndex);
Expand Down Expand Up @@ -1385,7 +1385,7 @@ VideoDecoder::FrameBatchOutput VideoDecoder::getFramesInRange(
return frameBatchOutput;
}

VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedByTimestampInRange(
VideoDecoder::FrameBatchOutput VideoDecoder::getFramesPlayedInRange(
int streamIndex,
double startSeconds,
double stopSeconds) {
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 @@ -219,7 +219,7 @@ class VideoDecoder {
// duration of 1.0s, it will be visible in the timestamp range [5.0, 6.0).
// i.e. it will be returned when this function is called with seconds=5.0 or
// seconds=5.999, etc.
FrameOutput getFramePlayedAtTimestampNoDemux(double seconds);
FrameOutput getFramePlayedAtNoDemux(double seconds);

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

FrameBatchOutput getFramesPlayedByTimestamps(
FrameBatchOutput getFramesPlayedAt(
int streamIndex,
const std::vector<double>& timestamps);

Expand Down Expand Up @@ -265,7 +265,7 @@ class VideoDecoder {
// Valid values for startSeconds and stopSeconds are:
//
// [minPtsSecondsFromScan, maxPtsSecondsFromScan)
FrameBatchOutput getFramesPlayedByTimestampInRange(
FrameBatchOutput getFramesPlayedInRange(
int streamIndex,
double startSeconds,
double stopSeconds);
Expand Down
7 changes: 3 additions & 4 deletions src/torchcodec/decoders/_core/VideoDecoderOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ OpsFrameOutput get_next_frame(at::Tensor& decoder) {

OpsFrameOutput get_frame_at_pts(at::Tensor& decoder, double seconds) {
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
auto result = videoDecoder->getFramePlayedAtTimestampNoDemux(seconds);
auto result = videoDecoder->getFramePlayedAtNoDemux(seconds);
return makeOpsFrameOutput(result);
}

Expand Down Expand Up @@ -287,8 +287,7 @@ OpsFrameBatchOutput get_frames_by_pts(
at::ArrayRef<double> timestamps) {
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
std::vector<double> timestampsVec(timestamps.begin(), timestamps.end());
auto result =
videoDecoder->getFramesPlayedByTimestamps(stream_index, timestampsVec);
auto result = videoDecoder->getFramesPlayedAt(stream_index, timestampsVec);
return makeOpsFrameBatchOutput(result);
}

Expand All @@ -298,7 +297,7 @@ OpsFrameBatchOutput get_frames_by_pts_in_range(
double start_seconds,
double stop_seconds) {
auto videoDecoder = unwrapTensorToGetDecoder(decoder);
auto result = videoDecoder->getFramesPlayedByTimestampInRange(
auto result = videoDecoder->getFramesPlayedInRange(
stream_index, start_seconds, stop_seconds);
return makeOpsFrameBatchOutput(result);
}
Expand Down
10 changes: 5 additions & 5 deletions test/decoders/VideoDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,18 @@ TEST_P(VideoDecoderTest, GetsFramePlayedAtTimestamp) {
std::unique_ptr<VideoDecoder> ourDecoder =
createDecoderFromPath(path, GetParam());
ourDecoder->addVideoStreamDecoder(-1);
auto output = ourDecoder->getFramePlayedAtTimestampNoDemux(6.006);
auto output = ourDecoder->getFramePlayedAtNoDemux(6.006);
EXPECT_EQ(output.ptsSeconds, 6.006);
// The frame's duration is 0.033367 according to ffprobe,
// so the next frame is played at timestamp=6.039367.
const double kNextFramePts = 6.039366666666667;
// The frame that is played a microsecond before the next frame is still
// the previous frame.
output = ourDecoder->getFramePlayedAtTimestampNoDemux(kNextFramePts - 1e-6);
output = ourDecoder->getFramePlayedAtNoDemux(kNextFramePts - 1e-6);
EXPECT_EQ(output.ptsSeconds, 6.006);
// The frame that is played at the exact pts of the frame is the next
// frame.
output = ourDecoder->getFramePlayedAtTimestampNoDemux(kNextFramePts);
output = ourDecoder->getFramePlayedAtNoDemux(kNextFramePts);
EXPECT_EQ(output.ptsSeconds, kNextFramePts);

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

Expand Down
Loading