Skip to content

Commit 28e1503

Browse files
authored
Fix first PTS bug (#565)
1 parent 8e611bb commit 28e1503

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ void VideoDecoder::addStream(
467467
TORCH_CHECK_EQ(retVal, AVSUCCESS);
468468

469469
streamInfo.codecContext->thread_count = ffmpegThreadCount.value_or(0);
470+
streamInfo.codecContext->pkt_timebase = streamInfo.stream->time_base;
470471

471472
// TODO_CODE_QUALITY same as above.
472473
if (mediaType == AVMEDIA_TYPE_VIDEO && device.type() == torch::kCUDA) {

test/decoders/test_decoders.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -990,13 +990,7 @@ def test_get_all_samples(self, asset, stop_seconds):
990990
torch.testing.assert_close(samples.data, reference_frames)
991991
assert samples.sample_rate == asset.sample_rate
992992

993-
# TODO there's a bug with NASA_AUDIO_MP3: https://github.com/pytorch/torchcodec/issues/553
994-
expected_pts = (
995-
0.072
996-
if asset is NASA_AUDIO_MP3
997-
else asset.get_frame_info(idx=0).pts_seconds
998-
)
999-
assert samples.pts_seconds == expected_pts
993+
assert samples.pts_seconds == asset.get_frame_info(idx=0).pts_seconds
1000994

1001995
@pytest.mark.parametrize("asset", (NASA_AUDIO, NASA_AUDIO_MP3))
1002996
def test_at_frame_boundaries(self, asset):
@@ -1060,12 +1054,8 @@ def test_start_equals_stop(self, asset):
10601054
assert samples.data.shape == (0, 0)
10611055

10621056
def test_frame_start_is_not_zero(self):
1063-
# For NASA_AUDIO_MP3, the first frame is not at 0, it's at 0.072 [1].
1057+
# For NASA_AUDIO_MP3, the first frame is not at 0, it's at 0.138125.
10641058
# So if we request start = 0.05, we shouldn't be truncating anything.
1065-
#
1066-
# [1] well, really it's at 0.138125, not 0.072 (see
1067-
# https://github.com/pytorch/torchcodec/issues/553), but for the purpose
1068-
# of this test it doesn't matter.
10691059

10701060
asset = NASA_AUDIO_MP3
10711061
start_seconds = 0.05 # this is less than the first frame's pts

test/decoders/test_ops.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ def get_reference_frames(start_seconds, stop_seconds):
826826

827827
@pytest.mark.parametrize("asset", (NASA_AUDIO, NASA_AUDIO_MP3))
828828
def test_pts(self, asset):
829+
# Non-regression test for
830+
# https://github.com/pytorch/torchcodec/issues/553
829831
decoder = create_from_file(str(asset.path), seek_mode="approximate")
830832
add_audio_stream(decoder)
831833

@@ -840,15 +842,7 @@ def test_pts(self, asset):
840842
frames, asset.get_frame_data_by_index(frame_index)
841843
)
842844

843-
if asset is NASA_AUDIO_MP3 and frame_index == 0:
844-
# TODO This is a bug. The 0.138125 is correct while 0.072 is
845-
# incorrect, even though it comes from the decoded AVFrame's pts
846-
# field.
847-
# See https://github.com/pytorch/torchcodec/issues/553
848-
assert pts_seconds == 0.072
849-
assert start_seconds == 0.138125
850-
else:
851-
assert pts_seconds == start_seconds
845+
assert pts_seconds == start_seconds
852846

853847

854848
if __name__ == "__main__":

0 commit comments

Comments
 (0)