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

feat: Parse vpcC and av1C boxes #6157

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/media/segment_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,14 @@ shaka.media.SegmentUtils = class {
baseBox = box.name;
Mp4Parser.visualSampleEntry(box);
})
.box('vp09', codecBoxParser)
.box('av01', codecBoxParser)
.box('vp09', (box) => {
baseBox = box.name;
Mp4Parser.visualSampleEntry(box);
})
.box('av01', (box) => {
baseBox = box.name;
Mp4Parser.visualSampleEntry(box);
})
.box('avcC', (box) => {
let codecBase = baseBox || '';
switch (baseBox) {
Expand Down Expand Up @@ -324,6 +330,20 @@ shaka.media.SegmentUtils = class {
videoCodecs.push(parsedDVCCBox.codec);
hasVideo = true;
})
.fullBox('vpcC', (box) => {
const codecBase = baseBox || '';
const parsedVPCCBox = shaka.util.Mp4BoxParsers.parseVPCC(
codecBase, box.reader, box.name);
videoCodecs.push(parsedVPCCBox.codec);
hasVideo = true;
})
.box('av1C', (box) => {
const codecBase = baseBox || '';
const parsedAV1CBox = shaka.util.Mp4BoxParsers.parseAV1C(
codecBase, box.reader, box.name);
videoCodecs.push(parsedAV1CBox.codec);
hasVideo = true;
})

// This signals an encrypted sample, which we can go inside of to
// find the codec used.
Expand Down
83 changes: 82 additions & 1 deletion lib/util/mp4_box_parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ shaka.util.Mp4BoxParsers = class {
* @param {string} codecBase
* @param {!shaka.util.DataViewReader} reader
* @param {string} boxName
* @return {!shaka.util.ParsedHVCCBox}
* @return {!shaka.util.ParsedDVCCBox}
*/
static parseDVCC(codecBase, reader, boxName) {
reader.skip(2); // Skip "dv_version_major" and "dv_version_minor"
Expand All @@ -417,6 +417,65 @@ shaka.util.Mp4BoxParsers = class {
return {codec};
}

/**
* Parses a VPCC box.
* @param {string} codecBase
* @param {!shaka.util.DataViewReader} reader
* @param {string} boxName
* @return {!shaka.util.ParsedVPCCBox}
*/
static parseVPCC(codecBase, reader, boxName) {
const profile = reader.readUint8();
const level = reader.readUint8();
const bitDepth = (reader.readUint8() >> 4) & 0x0f;
const codec = codecBase + '.' + this.addLeadingZero_(profile) +
'.' + this.addLeadingZero_(level) + '.' + this.addLeadingZero_(bitDepth);

return {codec};
}

/**
* Parses a AV1C box.
* @param {string} codecBase
* @param {!shaka.util.DataViewReader} reader
* @param {string} boxName
* @return {!shaka.util.ParsedAV1CBox}
*/
static parseAV1C(codecBase, reader, boxName) {
// More info https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox-syntax
reader.skip(1); // Skip "marker" and "version"
const secondByte = reader.readUint8();
const thirdByte = reader.readUint8();
const profile = secondByte >>> 5;
const level = secondByte & 0x1f;
const tierFlag = thirdByte >>> 7 ? 'H' : 'M';
const highBitDepth = (thirdByte & 0x40) >> 6;
const twelveBit = (thirdByte & 0x20) >> 5;
const bitDepth = profile === 2 && highBitDepth ?
(twelveBit ? 12 : 10) : (highBitDepth ? 10 : 8);
const monochrome = (thirdByte & 0x10) >> 4;
const chromaSubsamplingX = (thirdByte & 0x08) >> 3;
const chromaSubsamplingY = (thirdByte & 0x04) >> 2;
const chromaSamplePosition = thirdByte & 0x03;
// TODO: parse color_description_present_flag
// default it to BT.709/limited range for now
const colorPrimaries = 1;
const transferCharacteristics = 1;
const matrixCoefficients = 1;
const videoFullRangeFlag = 0;
const codec = codecBase + '.' + profile +
'.' + this.addLeadingZero_(level) + tierFlag +
'.' + this.addLeadingZero_(bitDepth) +
'.' + monochrome +
'.' + chromaSubsamplingX + chromaSubsamplingY + chromaSamplePosition +
'.' + this.addLeadingZero_(colorPrimaries) +
'.' + this.addLeadingZero_(transferCharacteristics) +
'.' + this.addLeadingZero_(matrixCoefficients) +
'.' + videoFullRangeFlag;

return {codec};
}

/**
* Parses a FRMA box.
* @param {!shaka.util.DataViewReader} reader
Expand Down Expand Up @@ -697,6 +756,28 @@ shaka.util.ParsedHVCCBox;
*/
shaka.util.ParsedDVCCBox;

/**
* @typedef {{
* codec: string
* }}
*
* @property {string} codec
*
* @exportDoc
*/
shaka.util.ParsedVPCCBox;

/**
* @typedef {{
* codec: string
* }}
*
* @property {string} codec
*
* @exportDoc
*/
shaka.util.ParsedAV1CBox;

/**
* @typedef {{
* handlerType: string
Expand Down
Loading