Skip to content

Commit

Permalink
Add colr box to video sample description box
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanilagy committed Nov 22, 2024
1 parent 3e62b18 commit 882b068
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 8 deletions.
41 changes: 40 additions & 1 deletion build/mp4-muxer.js

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

4 changes: 2 additions & 2 deletions build/mp4-muxer.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/mp4-muxer.min.mjs

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion build/mp4-muxer.mjs

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mp4-muxer",
"version": "5.1.3",
"version": "5.1.4",
"description": "MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.",
"main": "./build/mp4-muxer.js",
"module": "./build/mp4-muxer.mjs",
Expand Down
34 changes: 33 additions & 1 deletion src/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,39 @@ export const videoSampleDescription = (
u16(0x0018), // Depth
i16(0xffff) // Pre-defined
], [
VIDEO_CODEC_TO_CONFIGURATION_BOX[track.info.codec](track)
VIDEO_CODEC_TO_CONFIGURATION_BOX[track.info.codec](track),
track.info.decoderConfig.colorSpace ? colr(track) : null
]);

// These maps are taken from https://www.matroska.org/technical/elements.html,
// which references the tables in ITU-T H.273 - they should apply here.

const COLOR_PRIMARIES_MAP: Record<VideoColorPrimaries, number> = {
'bt709': 1, // ITU-R BT.709
'bt470bg': 5, // ITU-R BT.470BG
'smpte170m': 6 // ITU-R BT.601 525 - SMPTE 170M
};

const TRANSFER_CHARACTERISTICS_MAP: Record<VideoTransferCharacteristics, number> = {
'bt709': 1, // ITU-R BT.709
'smpte170m': 6, // SMPTE 170M
'iec61966-2-1': 13 // IEC 61966-2-1
};

const MATRIX_COEFFICIENTS_MAP: Record<VideoMatrixCoefficients, number> = {
'rgb': 0, // Identity
'bt709': 1, // ITU-R BT.709
'bt470bg': 5, // ITU-R BT.470BG
'smpte170m': 6 // SMPTE 170M
};

/** Colour Information Box: Specifies the colour space of the video. */
export const colr = (track: VideoTrack) => box('colr', [
ascii('nclx'), // Colour type
u16(COLOR_PRIMARIES_MAP[track.info.decoderConfig.colorSpace.primaries]), // Colour primaries
u16(TRANSFER_CHARACTERISTICS_MAP[track.info.decoderConfig.colorSpace.transfer]), // Transfer characteristics
u16(MATRIX_COEFFICIENTS_MAP[track.info.decoderConfig.colorSpace.matrix]), // Matrix coefficients
u8((track.info.decoderConfig.colorSpace.fullRange ? 1 : 0) << 7) // Full range flag
]);

/** AVC Configuration Box: Provides additional information to the decoder. */
Expand Down

0 comments on commit 882b068

Please sign in to comment.