Skip to content

Commit a4a034a

Browse files
committed
Fix pts <-> seconds conversions
1 parent 721c315 commit a4a034a

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
} // namespace
@@ -152,7 +149,7 @@ void SingleStreamDecoder::initializeDecoder() {
152149

153150
if (formatContext_->duration > 0) {
154151
containerMetadata_.durationSeconds =
155-
ptsToSeconds(formatContext_->duration, AV_TIME_BASE);
152+
ptsToSeconds(formatContext_->duration, AV_TIME_BASE_Q);
156153
}
157154

158155
if (formatContext_->bit_rate > 0) {

0 commit comments

Comments
 (0)