Skip to content

Commit 4ba7db2

Browse files
committed
Merge branch 'fix-timebase' into dts_fallback
2 parents 9d6bcff + a4a034a commit 4ba7db2

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717
namespace facebook::torchcodec {
1818
namespace {
1919

20-
double ptsToSeconds(int64_t pts, int den) {
21-
return static_cast<double>(pts) / den;
22-
}
23-
2420
double ptsToSeconds(int64_t pts, const AVRational& timeBase) {
25-
return ptsToSeconds(pts, timeBase.den);
21+
return static_cast<double>(pts) * timeBase.num / timeBase.den;
2622
}
2723

2824
int64_t secondsToClosestPts(double seconds, const AVRational& timeBase) {
29-
return static_cast<int64_t>(std::round(seconds * timeBase.den));
25+
return static_cast<int64_t>(
26+
std::round(seconds * timeBase.den / timeBase.num));
3027
}
3128

3229
int64_t getPtsOrDts(const UniqueAVFrame& avFrame) {
@@ -159,7 +156,7 @@ void SingleStreamDecoder::initializeDecoder() {
159156

160157
if (formatContext_->duration > 0) {
161158
containerMetadata_.durationSeconds =
162-
ptsToSeconds(formatContext_->duration, AV_TIME_BASE);
159+
ptsToSeconds(formatContext_->duration, AV_TIME_BASE_Q);
163160
}
164161

165162
if (formatContext_->bit_rate > 0) {

0 commit comments

Comments
 (0)