@@ -1536,6 +1536,9 @@ int64_t VideoDecoder::secondsToIndexLowerBound(double seconds) {
1536
1536
case SeekMode::approximate: {
1537
1537
auto & streamMetadata =
1538
1538
containerMetadata_.allStreamMetadata [activeStreamIndex_];
1539
+ TORCH_CHECK (
1540
+ streamMetadata.averageFps .has_value (),
1541
+ " Cannot use approximate mode since we couldn't find the average fps from the metadata." );
1539
1542
return std::floor (seconds * streamMetadata.averageFps .value ());
1540
1543
}
1541
1544
default :
@@ -1560,6 +1563,9 @@ int64_t VideoDecoder::secondsToIndexUpperBound(double seconds) {
1560
1563
case SeekMode::approximate: {
1561
1564
auto & streamMetadata =
1562
1565
containerMetadata_.allStreamMetadata [activeStreamIndex_];
1566
+ TORCH_CHECK (
1567
+ streamMetadata.averageFps .has_value (),
1568
+ " Cannot use approximate mode since we couldn't find the average fps from the metadata." );
1563
1569
return std::ceil (seconds * streamMetadata.averageFps .value ());
1564
1570
}
1565
1571
default :
@@ -1575,6 +1581,9 @@ int64_t VideoDecoder::getPts(int64_t frameIndex) {
1575
1581
case SeekMode::approximate: {
1576
1582
auto & streamMetadata =
1577
1583
containerMetadata_.allStreamMetadata [activeStreamIndex_];
1584
+ TORCH_CHECK (
1585
+ streamMetadata.averageFps .has_value (),
1586
+ " Cannot use approximate mode since we couldn't find the average fps from the metadata." );
1578
1587
return secondsToClosestPts (
1579
1588
frameIndex / streamMetadata.averageFps .value (), streamInfo.timeBase );
1580
1589
}
@@ -1591,8 +1600,12 @@ int64_t VideoDecoder::getNumFrames(const StreamMetadata& streamMetadata) {
1591
1600
switch (seekMode_) {
1592
1601
case SeekMode::exact:
1593
1602
return streamMetadata.numFramesFromScan .value ();
1594
- case SeekMode::approximate:
1603
+ case SeekMode::approximate: {
1604
+ TORCH_CHECK (
1605
+ streamMetadata.numFrames .has_value (),
1606
+ " Cannot use approximate mode since we couldn't find the number of frames from the metadata." );
1595
1607
return streamMetadata.numFrames .value ();
1608
+ }
1596
1609
default :
1597
1610
throw std::runtime_error (" Unknown SeekMode" );
1598
1611
}
@@ -1613,8 +1626,12 @@ double VideoDecoder::getMaxSeconds(const StreamMetadata& streamMetadata) {
1613
1626
switch (seekMode_) {
1614
1627
case SeekMode::exact:
1615
1628
return streamMetadata.maxPtsSecondsFromScan .value ();
1616
- case SeekMode::approximate:
1629
+ case SeekMode::approximate: {
1630
+ TORCH_CHECK (
1631
+ streamMetadata.durationSeconds .has_value (),
1632
+ " Cannot use approximate mode since we couldn't find the duration from the metadata." );
1617
1633
return streamMetadata.durationSeconds .value ();
1634
+ }
1618
1635
default :
1619
1636
throw std::runtime_error (" Unknown SeekMode" );
1620
1637
}
0 commit comments