Skip to content

Commit 389c078

Browse files
author
Molly Xu
committed
fallback to container duration in approximate mode when stream duration is unavailable
1 parent 1befed7 commit 389c078

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ void SingleStreamDecoder::initializeDecoder() {
158158
ptsToSeconds(formatContext_->duration, defaultTimeBase);
159159
}
160160

161+
// Use container duration as fallback for streams missing stream duration
162+
if (containerMetadata_.durationSecondsFromHeader.has_value()) {
163+
for (auto& streamMetadata : containerMetadata_.allStreamMetadata) {
164+
if (!streamMetadata.durationSecondsFromHeader.has_value()) {
165+
streamMetadata.durationSecondsFromHeader =
166+
containerMetadata_.durationSecondsFromHeader;
167+
}
168+
}
169+
}
170+
161171
if (formatContext_->bit_rate > 0) {
162172
containerMetadata_.bitRate = formatContext_->bit_rate;
163173
}

test/test_decoders.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
SINE_MONO_S32,
4747
SINE_MONO_S32_44100,
4848
SINE_MONO_S32_8000,
49-
supports_approximate_mode,
5049
TEST_SRC_2_720P,
5150
TEST_SRC_2_720P_H265,
5251
TEST_SRC_2_720P_MPEG4,
@@ -1492,8 +1491,6 @@ def test_get_frames_at_tensor_indices(self):
14921491
def test_beta_cuda_interface_get_frame_at(
14931492
self, asset, contiguous_indices, seek_mode
14941493
):
1495-
if seek_mode == "approximate" and not supports_approximate_mode(asset):
1496-
pytest.skip("asset doesn't work with approximate mode")
14971494

14981495
if in_fbcode() and asset is AV1_VIDEO:
14991496
pytest.skip("AV1 CUDA not supported internally")
@@ -1540,8 +1537,6 @@ def test_beta_cuda_interface_get_frame_at(
15401537
def test_beta_cuda_interface_get_frames_at(
15411538
self, asset, contiguous_indices, seek_mode
15421539
):
1543-
if seek_mode == "approximate" and not supports_approximate_mode(asset):
1544-
pytest.skip("asset doesn't work with approximate mode")
15451540
if in_fbcode() and asset is AV1_VIDEO:
15461541
pytest.skip("AV1 CUDA not supported internally")
15471542

@@ -1585,8 +1580,6 @@ def test_beta_cuda_interface_get_frames_at(
15851580
)
15861581
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
15871582
def test_beta_cuda_interface_get_frame_played_at(self, asset, seek_mode):
1588-
if seek_mode == "approximate" and not supports_approximate_mode(asset):
1589-
pytest.skip("asset doesn't work with approximate mode")
15901583
if in_fbcode() and asset is AV1_VIDEO:
15911584
pytest.skip("AV1 CUDA not supported internally")
15921585

@@ -1627,8 +1620,6 @@ def test_beta_cuda_interface_get_frame_played_at(self, asset, seek_mode):
16271620
)
16281621
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
16291622
def test_beta_cuda_interface_get_frames_played_at(self, asset, seek_mode):
1630-
if seek_mode == "approximate" and not supports_approximate_mode(asset):
1631-
pytest.skip("asset doesn't work with approximate mode")
16321623
if in_fbcode() and asset is AV1_VIDEO:
16331624
pytest.skip("AV1 CUDA not supported internally")
16341625

@@ -1670,8 +1661,6 @@ def test_beta_cuda_interface_get_frames_played_at(self, asset, seek_mode):
16701661
)
16711662
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
16721663
def test_beta_cuda_interface_backwards(self, asset, seek_mode):
1673-
if seek_mode == "approximate" and not supports_approximate_mode(asset):
1674-
pytest.skip("asset doesn't work with approximate mode")
16751664
if in_fbcode() and asset is AV1_VIDEO:
16761665
pytest.skip("AV1 CUDA not supported internally")
16771666

test/utils.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,3 @@ def sample_format(self) -> str:
798798
},
799799
frames={0: {}}, # Not needed for now
800800
)
801-
802-
803-
def supports_approximate_mode(asset: TestVideo) -> bool:
804-
# Those are missing the `duration` field so they fail in approximate mode (on all devices).
805-
# TODO: we should address this, see
806-
# https://github.com/meta-pytorch/torchcodec/issues/945
807-
return asset not in (AV1_VIDEO, TEST_SRC_2_720P_VP9, TEST_SRC_2_720P_VP8)

0 commit comments

Comments
 (0)