2020-07-16 22:19:09 +02:00
|
|
|
import globalize from 'globalize';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
export function getVideoQualityOptions(options) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const maxStreamingBitrate = options.currentMaxBitrate;
|
|
|
|
let videoWidth = options.videoWidth;
|
|
|
|
const videoHeight = options.videoHeight;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
// If the aspect ratio is less than 16/9 (1.77), set the width as if it were pillarboxed.
|
|
|
|
// 4:3 1440x1080 -> 1920x1080
|
|
|
|
if (videoWidth / videoHeight < 16 / 9) {
|
|
|
|
videoWidth = videoHeight * (16 / 9);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const maxAllowedWidth = videoWidth || 4096;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const qualityOptions = [];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
if (maxAllowedWidth >= 3800) {
|
|
|
|
qualityOptions.push({ name: '4K - 120 Mbps', maxHeight: 2160, bitrate: 120000000 });
|
|
|
|
qualityOptions.push({ name: '4K - 100 Mbps', maxHeight: 2160, bitrate: 100000000 });
|
|
|
|
qualityOptions.push({ name: '4K - 80 Mbps', maxHeight: 2160, bitrate: 80000000 });
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
// Some 1080- videos are reported as 1912?
|
|
|
|
if (maxAllowedWidth >= 1900) {
|
|
|
|
qualityOptions.push({ name: '1080p - 60 Mbps', maxHeight: 1080, bitrate: 60000000 });
|
|
|
|
qualityOptions.push({ name: '1080p - 50 Mbps', maxHeight: 1080, bitrate: 50000000 });
|
|
|
|
qualityOptions.push({ name: '1080p - 40 Mbps', maxHeight: 1080, bitrate: 40000000 });
|
|
|
|
qualityOptions.push({ name: '1080p - 30 Mbps', maxHeight: 1080, bitrate: 30000000 });
|
|
|
|
qualityOptions.push({ name: '1080p - 25 Mbps', maxHeight: 1080, bitrate: 25000000 });
|
|
|
|
qualityOptions.push({ name: '1080p - 20 Mbps', maxHeight: 1080, bitrate: 20000000 });
|
|
|
|
qualityOptions.push({ name: '1080p - 15 Mbps', maxHeight: 1080, bitrate: 15000000 });
|
|
|
|
qualityOptions.push({ name: '1080p - 10 Mbps', maxHeight: 1080, bitrate: 10000001 });
|
|
|
|
qualityOptions.push({ name: '1080p - 8 Mbps', maxHeight: 1080, bitrate: 8000001 });
|
|
|
|
qualityOptions.push({ name: '1080p - 6 Mbps', maxHeight: 1080, bitrate: 6000001 });
|
|
|
|
qualityOptions.push({ name: '1080p - 5 Mbps', maxHeight: 1080, bitrate: 5000001 });
|
|
|
|
qualityOptions.push({ name: '1080p - 4 Mbps', maxHeight: 1080, bitrate: 4000002 });
|
|
|
|
} else if (maxAllowedWidth >= 1260) {
|
|
|
|
qualityOptions.push({ name: '720p - 10 Mbps', maxHeight: 720, bitrate: 10000000 });
|
|
|
|
qualityOptions.push({ name: '720p - 8 Mbps', maxHeight: 720, bitrate: 8000000 });
|
|
|
|
qualityOptions.push({ name: '720p - 6 Mbps', maxHeight: 720, bitrate: 6000000 });
|
|
|
|
qualityOptions.push({ name: '720p - 5 Mbps', maxHeight: 720, bitrate: 5000000 });
|
|
|
|
} else if (maxAllowedWidth >= 620) {
|
|
|
|
qualityOptions.push({ name: '480p - 4 Mbps', maxHeight: 480, bitrate: 4000001 });
|
|
|
|
qualityOptions.push({ name: '480p - 3 Mbps', maxHeight: 480, bitrate: 3000001 });
|
|
|
|
qualityOptions.push({ name: '480p - 2.5 Mbps', maxHeight: 480, bitrate: 2500000 });
|
|
|
|
qualityOptions.push({ name: '480p - 2 Mbps', maxHeight: 480, bitrate: 2000001 });
|
|
|
|
qualityOptions.push({ name: '480p - 1.5 Mbps', maxHeight: 480, bitrate: 1500001 });
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
if (maxAllowedWidth >= 1260) {
|
|
|
|
qualityOptions.push({ name: '720p - 4 Mbps', maxHeight: 720, bitrate: 4000000 });
|
|
|
|
qualityOptions.push({ name: '720p - 3 Mbps', maxHeight: 720, bitrate: 3000000 });
|
|
|
|
qualityOptions.push({ name: '720p - 2 Mbps', maxHeight: 720, bitrate: 2000000 });
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
// The extra 1 is because they're keyed off the bitrate value
|
|
|
|
qualityOptions.push({ name: '720p - 1.5 Mbps', maxHeight: 720, bitrate: 1500000 });
|
|
|
|
qualityOptions.push({ name: '720p - 1 Mbps', maxHeight: 720, bitrate: 1000001 });
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
qualityOptions.push({ name: '480p - 1 Mbps', maxHeight: 480, bitrate: 1000000 });
|
|
|
|
qualityOptions.push({ name: '480p - 720 kbps', maxHeight: 480, bitrate: 720000 });
|
|
|
|
qualityOptions.push({ name: '480p - 420 kbps', maxHeight: 480, bitrate: 420000 });
|
|
|
|
qualityOptions.push({ name: '360p', maxHeight: 360, bitrate: 400000 });
|
|
|
|
qualityOptions.push({ name: '240p', maxHeight: 240, bitrate: 320000 });
|
|
|
|
qualityOptions.push({ name: '144p', maxHeight: 144, bitrate: 192000 });
|
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const autoQualityOption = {
|
2020-07-16 22:19:09 +02:00
|
|
|
name: globalize.translate('Auto'),
|
|
|
|
bitrate: 0,
|
|
|
|
selected: options.isAutomaticBitrateEnabled
|
|
|
|
};
|
|
|
|
|
|
|
|
if (options.enableAuto) {
|
|
|
|
qualityOptions.push(autoQualityOption);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxStreamingBitrate) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let selectedIndex = -1;
|
|
|
|
for (let i = 0, length = qualityOptions.length; i < length; i++) {
|
|
|
|
const option = qualityOptions[i];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
if (selectedIndex === -1 && option.bitrate <= maxStreamingBitrate) {
|
|
|
|
selectedIndex = i;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
if (selectedIndex === -1) {
|
|
|
|
selectedIndex = qualityOptions.length - 1;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const currentQualityOption = qualityOptions[selectedIndex];
|
2020-07-16 22:19:09 +02:00
|
|
|
|
|
|
|
if (!options.isAutomaticBitrateEnabled) {
|
|
|
|
currentQualityOption.selected = true;
|
|
|
|
} else {
|
|
|
|
autoQualityOption.autoText = currentQualityOption.name;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-07-16 22:19:09 +02:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
return qualityOptions;
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
export function getAudioQualityOptions(options) {
|
2020-10-07 21:12:14 +09:00
|
|
|
const maxStreamingBitrate = options.currentMaxBitrate;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const qualityOptions = [];
|
2020-07-16 22:19:09 +02:00
|
|
|
|
|
|
|
qualityOptions.push({ name: '2 Mbps', bitrate: 2000000 });
|
|
|
|
qualityOptions.push({ name: '1.5 Mbps', bitrate: 1500000 });
|
|
|
|
qualityOptions.push({ name: '1 Mbps', bitrate: 1000000 });
|
|
|
|
qualityOptions.push({ name: '320 kbps', bitrate: 320000 });
|
|
|
|
qualityOptions.push({ name: '256 kbps', bitrate: 256000 });
|
|
|
|
qualityOptions.push({ name: '192 kbps', bitrate: 192000 });
|
|
|
|
qualityOptions.push({ name: '128 kbps', bitrate: 128000 });
|
|
|
|
qualityOptions.push({ name: '96 kbps', bitrate: 96000 });
|
|
|
|
qualityOptions.push({ name: '64 kbps', bitrate: 64000 });
|
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const autoQualityOption = {
|
2020-07-16 22:19:09 +02:00
|
|
|
name: globalize.translate('Auto'),
|
|
|
|
bitrate: 0,
|
|
|
|
selected: options.isAutomaticBitrateEnabled
|
|
|
|
};
|
|
|
|
|
|
|
|
if (options.enableAuto) {
|
|
|
|
qualityOptions.push(autoQualityOption);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
if (maxStreamingBitrate) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let selectedIndex = -1;
|
|
|
|
for (let i = 0, length = qualityOptions.length; i < length; i++) {
|
|
|
|
const option = qualityOptions[i];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
if (selectedIndex === -1 && option.bitrate <= maxStreamingBitrate) {
|
|
|
|
selectedIndex = i;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
if (selectedIndex === -1) {
|
|
|
|
selectedIndex = qualityOptions.length - 1;
|
|
|
|
}
|
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const currentQualityOption = qualityOptions[selectedIndex];
|
2020-07-16 22:19:09 +02:00
|
|
|
|
|
|
|
if (!options.isAutomaticBitrateEnabled) {
|
|
|
|
currentQualityOption.selected = true;
|
|
|
|
} else {
|
|
|
|
autoQualityOption.autoText = currentQualityOption.name;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-16 22:19:09 +02:00
|
|
|
return qualityOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getVideoQualityOptions,
|
|
|
|
getAudioQualityOptions
|
|
|
|
};
|