Skip to content

Commit c11024f

Browse files
committed
Revert "Align DecodecOutput with BatchDecodedOutput"
This reverts commit 8b1e44e.
1 parent 8b1e44e commit c11024f

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,10 @@ VideoDecoder::DecodedOutput VideoDecoder::convertAVFrameToDecodedOutput(
869869
AVFrame* frame = rawOutput.frame.get();
870870
output.streamIndex = streamIndex;
871871
auto& streamInfo = streams_[streamIndex];
872+
output.pts = frame->pts;
872873
output.ptsSeconds =
873874
ptsToSeconds(frame->pts, formatContext_->streams[streamIndex]->time_base);
875+
output.duration = getDuration(frame);
874876
output.durationSeconds = ptsToSeconds(
875877
getDuration(frame), formatContext_->streams[streamIndex]->time_base);
876878
// TODO: we should fold preAllocatedOutputTensor into RawDecodedOutput.

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,12 @@ class VideoDecoder {
194194
// The stream index of the decoded frame. Used to distinguish
195195
// between streams that are of the same type.
196196
int streamIndex;
197+
// The presentation timestamp of the decoded frame in time base.
198+
int64_t pts;
197199
// The presentation timestamp of the decoded frame in seconds.
198200
double ptsSeconds;
201+
// The duration of the decoded frame in time base.
202+
int64_t duration;
199203
// The duration of the decoded frame in seconds.
200204
double durationSeconds;
201205
};

test/decoders/VideoDecoderTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ TEST_P(VideoDecoderTest, ReturnsFirstTwoFramesOfVideo) {
172172
torch::Tensor tensor0FromOurDecoder = output.frame;
173173
EXPECT_EQ(tensor0FromOurDecoder.sizes(), std::vector<long>({3, 270, 480}));
174174
EXPECT_EQ(output.ptsSeconds, 0.0);
175+
EXPECT_EQ(output.pts, 0);
175176
output = ourDecoder->getNextFrameNoDemux();
176177
torch::Tensor tensor1FromOurDecoder = output.frame;
177178
EXPECT_EQ(tensor1FromOurDecoder.sizes(), std::vector<long>({3, 270, 480}));
178179
EXPECT_EQ(output.ptsSeconds, 1'001. / 30'000);
180+
EXPECT_EQ(output.pts, 1001);
179181

180182
torch::Tensor tensor0FromFFMPEG =
181183
readTensorFromDisk("nasa_13013.mp4.stream3.frame000000.pt");

0 commit comments

Comments
 (0)