Stream process support with example for on-the-fly MP4 encryption and refragmentation #465
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.
Overview
Implements support for processing fragmented MP4 files incrementally without loading entire
files into memory. This is good for handling large media files, live streaming scenarios,
and network streams where fragments arrive over time.
Core Features
1. StreamFile API (
mp4/stream.go)New
StreamFiletype enables incremental processing of fragmented MP4:GetSample: Fetch individual samples (1-based indexing)GetSampleRange: Fetch sample ranges efficientlyGetSamples: Fetch all samples for a track2. BoxSeekReader (
mp4/boxseekreader.go)Enables lazy mdat processing on non-seekable streams:
ResetBuffer()to prevent corruption3. FtypBox and StypBox improvements
Added
Copy()methods for deep copying:data []byteslices)Buffer Management Strategy
ReadFullBoxreturns slice view of buffer (no copy for performance)ResetBuffer()explicitly clears buffer after parsingReadFullBoxResetBuffer()called after seek to avoid corruptionDemonstration: stream-encrypt example
New
examples/stream-encryptapplication demonstrates the API in practice:GetSampleRange()Testing
mp4_testpackage)Files Changed
mp4/stream.go(+607 lines) - StreamFile APImp4/stream_test.go(+435 lines) - Streaming API testsmp4/boxseekreader.go(+357 lines) - Seekable wrapper for non-seekable streamsmp4/boxseekreader_test.go(+513 lines) - BoxSeekReader testsmp4/ftyp.go,mp4/styp.go- Added Copy() methodsexamples/stream-encrypt/*(+1149 lines) - Demonstration applicationRelated