diff --git a/src/torchcodec/_core/SingleStreamDecoder.cpp b/src/torchcodec/_core/SingleStreamDecoder.cpp index 8d9e9f651..ff3a84187 100644 --- a/src/torchcodec/_core/SingleStreamDecoder.cpp +++ b/src/torchcodec/_core/SingleStreamDecoder.cpp @@ -158,6 +158,16 @@ void SingleStreamDecoder::initializeDecoder() { ptsToSeconds(formatContext_->duration, defaultTimeBase); } + // Use container duration as fallback for streams missing stream duration + if (containerMetadata_.durationSecondsFromHeader.has_value()) { + for (auto& streamMetadata : containerMetadata_.allStreamMetadata) { + if (!streamMetadata.durationSecondsFromHeader.has_value()) { + streamMetadata.durationSecondsFromHeader = + containerMetadata_.durationSecondsFromHeader; + } + } + } + if (formatContext_->bit_rate > 0) { containerMetadata_.bitRate = formatContext_->bit_rate; } diff --git a/test/test_decoders.py b/test/test_decoders.py index 6e08e05a4..30964dcca 100644 --- a/test/test_decoders.py +++ b/test/test_decoders.py @@ -46,7 +46,6 @@ SINE_MONO_S32, SINE_MONO_S32_44100, SINE_MONO_S32_8000, - supports_approximate_mode, TEST_SRC_2_720P, TEST_SRC_2_720P_H265, TEST_SRC_2_720P_MPEG4, @@ -1492,8 +1491,6 @@ def test_get_frames_at_tensor_indices(self): def test_beta_cuda_interface_get_frame_at( self, asset, contiguous_indices, seek_mode ): - if seek_mode == "approximate" and not supports_approximate_mode(asset): - pytest.skip("asset doesn't work with approximate mode") if in_fbcode() and asset is AV1_VIDEO: pytest.skip("AV1 CUDA not supported internally") @@ -1540,8 +1537,6 @@ def test_beta_cuda_interface_get_frame_at( def test_beta_cuda_interface_get_frames_at( self, asset, contiguous_indices, seek_mode ): - if seek_mode == "approximate" and not supports_approximate_mode(asset): - pytest.skip("asset doesn't work with approximate mode") if in_fbcode() and asset is AV1_VIDEO: pytest.skip("AV1 CUDA not supported internally") @@ -1585,8 +1580,6 @@ def test_beta_cuda_interface_get_frames_at( ) @pytest.mark.parametrize("seek_mode", ("exact", "approximate")) def test_beta_cuda_interface_get_frame_played_at(self, asset, seek_mode): - if seek_mode == "approximate" and not supports_approximate_mode(asset): - pytest.skip("asset doesn't work with approximate mode") if in_fbcode() and asset is AV1_VIDEO: pytest.skip("AV1 CUDA not supported internally") @@ -1627,8 +1620,6 @@ def test_beta_cuda_interface_get_frame_played_at(self, asset, seek_mode): ) @pytest.mark.parametrize("seek_mode", ("exact", "approximate")) def test_beta_cuda_interface_get_frames_played_at(self, asset, seek_mode): - if seek_mode == "approximate" and not supports_approximate_mode(asset): - pytest.skip("asset doesn't work with approximate mode") if in_fbcode() and asset is AV1_VIDEO: pytest.skip("AV1 CUDA not supported internally") @@ -1670,8 +1661,6 @@ def test_beta_cuda_interface_get_frames_played_at(self, asset, seek_mode): ) @pytest.mark.parametrize("seek_mode", ("exact", "approximate")) def test_beta_cuda_interface_backwards(self, asset, seek_mode): - if seek_mode == "approximate" and not supports_approximate_mode(asset): - pytest.skip("asset doesn't work with approximate mode") if in_fbcode() and asset is AV1_VIDEO: pytest.skip("AV1 CUDA not supported internally")