From af1798385f1dd7b26f53606d37bae195e809456f Mon Sep 17 00:00:00 2001
From: Nicolas Hug <contact@nicolas-hug.com>
Date: Mon, 17 Mar 2025 11:04:27 +0000
Subject: [PATCH] Add test to illustrate audio bug

---
 test/decoders/test_ops.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/test/decoders/test_ops.py b/test/decoders/test_ops.py
index 724eff62..7c36ade7 100644
--- a/test/decoders/test_ops.py
+++ b/test/decoders/test_ops.py
@@ -850,6 +850,23 @@ def test_pts(self, asset):
             else:
                 assert pts_seconds == start_seconds
 
+    def test_decode_before_frame_start(self):
+        # Test illustrating bug described in
+        # https://github.com/pytorch/torchcodec/issues/567
+        asset = NASA_AUDIO_MP3
+
+        decoder = create_from_file(str(asset.path), seek_mode="approximate")
+        add_audio_stream(decoder)
+
+        frames, *_ = get_frames_by_pts_in_range_audio(
+            decoder, start_seconds=0, stop_seconds=0.05
+        )
+        all_frames, *_ = get_frames_by_pts_in_range_audio(
+            decoder, start_seconds=0, stop_seconds=None
+        )
+        # TODO fix this. `frames` should be empty.
+        torch.testing.assert_close(frames, all_frames)
+
 
 if __name__ == "__main__":
     pytest.main()