1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-24 19:32:29 +01:00

re-encode flac when cutting

and warn about it
fixes #1809
This commit is contained in:
Mikael Finstad 2024-08-27 20:18:05 +02:00
parent 1a674fa735
commit e7d2caf893
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
3 changed files with 21 additions and 2 deletions

View File

@ -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({
<table className={styles['options']}>
<tbody>
{warnings.map((warning) => (
<tr key={warning}>
<td colSpan={2}>
<div style={warningStyle}><WarningSignIcon verticalAlign="middle" color="warning" /> {warnings.join('\n')}</div>
</td>
<td />
</tr>
))}
{selectedSegments.length !== nonFilteredSegmentsOrInverse.length && (
<tr>
<td colSpan={2}>

View File

@ -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[] = [];

View File

@ -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');
}