183 lines
5.9 KiB
TypeScript
183 lines
5.9 KiB
TypeScript
// Metro module 4754 (f4755).
|
|
import { VideoCompressionQuality } from "../../user_settings/UnsyncedUserSettingsStore";
|
|
import Logger from "../../debug/Logger";
|
|
let c2907_1 = new Logger("VideoUploadUtils.tsx");
|
|
class VideoQualityTarget {
|
|
constructor(a0, a1, a2) {
|
|
this.value = a0;
|
|
this.targetResolution = a1;
|
|
this.targetBitrate = a2;
|
|
}
|
|
toString() {
|
|
return this.value;
|
|
}
|
|
}
|
|
const VERY_LOW = {
|
|
__proto__: VideoQualityTarget.prototype
|
|
};
|
|
VERY_LOW.value = "very_low";
|
|
VERY_LOW.targetResolution = 360;
|
|
VERY_LOW.targetBitrate = 800000;
|
|
VideoQualityTarget.VERY_LOW = VERY_LOW;
|
|
const LOW = {
|
|
__proto__: VideoQualityTarget.prototype
|
|
};
|
|
LOW.value = "low";
|
|
LOW.targetResolution = 360;
|
|
LOW.targetBitrate = 1200000;
|
|
VideoQualityTarget.LOW = LOW;
|
|
const MEDIUM = {
|
|
__proto__: VideoQualityTarget.prototype
|
|
};
|
|
MEDIUM.value = "medium";
|
|
MEDIUM.targetResolution = 480;
|
|
MEDIUM.targetBitrate = 1800000;
|
|
VideoQualityTarget.MEDIUM = MEDIUM;
|
|
const HIGH = {
|
|
__proto__: VideoQualityTarget.prototype
|
|
};
|
|
HIGH.value = "high";
|
|
HIGH.targetResolution = 720;
|
|
HIGH.targetBitrate = 2250000;
|
|
VideoQualityTarget.HIGH = HIGH;
|
|
const VERY_HIGH = {
|
|
__proto__: VideoQualityTarget.prototype
|
|
};
|
|
VERY_HIGH.value = "very_high";
|
|
VERY_HIGH.targetResolution = 1080;
|
|
VERY_HIGH.targetBitrate = 7000000;
|
|
VideoQualityTarget.VERY_HIGH = VERY_HIGH;
|
|
VideoQualityTarget.fromCompressionQuality = function fromCompressionQuality(a0) {
|
|
let VERY_LOW;
|
|
if (VideoCompressionQuality.VERY_LOW === a0) {
|
|
VERY_LOW = VideoQualityTarget.VERY_LOW;
|
|
} else if (VideoCompressionQuality.LOW === a0) {
|
|
VERY_LOW = VideoQualityTarget.LOW;
|
|
} else if (VideoCompressionQuality.MEDIUM === a0) {
|
|
VERY_LOW = VideoQualityTarget.MEDIUM;
|
|
} else if (VideoCompressionQuality.HIGH === a0) {
|
|
VERY_LOW = VideoQualityTarget.HIGH;
|
|
} else {
|
|
if (VideoCompressionQuality.VERY_HIGH !== a0) {
|
|
throw new Error(`Unknown compression quality: ${a0}`);
|
|
}
|
|
VERY_LOW = VideoQualityTarget.VERY_HIGH;
|
|
}
|
|
return VERY_LOW;
|
|
};
|
|
const r56 = {
|
|
bitrateFloor: 300000,
|
|
createHDR: false,
|
|
frameRate: 30,
|
|
keyFrameIntervalSeconds: 2,
|
|
rotationDegrees: 0,
|
|
skipVideoTranscode: false,
|
|
targetBitrate: VideoQualityTarget.MEDIUM.targetBitrate,
|
|
targetHeight: 480,
|
|
targetWidth: 640,
|
|
useHEVC: false,
|
|
videoQuality: VideoQualityTarget.MEDIUM,
|
|
hevcIsSupported: false,
|
|
useTranscodedVideoForMovSources: true,
|
|
transmuxLivePhotos: true,
|
|
progressUpdateGranularity: 10
|
|
};
|
|
export { VideoQualityTarget };
|
|
export { r56 as DEFAULT_VIDEO_ENCODING_CONFIG };
|
|
export function calculateTargetDimensions(a0, a1) {
|
|
let r15, r19;
|
|
const r11 = a0.width / a0.height;
|
|
if (a0.width > a0.height) {
|
|
const r23 = Math.min(a1, a0.height);
|
|
r15 = Math.round(r23 * r11);
|
|
r19 = r23;
|
|
} else {
|
|
r15 = Math.min(a1, a0.width);
|
|
r19 = Math.round(r15 / r11);
|
|
}
|
|
return {
|
|
width: r15 % 2 !== 0 ? r15 + 1 : r15,
|
|
height: r19 % 2 !== 0 ? r19 + 1 : r19
|
|
};
|
|
}
|
|
export function canSkipVideoTranscode(a0, a1, a2, a3) {
|
|
let r23, r27;
|
|
if (a2 != null && a3 != null && a2 > a3) {
|
|
return false;
|
|
}
|
|
const targetResolution = a0.targetResolution;
|
|
const r11 = a1.width / a1.height;
|
|
if (a1.width > a1.height) {
|
|
const r30 = Math.min(targetResolution, a1.height);
|
|
r23 = Math.round(r30 * r11);
|
|
r27 = r30;
|
|
} else {
|
|
r23 = Math.min(targetResolution, a1.width);
|
|
r27 = Math.round(r23 / r11);
|
|
}
|
|
const r34 = r23 % 2 !== 0 ? r23 + 1 : r23;
|
|
const r37 = r27 % 2 !== 0 ? r27 + 1 : r27;
|
|
const r43 = Math.round(a1.width);
|
|
const r47 = Math.round(a1.height);
|
|
const r4 = r43 <= r34 && r47 <= r37;
|
|
const r6 = a1.bitRate <= a0.targetBitrate;
|
|
return !((r4 ? !r6 : !r4) || a1.format == null || a1.format.match(/(avc1|hvc1|video\/(avc|hevc))/i) === null);
|
|
}
|
|
export function logSourceMetadata(a0) {
|
|
const r1 = a0.format != null;
|
|
let r8 = "unknown";
|
|
if (r1) {
|
|
let r12 = ({
|
|
hvc1: "hvc1 (HEVC)",
|
|
avc1: "avc1 (H.264)"
|
|
})[a0.format];
|
|
if (r12 == null) {
|
|
r12 = a0.format;
|
|
}
|
|
r8 = r12;
|
|
}
|
|
c2907_1.info("Video Source Metadata:");
|
|
c2907_1.info(`- Codec: ${r8}`);
|
|
c2907_1.info(`- Dimensions: ${a0.width}x${a0.height}`);
|
|
c2907_1.info(`- Bitrate: ${a0.bitRate} bps`);
|
|
c2907_1.info(`- Frame Rate: ${a0.frameRate} fps`);
|
|
c2907_1.info("- HDR: " + (a0.isHDRContent ? "Yes" : "No"));
|
|
c2907_1.info(`- Rotation Degrees: ${a0.rotationDegrees}`);
|
|
c2907_1.info(`- Profile: ${a0.sourceProfile}`);
|
|
c2907_1.info(`- Level: ${a0.sourceLevel}`);
|
|
c2907_1.info(`- Duration: ${a0.durationMs} ms`);
|
|
}
|
|
export function logEncoderSettings(a0) {
|
|
c2907_1.info("Encoder Video Quality Settings:");
|
|
const videoQuality = a0.videoQuality;
|
|
c2907_1.info(`- Compression Quality: ${videoQuality == null ? void 0 : videoQuality.toString()}`);
|
|
c2907_1.info(`- Compression Quality Target Resolution: ${a0.videoQuality?.targetResolution}p`);
|
|
c2907_1.info(`- Compression Quality Max Bitrate: ${a0.videoQuality?.targetBitrate} bps`);
|
|
c2907_1.info("Encoder Video Transcoding Settings:");
|
|
if (a0.skipVideoTranscode) {
|
|
c2907_1.info("- Skip Video Transcode: Yes");
|
|
} else {
|
|
c2907_1.info("- Codec: " + (a0.useHEVC ? "hvc1 (HEVC)" : "avc1 (H.264)"));
|
|
c2907_1.info(`- Dimensions: ${a0.targetWidth}x${a0.targetHeight}`);
|
|
c2907_1.info(`- Bitrate: ${a0.targetBitrate} bps`);
|
|
c2907_1.info(`- Frame Rate: ${a0.frameRate} fps`);
|
|
c2907_1.info(`- Key Frame Interval: ${a0.keyFrameIntervalSeconds} seconds`);
|
|
const createHDR = a0.createHDR;
|
|
let r83 = "No";
|
|
c2907_1.info("- Create HDR: " + (createHDR ? "Yes" : "No"));
|
|
c2907_1.info(`- Rotation Degrees: ${a0.rotationDegrees}`);
|
|
if (a0.hevcIsSupported) {
|
|
r83 = "Yes";
|
|
}
|
|
c2907_1.info("- HEVC Supported: " + r83);
|
|
c2907_1.info(`- Progress Update Granularity: ${a0.progressUpdateGranularity}`);
|
|
}
|
|
}
|
|
export function calculateOptimalBitrate(a0, a1, a2) {
|
|
return Math.min(Math.max(a0.bitRate, a2), a1.targetBitrate);
|
|
}
|
|
export function shouldUseHEVC(a0, a1, a2, a3, a4) {
|
|
const r1 = a1 ? !a2 : !a1;
|
|
return r1 ? !r1 : !((a3 ? a0.rotationDegrees !== 0 : a3) && !a4);
|
|
}
|