The swiss army knife of lossless video/audio editing
encode flac when merging too
Mikael Finstad25113050ab85
diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.tsindex 331f2eb8..4d348234 100644--- a/src/renderer/src/hooks/useFfmpegOperations.ts+++ b/src/renderer/src/hooks/useFfmpegOperations.ts@@ -190,6 +190,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, treaoutFormat,manuallyCopyDisposition: true,fixCodecTag,+ needFlac: true, // https://github.com/mifi/lossless-cut/issues/2636});// Keep this similar to losslessCutSingle()@@ -335,7 +336,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea...flatMap(Object.entries(customTagsByFile[filePath] || []), ([key, value]) => ['-metadata', `${key}=${value}`]),];- const mapStreamsArgs = getMapStreamsArgs({ copyFileStreams: copyFileStreamsFiltered, allFilesMeta, outFormat, areWeCutting, fixCodecTag });+ const mapStreamsArgs = getMapStreamsArgs({ copyFileStreams: copyFileStreamsFiltered, allFilesMeta, outFormat, needFlac: areWeCutting, fixCodecTag });const customParamsArgs = (() => {const ret: string[] = [];@@ -716,8 +717,6 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea// h264/aac_at: No licensing when using HW encoder (Video/Audio Toolbox on Mac)// https://github.com/mifi/lossless-cut/issues/372#issuecomment-810766512- const targetHeight = 400;-switch (video) {case 'hq': {// eslint-disable-next-line unicorn/prefer-ternary@@ -735,6 +734,8 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, treabreak;}case 'lq': {+ const targetHeight = 400;+// eslint-disable-next-line unicorn/prefer-ternaryif (isMac) {videoArgs = ['-vf', `scale=-2:${targetHeight},format=yuv420p`, '-allow_sw', '1', '-sws_flags', 'lanczos', '-vcodec', 'h264', '-b:v', '1500k'];diff --git a/src/renderer/src/util/streams.ts b/src/renderer/src/util/streams.tsindex 241a962b..00e0c9ba 100644--- a/src/renderer/src/util/streams.ts+++ b/src/renderer/src/util/streams.ts@@ -107,13 +107,13 @@ export const isMatroska = (format: string | undefined) => format != null && ['matype GetVideoArgsFn = (a: { streamIndex: number, outputIndex: number }) => string[] | undefined;-function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposition = false, getVideoArgs = () => undefined, areWeCutting, fixCodecTag }: {+function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposition = false, getVideoArgs = () => undefined, needFlac, fixCodecTag }: {stream: LiteFFprobeStream,outputIndex: number,outFormat: string | undefined,manuallyCopyDisposition?: boolean | undefined,getVideoArgs?: GetVideoArgsFn | undefined,- areWeCutting: boolean | undefined,+ needFlac: boolean | undefined,fixCodecTag: FixCodecTagOption | undefined,}) {let args: string[] = [];@@ -170,7 +170,7 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposi// I think DV format only supports PCM_S16LE https://github.com/FFmpeg/FFmpeg/blob/b92028346c35dad837dd1160930435d88bd838b5/libavformat/dvenc.c#L450addCodecArgs('pcm_s16le');addArgs(`-ar:${outputIndex}`, '48000'); // maybe technically not lossless?- } else if (outFormat === 'flac' && areWeCutting && stream.codec_name === 'flac') { // https://github.com/mifi/lossless-cut/issues/1809+ } else if (outFormat === 'flac' && needFlac && stream.codec_name === 'flac') { // https://github.com/mifi/lossless-cut/issues/1809addCodecArgs('flac'); // lossless because flac is a lossless codec} else {addCodecArgs('copy');@@ -207,14 +207,14 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposireturn args;}-export function getMapStreamsArgs({ startIndex = 0, outFormat, allFilesMeta, copyFileStreams, manuallyCopyDisposition, getVideoArgs, areWeCutting, fixCodecTag }: {+export function getMapStreamsArgs({ startIndex = 0, outFormat, allFilesMeta, copyFileStreams, manuallyCopyDisposition, getVideoArgs, needFlac, fixCodecTag }: {startIndex?: number,outFormat: string | undefined,allFilesMeta: Record<string, Pick<AllFilesMeta[string], 'streams'>>,copyFileStreams: CopyfileStreams,manuallyCopyDisposition?: boolean,getVideoArgs?: GetVideoArgsFn,- areWeCutting?: boolean,+ needFlac?: boolean,fixCodecTag?: FixCodecTagOption,}) {let args: string[] = [];@@ -228,7 +228,7 @@ export function getMapStreamsArgs({ startIndex = 0, outFormat, allFilesMeta, copargs = [...args,'-map', `${fileIndex}:${streamId}`,- ...getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposition, getVideoArgs, areWeCutting, fixCodecTag }),+ ...getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposition, getVideoArgs, needFlac, fixCodecTag }),];outputIndex += 1;});