From e7d2caf893857dfb851de84b46a42e0e8eb1711f Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Tue, 27 Aug 2024 20:18:05 +0200 Subject: [PATCH] re-encode flac when cutting and warn about it fixes #1809 --- src/renderer/src/components/ExportConfirm.tsx | 16 ++++++++++++++++ src/renderer/src/hooks/useFfmpegOperations.ts | 5 +++-- src/renderer/src/util/streams.ts | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/ExportConfirm.tsx b/src/renderer/src/components/ExportConfirm.tsx index 1fde6cc7..7e889b4b 100644 --- a/src/renderer/src/components/ExportConfirm.tsx +++ b/src/renderer/src/components/ExportConfirm.tsx @@ -103,6 +103,14 @@ function ExportConfirm({ // some thumbnail streams (png,jpg etc) cannot always be cut correctly, so we warn if they try to. const areWeCuttingProblematicStreams = areWeCutting && mainCopiedThumbnailStreams.length > 0; + const warnings = useMemo(() => { + const ret: string[] = []; + // https://github.com/mifi/lossless-cut/issues/1809 + if (areWeCutting && outFormat === 'flac') { + ret.push(t('There is a known issue in FFmpeg with cutting FLAC files. The file will be re-encoded, which is still lossless, but the export may be slower.')); + } + return ret; + }, [areWeCutting, outFormat, t]); const exportModeDescription = useMemo(() => ({ segments_to_chapters: t('Don\'t cut the file, but instead export an unmodified original which has chapters generated from segments'), merge: t('Auto merge segments to one file after export'), @@ -208,6 +216,14 @@ function ExportConfirm({ + {warnings.map((warning) => ( + + + + ))} {selectedSegments.length !== nonFilteredSegmentsOrInverse.length && (
+
{warnings.join('\n')}
+
+
diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.ts index 2caea4c0..ecf5a05e 100644 --- a/src/renderer/src/hooks/useFfmpegOperations.ts +++ b/src/renderer/src/hooks/useFfmpegOperations.ts @@ -218,7 +218,8 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea const cuttingStart = isCuttingStart(cutFrom); const cutFromWithAdjustment = cutFrom + cutFromAdjustmentFrames * frameDuration; const cuttingEnd = isCuttingEnd(cutTo, videoDuration); - console.log('Cutting from', cuttingStart ? `${cutFrom} (${cutFromWithAdjustment} adjusted ${cutFromAdjustmentFrames} frames)` : 'start', 'to', cuttingEnd ? cutTo : 'end'); + const areWeCutting = cuttingStart || cuttingEnd; + if (areWeCutting) console.log('Cutting from', cuttingStart ? `${cutFrom} (${cutFromWithAdjustment} adjusted ${cutFromAdjustmentFrames} frames)` : 'start', 'to', cuttingEnd ? cutTo : 'end'); let cutDuration = cutTo - cutFromWithAdjustment; if (detectedFps != null) cutDuration = Math.max(cutDuration, frameDuration); // ensure at least one frame duration @@ -279,7 +280,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea ...flatMap(Object.entries(customTagsByFile[filePath] || []), ([key, value]) => ['-metadata', `${key}=${value}`]), ]; - const mapStreamsArgs = getMapStreamsArgs({ copyFileStreams: copyFileStreamsFiltered, allFilesMeta, outFormat }); + const mapStreamsArgs = getMapStreamsArgs({ copyFileStreams: copyFileStreamsFiltered, allFilesMeta, outFormat, areWeCutting }); const customParamsArgs = (() => { const ret: string[] = []; diff --git a/src/renderer/src/util/streams.ts b/src/renderer/src/util/streams.ts index 6c0b491d..2032ac56 100644 --- a/src/renderer/src/util/streams.ts +++ b/src/renderer/src/util/streams.ts @@ -169,6 +169,8 @@ function getPerStreamFlags({ stream, outputIndex, outFormat, manuallyCopyDisposi // I think DV format only supports PCM_S16LE https://github.com/FFmpeg/FFmpeg/blob/b92028346c35dad837dd1160930435d88bd838b5/libavformat/dvenc.c#L450 addCodecArgs('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 + addCodecArgs('flac'); // lossless because flac is a lossless codec } else { addCodecArgs('copy'); }