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

fix(toDash): Add missing transfer characteristics for h264 streams #573

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
42 changes: 27 additions & 15 deletions src/utils/StreamingInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,26 +354,38 @@ function getColorInfo(format: Format) {
// The player.js file was also helpful

const color_info = format.color_info;
const primaries =
color_info?.primaries ? COLOR_PRIMARIES[color_info.primaries] : undefined;
let primaries;
let transfer_characteristics;
let matrix_coefficients;

const transfer_characteristics =
color_info?.transfer_characteristics ? COLOR_TRANSFER_CHARACTERISTICS[color_info.transfer_characteristics] : undefined;
if (color_info) {
if (color_info.primaries) {
primaries = COLOR_PRIMARIES[color_info.primaries];
}

if (color_info.transfer_characteristics) {
transfer_characteristics = COLOR_TRANSFER_CHARACTERISTICS[color_info.transfer_characteristics];
} else if (getStringBetweenStrings(format.mime_type, 'codecs="', '"')?.startsWith('avc1')) {
// YouTube's h264 streams always seem to be SDR, so this is a pretty safe bet.
transfer_characteristics = COLOR_TRANSFER_CHARACTERISTICS.BT709;
}

const matrix_coefficients =
color_info?.matrix_coefficients ? COLOR_MATRIX_COEFFICIENTS[color_info.matrix_coefficients] : undefined;
if (color_info.matrix_coefficients) {
matrix_coefficients = COLOR_MATRIX_COEFFICIENTS[color_info.matrix_coefficients];

if (color_info?.matrix_coefficients && !matrix_coefficients) {
const url = new URL(format.url as string);
if (!matrix_coefficients) {
const url = new URL(format.url as string);

const anonymisedFormat = JSON.parse(JSON.stringify(format));
anonymisedFormat.url = 'REDACTED';
anonymisedFormat.signature_cipher = 'REDACTED';
anonymisedFormat.cipher = 'REDACTED';
const anonymisedFormat = JSON.parse(JSON.stringify(format));
anonymisedFormat.url = 'REDACTED';
anonymisedFormat.signature_cipher = 'REDACTED';
anonymisedFormat.cipher = 'REDACTED';

console.warn(`YouTube.js toDash(): Unknown matrix coefficients "${color_info.matrix_coefficients}", the DASH manifest is still usuable without this.\n`
+ `Please report it at ${Platform.shim.info.bugs_url} so we can add support for it.\n`
+ `Innertube client: ${url.searchParams.get('c')}\nformat:`, anonymisedFormat);
console.warn(`YouTube.js toDash(): Unknown matrix coefficients "${color_info.matrix_coefficients}", the DASH manifest is still usuable without this.\n`
+ `Please report it at ${Platform.shim.info.bugs_url} so we can add support for it.\n`
+ `Innertube client: ${url.searchParams.get('c')}\nformat:`, anonymisedFormat);
}
}
}

const info: ColorInfo = {
Expand Down
Loading