Skip to content

The swiss army knife of lossless video/audio editing

Fix timestamps of smart cut output that needs concat

Claude14dafe243088
diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.ts
index b127d9ab..06eac94f 100644
--- a/src/renderer/src/hooks/useFfmpegOperations.ts
+++ b/src/renderer/src/hooks/useFfmpegOperations.ts
@@ -659,11 +659,12 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
await cutEncodeSmartPart({ cutFrom, cutTo, outPath, outFormat, videoCodec, videoBitrate: encCustomBitrate != null ? encCustomBitrate * 1000 : sourceCodecParams.videoBitrate, videoStreamIndex: videoStream.index, videoTimebase: sourceCodecParams.videoTimebase, allFilesMeta, copyFileStreams: copyFileStreamsFiltered, ffmpegExperimental, hasBFrames: sourceCodecParams.videoStream.has_b_frames });
}
+ // used when the final output file was produced by encoding or concat, because they don't transfer the timestamps of the segment
+ const transferSegmentTimestamps = async () => transferTimestamps({ inPath: filePath, outPath: finalOutPath, cutFrom: desiredCutFrom, cutTo, duration: isDurationValid(fileDuration) ? fileDuration : undefined, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart });
+
const cutEncodeWholePart = async () => {
await cutEncodeSmartPartWrapper({ cutFrom: desiredCutFrom, cutTo, outPath: finalOutPath });
- // cutEncodeSmartPart doesn't transfer timestamps (its output is usually a temporary file to be concated),
- // but here it produced the final output file, so we need to do it ourselves
- await transferTimestamps({ inPath: filePath, outPath: finalOutPath, cutFrom: desiredCutFrom, cutTo, duration: isDurationValid(fileDuration) ? fileDuration : undefined, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart });
+ await transferSegmentTimestamps();
return { path: finalOutPath, created: true };
};
@@ -720,6 +721,8 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
const { streams: streamsAfterCut } = await readFileFfprobeMeta(losslessPartOutPath);
await concatFiles({ paths: smartCutSegmentsToConcat, outDir: outputDir, outPath: finalOutPath, metadataFromPath: losslessPartOutPath, outFormat, includeAllStreams: true, streams: streamsAfterCut, ffmpegExperimental, preserveMovData, movFastStart, chapters, preserveMetadataOnMerge, videoTimebase, onProgress: onConcatProgress });
+ // concatFiles copied the timestamps of the lossless part (which starts at the next keyframe, not at the segment start)
+ await transferSegmentTimestamps();
return { path: finalOutPath, created: true };
} finally {
await tryDeleteFiles(smartCutSegmentsToConcat);