Skip to content

Commit

Permalink
More mode consolidation.
Browse files Browse the repository at this point in the history
  • Loading branch information
scotts committed Dec 21, 2024
1 parent 7267b5a commit ae44f78
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
35 changes: 2 additions & 33 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,6 @@ VideoDecoder::BatchDecodedOutput::BatchDecodedOutput(
frames = allocateEmptyHWCTensor(height, width, options.device, numFrames);
}

VideoDecoder::BatchDecodedOutput::BatchDecodedOutput(
const std::vector<torch::Tensor>& inFrames,
std::vector<double>& inPtsSeconds,
std::vector<double>& inDurationSeconds)
: frames(torch::stack(inFrames)),
ptsSeconds(torch::from_blob(
inPtsSeconds.data(),
inPtsSeconds.size(),
{torch::kFloat64})
.clone()),
durationSeconds(torch::from_blob(
inDurationSeconds.data(),
inDurationSeconds.size(),
{torch::kFloat64})
.clone()) {}

bool VideoDecoder::DecodedFrameContext::operator==(
const VideoDecoder::DecodedFrameContext& other) {
return decodedWidth == other.decodedWidth && decodedHeight == decodedHeight &&
Expand Down Expand Up @@ -1323,23 +1307,8 @@ VideoDecoder::BatchDecodedOutput VideoDecoder::getFramesPlayedByTimestamps(
"; must be in range [" + std::to_string(minSeconds) + ", " +
std::to_string(maxSeconds) + ").");

int64_t frameIndex = -1;
if (seekMode_ == SeekMode::exact) {
auto it = std::lower_bound(
stream.allFrames.begin(),
stream.allFrames.end(),
frameSeconds,
[&stream](const FrameInfo& info, double frameSeconds) {
return ptsToSeconds(info.nextPts, stream.timeBase) <= frameSeconds;
});
frameIndex = it - stream.allFrames.begin();
} else if (seekMode_ == SeekMode::approximate) {
frameIndex = std::floor(frameSeconds * streamMetadata.averageFps.value());
} else {
throw std::runtime_error("Unknown SeekMode");
}

frameIndices[i] = frameIndex;
frameIndices[i] =
secondsToIndexLowerBound(frameSeconds, stream, streamMetadata);
}

return getFramesAtIndices(streamIndex, frameIndices);
Expand Down
5 changes: 0 additions & 5 deletions src/torchcodec/decoders/_core/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ class VideoDecoder {
int64_t numFrames,
const VideoStreamDecoderOptions& options,
const StreamMetadata& metadata);

explicit BatchDecodedOutput(
const std::vector<torch::Tensor>& inFrames,
std::vector<double>& inPtsSeconds,
std::vector<double>& inDurationSeconds);
};

// Returns frames at the given indices for a given stream as a single stacked
Expand Down

0 comments on commit ae44f78

Please sign in to comment.