diff --git a/src/commandBuilder.ts b/src/commandBuilder.ts index 5fc0f4d..c88b27f 100644 --- a/src/commandBuilder.ts +++ b/src/commandBuilder.ts @@ -1,16 +1,31 @@ import { parsedVideoInfo } from "./types.ts"; import { basename, dirname } from "@std/path"; +import { profile } from "./types.ts"; function escapeFilename(filename: string): string { return filename.replace(/[^a-zA-Z0-9]/g, ""); } +const profiles: Record = { + "DVD": { + "crf": 29, + "preset": 2, + "filmGrain": 5, + }, + "BluRay": { + "crf": 27, + "preset": 2, + "filmGrain": 5, + }, +}; + export function encodingCommandBuilder(videoInfo: parsedVideoInfo): string { let videoName: string | null = null; const videoPath = dirname(videoInfo.filename); if (videoInfo.metadata) { videoName = videoInfo.metadata.title; } + const profile = videoInfo.MPix < 1 ? profiles.DVD : profiles.BluRay; const args = [ "ffmpeg \\\n", "-v", @@ -27,16 +42,12 @@ export function encodingCommandBuilder(videoInfo: parsedVideoInfo): string { "-pix_fmt", "yuv420p10le \\\n", ]; - if (videoInfo.MPix < 1) { - args.push("-crf", "29 \\\n"); - } else { - args.push("-crf", "25 \\\n"); - } + args.push("-crf", profile.crf + " \\\n"); args.push( "-svtav1-params", - "tune=0:film-grain=5:scd=1:film-grain-denoise=1 \\\n", + `tune=0:film-grain=${profile.filmGrain}:scd=1:film-grain-denoise=1 \\\n`, ); - args.push("-preset", "2 \\\n"); + args.push("-preset", profile.preset + " \\\n"); if (videoInfo.isAnamorphic || videoInfo.isInterlaced) { const filter_string: string[] = []; diff --git a/src/types.ts b/src/types.ts index 426c712..210a5e5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -224,3 +224,9 @@ export interface parsedVideoInfo { audioStreams?: parsedAudioStream[]; subtitleStreams?: parsedSubtitleStream[]; } + +export interface profile { + crf: number; + preset: number; + filmGrain: number; +}