Skip to content

Commit

Permalink
Merge pull request #47 from boxcast/composition-time-offset
Browse files Browse the repository at this point in the history
Track (optional) composition time offsets for video chunks and write them to the target appropriately
  • Loading branch information
Vanilagy authored Jun 12, 2024
2 parents bba6ec9 + 0013e1d commit 08ad562
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 158 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ interface MuxerOptions {
| 'fragmented'
| { expectedVideoChunks?: number, expectedAudioChunks?: number }

firstTimestampBehavior?: 'strict' | 'offset'
firstTimestampBehavior?: 'strict' | 'offset' | 'cross-track-offset'
}
```
Codecs currently supported by this library are AVC/H.264, HEVC/H.265, VP9 and AV1 for video, and AAC and Opus for audio.
Expand Down Expand Up @@ -240,8 +240,10 @@ timestamps must start with 0 to ensure proper playback. However, when directly p
from a MediaTrackStream into the encoder and then the muxer, the timestamps are usually relative to the age of
the document or the computer's clock, which is typically not what we want. Handling of these timestamps must be
set explicitly:
- Use `'offset'` to offset the timestamp of each video track by that track's first chunk's timestamp. This way, it
- Use `'offset'` to offset the timestamp of each track by that track's first chunk's timestamp. This way, it
starts at 0.
- Use `'cross-track-offset'` to offset the timestamp of each track by the _minimum of all tracks' first chunk timestamp_.
This works like `'offset'`, but should be used when the all tracks use the same timebase.
### Muxing media chunks
Then, with VideoEncoder and AudioEncoder set up, send encoded chunks to the muxer using the following methods:
Expand Down Expand Up @@ -280,7 +282,8 @@ addVideoChunkRaw(
type: 'key' | 'delta',
timestamp: number, // in microseconds
duration: number, // in microseconds
meta?: EncodedVideoChunkMetadata
meta?: EncodedVideoChunkMetadata,
compositionTimeOffset: number // in microseconds
): void;

addAudioChunkRaw(
Expand Down
25 changes: 19 additions & 6 deletions build/mp4-muxer.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 08ad562

Please sign in to comment.