Let the C++ Demuxer follow several streams of one container - #1677
Merged
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1677
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 18 PendingAs of commit 30fed89 with merge base 0d3103d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
from
September 1, 2026 14:46
0edb422 to
589f6b8
Compare
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
3 times, most recently
from
September 2, 2026 12:52
0a7fce7 to
03bd3e2
Compare
NicolasHug
changed the base branch from
msd/eof-sentinels
to
msd/frame-index-rename
September 2, 2026 12:56
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
from
September 2, 2026 13:41
03bd3e2 to
2cceac2
Compare
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
from
September 2, 2026 13:46
2cceac2 to
03bd3e2
Compare
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
from
September 2, 2026 13:47
03bd3e2 to
1ea878c
Compare
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
from
September 2, 2026 13:51
1ea878c to
adf1fca
Compare
NicolasHug
commented
Sep 3, 2026
Comment on lines
+52
to
+60
| int read_next_packet( | ||
| AVFormatContext* format_context, | ||
| int active_stream_index, | ||
| ReferenceAVPacket& packet) { | ||
| return read_next_active_packet( | ||
| format_context, packet, [active_stream_index](int stream_index) { | ||
| return stream_index == active_stream_index; | ||
| }); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
I think this one can be removed when addressing the PR just above (scan)
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
from
September 3, 2026 08:28
adf1fca to
6e77021
Compare
The demuxer selected exactly one stream at construction. It now opens and probes in the constructor, and follows streams through add_stream(), which can be called more than once; av_read_frame's output is filtered against the set, and each packet is handed back with the stream index it came from. This is what makes audio + video from one container a single pass. Two single-stream demuxers open the file twice, and a source that is expensive to open twice pays for it. seek() takes the stream to resolve against, since FFmpeg resolves a seek in one stream's time base and lands on that stream's keyframes; left unspecified it picks the first followed video stream, then the first followed stream. scan() likewise takes the stream to index. PacketDecoder takes the stream it decodes rather than reading the demuxer's only one. No Python API changes: VideoDemuxer and AudioDemuxer construct then add their single stream, and behave exactly as before. Adding a stream once demuxing has started is rejected - it would start from wherever the container currently is rather than from the beginning.
NicolasHug
force-pushed
the
msd/cpp-multi-stream
branch
from
September 3, 2026 08:29
6e77021 to
30fed89
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The demuxer selected exactly one stream at construction. It now opens and probes in the constructor, and follows streams through
add_stream(), which can be called more than once;av_read_frame's output is filtered against the set, and each packet is handed back with the stream index it came from.seek()takes the stream to resolve against, since FFmpeg resolves a seek in one stream's time base and lands on that stream's keyframes: it's stream-dependent. By default, it picks the first followed stream as passed by thestreams=parameter at Demuxer creation.No Python API changes.
Stack created with GitHub Stacks CLI • Give Feedback 💬