@ -11,7 +11,7 @@ import { getMapStreamsArgs, getStreamIdsToCopy } from '../util/streams';
import { needsSmartCut , getCodecParams } from '../smartcut' ;
import { getGuaranteedSegments , isDurationValid } from '../segments' ;
import { FFprobeStream } from '../../../../ffprobe' ;
import { AvoidNegativeTs , Html5ifyMode, PreserveMetadata } from '../../../../types' ;
import { AvoidNegativeTs , FixCodecTagOption, Html5ifyMode, PreserveMetadata } from '../../../../types' ;
import { AllFilesMeta , Chapter , CopyfileStreams , CustomTagsByFile , LiteFFprobeStream , ParamsByStreamId , SegmentToExport } from '../types' ;
import { LossyMode } from '../../../main' ;
import { UserFacingError } from '../../errors' ;
@ -120,7 +120,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
const getOutputPlaybackRateArgs = useCallback ( ( ) = > ( outputPlaybackRate !== 1 ? [ '-itsscale' , String ( 1 / outputPlaybackRate ) ] : [ ] ) , [ outputPlaybackRate ] ) ;
const concatFiles = useCallback ( async ( { paths , outDir , outPath , metadataFromPath , includeAllStreams , streams , outFormat , ffmpegExperimental , onProgress = ( ) = > undefined , preserveMovData , movFastStart , chapters, preserveMetadataOnMerge , videoTimebase } : {
const concatFiles = useCallback ( async ( { paths , outDir , outPath , metadataFromPath , includeAllStreams , streams , outFormat , ffmpegExperimental , onProgress = ( ) = > undefined , preserveMovData , movFastStart , fixCodecTag, chapters, preserveMetadataOnMerge , videoTimebase } : {
paths : string [ ] ,
outDir : string | undefined ,
outPath : string ,
@ -132,6 +132,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
onProgress ? : ( a : number ) = > void ,
preserveMovData : boolean ,
movFastStart : boolean ,
fixCodecTag : FixCodecTagOption ,
chapters : Chapter [ ] | undefined ,
preserveMetadataOnMerge : boolean ,
videoTimebase? : number | undefined ,
@ -188,6 +189,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
copyFileStreams : [ { path : metadataFromPath , streamIds : streamIdsToCopy } ] ,
outFormat ,
manuallyCopyDisposition : true ,
fixCodecTag ,
} ) ;
// Keep this similar to losslessCutSingle()
@ -245,7 +247,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
const losslessCutSingle = useCallback ( async ( {
keyframeCut : ssBeforeInput , avoidNegativeTs , copyFileStreams , cutFrom , cutTo , chaptersPath , onProgress , outPath ,
fileDuration , rotation , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMovData , preserveChapters , movFastStart , customTagsByFile, paramsByStreamId , videoTimebase , detectedFps ,
fileDuration , rotation , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMovData , preserveChapters , movFastStart , fixCodecTag, customTagsByFile, paramsByStreamId , videoTimebase , detectedFps ,
} : {
keyframeCut : boolean ,
avoidNegativeTs : AvoidNegativeTs | undefined ,
@ -265,6 +267,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
preserveMovData : boolean ,
preserveChapters : boolean ,
movFastStart : boolean ,
fixCodecTag : FixCodecTagOption ,
customTagsByFile : CustomTagsByFile ,
paramsByStreamId : ParamsByStreamId ,
videoTimebase? : number | undefined ,
@ -332,7 +335,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
. . . flatMap ( Object . entries ( customTagsByFile [ filePath ] || [ ] ) , ( [ key , value ] ) = > [ '-metadata' , ` ${ key } = ${ value } ` ] ) ,
] ;
const mapStreamsArgs = getMapStreamsArgs ( { copyFileStreams : copyFileStreamsFiltered , allFilesMeta , outFormat , areWeCutting } ) ;
const mapStreamsArgs = getMapStreamsArgs ( { copyFileStreams : copyFileStreamsFiltered , allFilesMeta , outFormat , areWeCutting , fixCodecTag } ) ;
const customParamsArgs = ( ( ) = > {
const ret : string [ ] = [ ] ;
@ -492,7 +495,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
} , [ appendFfmpegCommandLog , filePath ] ) ;
const cutMultiple = useCallback ( async ( {
outputDir , customOutDir , segments : segmentsIn , cutFileNames , fileDuration , rotation , detectedFps , onProgress : onTotalProgress , keyframeCut , copyFileStreams , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMetadataOnMerge , preserveMovData , preserveChapters , movFastStart , avoidNegativeTs, customTagsByFile , paramsByStreamId , chapters ,
outputDir , customOutDir , segments : segmentsIn , cutFileNames , fileDuration , rotation , detectedFps , onProgress : onTotalProgress , keyframeCut , copyFileStreams , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMetadataOnMerge , preserveMovData , preserveChapters , movFastStart , fixCodecTag, avoidNegativeTs, customTagsByFile , paramsByStreamId , chapters ,
} : {
outputDir : string ,
customOutDir : string | undefined ,
@ -513,6 +516,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
preserveMetadataOnMerge : boolean ,
preserveChapters : boolean ,
movFastStart : boolean ,
fixCodecTag : FixCodecTagOption ,
avoidNegativeTs : AvoidNegativeTs | undefined ,
customTagsByFile : CustomTagsByFile ,
paramsByStreamId : ParamsByStreamId ,
@ -549,7 +553,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
// simple lossless cut
invariant ( outFormat != null ) ;
await losslessCutSingle ( {
cutFrom : desiredCutFrom , cutTo , chaptersPath , outPath : finalOutPath , copyFileStreams , keyframeCut , avoidNegativeTs , fileDuration , rotation , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMovData , preserveChapters , movFastStart , customTagsByFile, paramsByStreamId , onProgress : ( progress ) = > onSingleProgress ( i , progress ) ,
cutFrom : desiredCutFrom , cutTo , chaptersPath , outPath : finalOutPath , copyFileStreams , keyframeCut , avoidNegativeTs , fileDuration , rotation , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMovData , preserveChapters , movFastStart , fixCodecTag, customTagsByFile, paramsByStreamId , onProgress : ( progress ) = > onSingleProgress ( i , progress ) ,
} ) ;
return { path : finalOutPath , created : true } ;
}
@ -622,7 +626,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
// for smart cut we need to use keyframe cut here, and no avoid_negative_ts
await losslessCutSingle ( {
cutFrom : losslessCutFrom , cutTo , chaptersPath , outPath : losslessPartOutPath , copyFileStreams : copyFileStreamsFiltered , keyframeCut : true , avoidNegativeTs : undefined , fileDuration , rotation , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMovData , preserveChapters , movFastStart , customTagsByFile, paramsByStreamId , videoTimebase , onProgress ,
cutFrom : losslessCutFrom , cutTo , chaptersPath , outPath : losslessPartOutPath , copyFileStreams : copyFileStreamsFiltered , keyframeCut : true , avoidNegativeTs : undefined , fileDuration , rotation , allFilesMeta , outFormat , shortestFlag , ffmpegExperimental , preserveMetadata , preserveMovData , preserveChapters , movFastStart , fixCodecTag, customTagsByFile, paramsByStreamId , videoTimebase , onProgress ,
} ) ;
// We don't need to concat, just return the single cut file (we may need smart cut in other segments though)
@ -644,7 +648,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
// need to re-read streams because indexes may have changed. Using main file as source of streams and metadata
const { streams : streamsAfterCut } = await readFileMeta ( losslessPartOutPath ) ;
await concatFiles ( { paths : smartCutSegmentsToConcat , outDir : outputDir , outPath : finalOutPath , metadataFromPath : losslessPartOutPath , outFormat , includeAllStreams : true , streams : streamsAfterCut , ffmpegExperimental , preserveMovData , movFastStart , chapters, preserveMetadataOnMerge , videoTimebase , onProgress : onConcatProgress } ) ;
await concatFiles ( { paths : smartCutSegmentsToConcat , outDir : outputDir , outPath : finalOutPath , metadataFromPath : losslessPartOutPath , outFormat , includeAllStreams : true , streams : streamsAfterCut , ffmpegExperimental , preserveMovData , movFastStart , fixCodecTag, chapters, preserveMetadataOnMerge , videoTimebase , onProgress : onConcatProgress } ) ;
return { path : finalOutPath , created : true } ;
} finally {
await tryDeleteFiles ( smartCutSegmentsToConcat ) ;
@ -658,13 +662,14 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
}
} , [ shouldSkipExistingFile , isEncoding , filePath , lossyMode , losslessCutSingle , cutEncodeSmartPart , encCustomBitrate , concatFiles ] ) ;
const concatCutSegments = useCallback ( async ( { customOutDir , outFormat , segmentPaths , ffmpegExperimental , onProgress , preserveMovData , movFastStart, chapterNames , preserveMetadataOnMerge , mergedOutFilePath } : {
const concatCutSegments = useCallback ( async ( { customOutDir , outFormat , segmentPaths , ffmpegExperimental , onProgress , preserveMovData , fixCodecTag, movFastStart, chapterNames , preserveMetadataOnMerge , mergedOutFilePath } : {
customOutDir : string | undefined ,
outFormat : string | undefined ,
segmentPaths : string [ ] ,
ffmpegExperimental : boolean ,
onProgress : ( p : number ) = > void ,
preserveMovData : boolean ,
fixCodecTag : FixCodecTagOption ,
movFastStart : boolean ,
chapterNames : ( string | undefined ) [ ] | undefined ,
preserveMetadataOnMerge : boolean ,
@ -680,7 +685,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
invariant ( metadataFromPath != null ) ;
// need to re-read streams because may have changed
const { streams } = await readFileMeta ( metadataFromPath ) ;
await concatFiles ( { paths : segmentPaths , outDir , outPath : mergedOutFilePath , metadataFromPath , outFormat , includeAllStreams : true , streams , ffmpegExperimental , onProgress , preserveMovData , movFastStart , chapters, preserveMetadataOnMerge } ) ;
await concatFiles ( { paths : segmentPaths , outDir , outPath : mergedOutFilePath , metadataFromPath , outFormat , includeAllStreams : true , streams , ffmpegExperimental , onProgress , preserveMovData , movFastStart , fixCodecTag, chapters, preserveMetadataOnMerge } ) ;
} , [ concatFiles , filePath , shouldSkipExistingFile ] ) ;
const html5ify = useCallback ( async ( { customOutDir , filePath : filePathArg , speed , hasAudio , hasVideo , onProgress } : {