Skip to content

Audio decoding support: range-based core API #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ae15304
Add basic range support
NicolasHug Mar 6, 2025
29e0b8d
Add more tests
NicolasHug Mar 6, 2025
cad69da
Merge branch 'main' of github.com:pytorch/torchcodec into audioooooooo
NicolasHug Mar 6, 2025
04f6282
Add separate audio decoding method
NicolasHug Mar 7, 2025
f8dfcda
Merge branch 'main' of github.com:pytorch/torchcodec into audioooooooo
NicolasHug Mar 7, 2025
da40954
More stuff
NicolasHug Mar 7, 2025
3881586
Cleanups
NicolasHug Mar 7, 2025
82bea4a
Remove old code
NicolasHug Mar 7, 2025
ce12f03
More validation, more tests
NicolasHug Mar 8, 2025
59b0d15
remove next() support
NicolasHug Mar 8, 2025
f4bed23
Rename
NicolasHug Mar 8, 2025
fe04cd2
Add support for None stop_seconds
NicolasHug Mar 8, 2025
98fee85
Remove pre-alloc logic
NicolasHug Mar 8, 2025
d2357fe
Add test
NicolasHug Mar 8, 2025
f3b56f8
Add proper error when backward seek is neede
NicolasHug Mar 8, 2025
5f2800a
Cleanup
NicolasHug Mar 8, 2025
2f020f2
Add TODO
NicolasHug Mar 9, 2025
0c11f72
Put back original compilation flags
NicolasHug Mar 9, 2025
de4facc
Fix
NicolasHug Mar 9, 2025
b5f2df0
nit
NicolasHug Mar 9, 2025
09e6f44
Oops, fix
NicolasHug Mar 9, 2025
3d955c1
Add case for start=stop
NicolasHug Mar 9, 2025
d791d2a
Simplify
NicolasHug Mar 9, 2025
0c0f62b
Don't use a lambda
NicolasHug Mar 9, 2025
893c358
Merge branch 'main' of github.com:pytorch/torchcodec into audioooooooo
NicolasHug Mar 11, 2025
c35ae47
Fix
NicolasHug Mar 11, 2025
c453a3c
Address comments
NicolasHug Mar 12, 2025
dafb927
Add comment
NicolasHug Mar 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify
  • Loading branch information
NicolasHug committed Mar 9, 2025
commit d791d2aeed13a35cea547de251a66b39d5087563
10 changes: 4 additions & 6 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,10 @@ torch::Tensor VideoDecoder::getFramesPlayedInRangeAudio(
// We should remove it and seek back to the stream's beginning when needed.
// See test_multiple_calls
TORCH_CHECK(
(streamInfo.lastDecodedAvFramePts == 0 &&
streamInfo.lastDecodedAvFrameDuration == 0) ||
(streamInfo.lastDecodedAvFramePts +
streamInfo.lastDecodedAvFrameDuration <=
secondsToClosestPts(startSeconds, streamInfo.timeBase)),
"The previous call's stop_seconds is larger than the current calls's start_seconds (roughly)");
streamInfo.lastDecodedAvFramePts +
streamInfo.lastDecodedAvFrameDuration <=
secondsToClosestPts(startSeconds, streamInfo.timeBase),
"Audio decoder cannot seek backwards, or start from the last decoded frame.");

setCursorPtsInSeconds(startSeconds);

Expand Down
16 changes: 4 additions & 12 deletions test/decoders/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,27 +782,19 @@ def get_reference_frames(start_seconds, stop_seconds):
)

# but starting immediately on the same frame raises
with pytest.raises(
RuntimeError,
match="The previous call's stop_seconds is larger than the current calls's start_seconds",
):
expected_match = "Audio decoder cannot seek backwards"
with pytest.raises(RuntimeError, match=expected_match):
get_frames_by_pts_in_range_audio(
decoder, start_seconds=stop_seconds, stop_seconds=6
)

with pytest.raises(
RuntimeError,
match="The previous call's stop_seconds is larger than the current calls's start_seconds",
):
with pytest.raises(RuntimeError, match=expected_match):
get_frames_by_pts_in_range_audio(
decoder, start_seconds=stop_seconds + 1e-4, stop_seconds=6
)

# and seeking backwards doesn't work either
with pytest.raises(
RuntimeError,
match="The previous call's stop_seconds is larger than the current calls's start_seconds",
):
with pytest.raises(RuntimeError, match=expected_match):
frames = get_frames_by_pts_in_range_audio(
decoder, start_seconds=0, stop_seconds=2
)
Expand Down
Loading