Skip to content
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

Optimize mp4 parse times by not copying video data #12

Merged
merged 3 commits into from
Oct 22, 2024
Merged

Conversation

jprochazk
Copy link
Member

@jprochazk jprochazk commented Oct 22, 2024

Note that there's still a lot of optimization/refactor potential in this crate, which is why this doesn't close the above issue, but not copying all the video data is a great start.

Samples now have a helper which returns a range into the video data.

Breaking changes

  • Removed Track::read_sample, superseded by Sample::range which can be used to index the original buffer
  • Removed Track::data
  • Sample byte offsets are no longer remapped in any way, they now represent an offset from the start of the MP4 file.
  • read_file now returns a tuple of (Mp4, Vec<u8>) so that the original byte buffer is not lost and can be used together with Sample::range

@jprochazk jprochazk marked this pull request as ready for review October 22, 2024 12:16
@jprochazk jprochazk added the include in changelog Will appear in CHANGELOG.md label Oct 22, 2024
@jprochazk jprochazk changed the title Don't copy data Optimize mp4 parse times by not copying video data Oct 22, 2024
@Wumpf Wumpf self-requested a review October 22, 2024 12:31
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!! Sounds like this gets us most of the way with minimal effort
That range method needs better doc though

ideally we'd have some form of shared ownership of the buffer, but don't know how that pans out with the arrow-owned buffer

tests/multitrack.rs Show resolved Hide resolved
src/reader.rs Outdated Show resolved Hide resolved
src/reader.rs Outdated Show resolved Hide resolved
@Wumpf Wumpf self-requested a review October 22, 2024 12:55
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for going beyond! 🫶

@jprochazk jprochazk merged commit 7d38361 into main Oct 22, 2024
6 checks passed
@jprochazk jprochazk deleted the jan/zerocopy branch October 22, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include in changelog Will appear in CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants