UNPKG

@codenoobforreal/clitools

Version:

CLI tool for video processing (H.265/HEVC encoding & QuickTime compatibility) using FFmpeg, and batch lossless image compression with format preservation

140 lines 3.89 kB
export class FFmpegCommandBuilder { globalOptions = ["-hide_banner", "-loglevel", "error"]; inputs = []; outputOptions = []; outputFile = ""; addProgressReporting(progressOutput = "pipe:2") { this.globalOptions.push("-progress", progressOutput); return this; } addInput(inputPath) { this.inputs.push("-i", inputPath); return this; } setVideoEncoder(encoder) { this.outputOptions.push("-c:v", encoder); return this; } setVideoTag(tag) { this.outputOptions.push("-tag:v", tag); return this; } copyVideo() { this.outputOptions.push("-c:v", "copy"); return this; } setCrf(crf) { this.outputOptions.push("-crf", crf.toString()); return this; } setPreset(preset = "medium") { this.outputOptions.push("-preset", preset); return this; } setPixFmt(fmt = "yuv420p") { this.outputOptions.push("-pix_fmt", fmt); return this; } setOutputFormat(format) { this.outputOptions.push("-f", format); return this; } copyAudio() { this.outputOptions.push("-c:a", "copy"); return this; } setOutput(outputPath) { this.outputFile = outputPath; return this; } build() { return [ ...this.globalOptions, ...this.inputs, ...this.outputOptions, this.outputFile, ]; } } export class FFmpegH265CommandBuilder extends FFmpegCommandBuilder { x265Params = []; /** TODO:yuv422p and yuv444p mapping might be wrong */ pixFmtToProfileMap = { yuv420p: "main", yuv420p10le: "main10", yuv420p12le: "main12", yuv422p: "main", yuv422p10le: "main422-10", yuv422p12le: "main422-12", yuv444p: "main", yuv444p10le: "main444-10", yuv444p12le: "main444-12", }; constructor() { super(); super.setVideoEncoder("libx265"); } // eslint-disable-next-line @typescript-eslint/no-unused-vars setVideoEncoder(_encode) { return this; } setLogLevel(level = "error") { this.x265Params.push(`log-level=${level}`); return this; } setProfileByPixFmt(pix_fmt = "yuv420p") { const profile = this.pixFmtToProfileMap[pix_fmt]; if (profile) { this.x265Params.push(`profile=${profile}`); return this; } // let encode decided return this; } setInputDepth(depth = 8) { this.x265Params.push(`input-depth=${depth}`); return this; } /** * will derive the output bit depth from the profile name if --output-depth is not specified. */ setOutputDepth(depth) { this.x265Params.push(`output-depth=${depth}`); return this; } applyX265Params() { if (this.x265Params.length > 0) { this.outputOptions.push("-x265-params", this.x265Params.join(":")); } return this; } } export class FFprobeCommandBuilder { globalOptions = []; outputFormat = []; inputPath = ""; setLogLevel(level = "error") { this.globalOptions.push("-v", level); return this; } selectStream(streamType = "v:0") { this.globalOptions.push("-select_streams", streamType); return this; } showEntries(entry = "stream:format") { this.globalOptions.push("-show_entries", entry); return this; } setOutputFormat(formatOptions) { this.outputFormat.push("-of", formatOptions); return this; } setInput(inputPath) { this.inputPath = inputPath; return this; } build() { return [...this.globalOptions, ...this.outputFormat, this.inputPath]; } } //# sourceMappingURL=command-builder.js.map