Repository navigation
format: mp4 - AV1 films in ISO base media boxes, the index before the pictures #170
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
134bf12
mp4: AV1 films in ISO base media boxes - work in progress
donislawdev 060663b
mp4: the stop guard asks each pass, and the reader refuses a table it…
donislawdev 0c7d025
mp4: golden films, the allocation ceiling measured, free boxes past 2…
donislawdev 17cde6e
mp4: the site, the social card, the stored screens, README and change…
donislawdev 5ac206a
mp4: the WebM reader of the film guards in a file of its own, beside …
donislawdev 1e1432e
mp4: the guard's reader wraps the error it was given (errorlint)
donislawdev e066ebf
mp4: review of #170 - the checker refuses chunks holding more samples…
donislawdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Package isobmff is what the formats built of ISO base media boxes share: | ||
| // the header every box starts with, and the free boxes their padding is | ||
| // carried in. AVIF and JPEG XL each held a copy of the same padding, and MP4 | ||
| // would have been the third (docs/MP4-2026-10-07.md section 4). | ||
| package isobmff | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/binary" | ||
| "io" | ||
| "math/rand/v2" | ||
|
|
||
| "github.com/donislawdev/TestingFilesGenerator/internal/core" | ||
| ) | ||
|
|
||
| // BoxHeader is what every box costs before its content: a four byte length | ||
| // and a four character name. | ||
| const BoxHeader = 8 | ||
|
|
||
| // maxFreePayload keeps a single box inside the four byte length field the | ||
| // container uses by default. Anything larger is spread over several boxes, | ||
| // which is measured to work rather than assumed. | ||
| const maxFreePayload = 1<<31 - BoxHeader | ||
|
|
||
| // WriteBoxHeader writes the header of a box of kind whose content is payload | ||
| // bytes long, in the four byte length every box here uses. | ||
| func WriteBoxHeader(w io.Writer, kind string, payload int64) error { | ||
| var b [BoxHeader]byte | ||
| binary.BigEndian.PutUint32(b[:4], uint32(BoxHeader+payload)) | ||
| copy(b[4:], kind) | ||
| _, err := w.Write(b[:]) | ||
| return err | ||
| } | ||
|
|
||
| // WritePadding fills total bytes with free boxes, without ever holding their | ||
| // content - bytes drawn from seed, so the same file comes out every time. | ||
| // total is at least BoxHeader, because no box is shorter. | ||
| // | ||
| // Several boxes rather than one when the padding is larger than a box length | ||
| // can say. The step below keeps the leftover from landing between one and | ||
| // seven bytes, which no box could then carry. | ||
| func WritePadding(ctx context.Context, w io.Writer, seed uint64, total int64) error { | ||
| rng := core.NewRand(seed) | ||
| buf := make([]byte, 32*1024) | ||
|
|
||
| for total > 0 { | ||
| payload := nextPayload(total) | ||
| if err := WriteBoxHeader(w, "free", payload); err != nil { | ||
| return err | ||
| } | ||
| if err := writeFiller(ctx, w, buf, rng, payload); err != nil { | ||
| return err | ||
| } | ||
| total -= BoxHeader + payload | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // nextPayload is how much filler the next free box carries. | ||
| // | ||
| // A box states its length in four bytes, so padding larger than that is spread | ||
| // over several boxes. The step down is what keeps the leftover from landing | ||
| // between one and seven bytes, which no box could then carry. | ||
| func nextPayload(total int64) int64 { | ||
| payload := total - BoxHeader | ||
| if payload <= maxFreePayload { | ||
| return payload | ||
| } | ||
| payload = maxFreePayload | ||
| if total-BoxHeader-payload < BoxHeader { | ||
| payload -= BoxHeader | ||
| } | ||
| return payload | ||
| } | ||
|
|
||
| func writeFiller(ctx context.Context, w io.Writer, buf []byte, rng *rand.Rand, size int64) error { | ||
| for left := size; left > 0; { | ||
| n := int64(len(buf)) | ||
| if left < n { | ||
| n = left | ||
| } | ||
| select { | ||
| case <-ctx.Done(): | ||
| return ctx.Err() | ||
| default: | ||
| } | ||
| core.FillRandomLE(buf[:n], rng) | ||
| if _, err := w.Write(buf[:n]); err != nil { | ||
| return err | ||
| } | ||
| left -= n | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.