@@ -60,7 +60,7 @@ async function tryDeleteFiles(paths: string[]) {
60
60
return pMap ( paths , ( path ) => unlinkWithRetry ( path ) . catch ( ( err ) => console . error ( 'Failed to delete' , path , err ) ) , { concurrency : 5 } ) ;
61
61
}
62
62
63
- function useFfmpegOperations ( { filePath, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart, needSmartCut, enableOverwriteOutput, outputPlaybackRate, cutFromAdjustmentFrames, appendLastCommandsLog } : {
63
+ function useFfmpegOperations ( { filePath, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart, needSmartCut, enableOverwriteOutput, outputPlaybackRate, cutFromAdjustmentFrames, appendLastCommandsLog, smartCutCustomBitrate } : {
64
64
filePath : string | undefined ,
65
65
treatInputFileModifiedTimeAsStart : boolean | null | undefined ,
66
66
treatOutputFileModifiedTimeAsStart : boolean | null | undefined ,
@@ -69,6 +69,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
69
69
outputPlaybackRate : number ,
70
70
cutFromAdjustmentFrames : number ,
71
71
appendLastCommandsLog : ( a : string ) => void ,
72
+ smartCutCustomBitrate : number | undefined ,
72
73
} ) {
73
74
const appendFfmpegCommandLog = useCallback ( ( args : string [ ] ) => appendLastCommandsLog ( getFfCommandLine ( 'ffmpeg' , args ) ) , [ appendLastCommandsLog ] ) ;
74
75
@@ -412,7 +413,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
412
413
return match ? [ match ] : [ ] ;
413
414
} ) ;
414
415
415
- const { losslessCutFrom, segmentNeedsSmartCut, videoCodec, videoBitrate, videoStreamIndex, videoTimebase } = await getSmartCutParams ( { path : filePath , videoDuration, desiredCutFrom, streams : streamsToCopyFromMainFile } ) ;
416
+ const { losslessCutFrom, segmentNeedsSmartCut, videoCodec, videoBitrate : detectedVideoBitrate , videoStreamIndex, videoTimebase } = await getSmartCutParams ( { path : filePath , videoDuration, desiredCutFrom, streams : streamsToCopyFromMainFile } ) ;
416
417
417
418
if ( segmentNeedsSmartCut && ! detectedFps ) throw new Error ( 'Smart cut is not possible when FPS is unknown' ) ;
418
419
@@ -430,10 +431,10 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
430
431
// eslint-disable-next-line no-shadow
431
432
async function cutEncodeSmartPartWrapper ( { cutFrom, cutTo, outPath } ) {
432
433
if ( await shouldSkipExistingFile ( outPath ) ) return ;
433
- if ( videoCodec == null || videoBitrate == null || videoTimebase == null ) throw new Error ( ) ;
434
+ if ( videoCodec == null || detectedVideoBitrate == null || videoTimebase == null ) throw new Error ( ) ;
434
435
invariant ( filePath != null ) ;
435
436
invariant ( outFormat != null ) ;
436
- const args = await cutEncodeSmartPart ( { filePath, cutFrom, cutTo, outPath, outFormat, videoCodec, videoBitrate, videoStreamIndex, videoTimebase, allFilesMeta, copyFileStreams : copyFileStreamsFiltered , ffmpegExperimental } ) ;
437
+ const args = await cutEncodeSmartPart ( { filePath, cutFrom, cutTo, outPath, outFormat, videoCodec, videoBitrate : smartCutCustomBitrate != null ? smartCutCustomBitrate * 1000 : detectedVideoBitrate , videoStreamIndex, videoTimebase, allFilesMeta, copyFileStreams : copyFileStreamsFiltered , ffmpegExperimental } ) ;
437
438
appendFfmpegCommandLog ( args ) ;
438
439
}
439
440
@@ -497,7 +498,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
497
498
} finally {
498
499
if ( chaptersPath ) await tryDeleteFiles ( [ chaptersPath ] ) ;
499
500
}
500
- } , [ needSmartCut , filePath , losslessCutSingle , shouldSkipExistingFile , concatFiles ] ) ;
501
+ } , [ needSmartCut , filePath , losslessCutSingle , shouldSkipExistingFile , smartCutCustomBitrate , appendFfmpegCommandLog , concatFiles ] ) ;
501
502
502
503
const autoConcatCutSegments = useCallback ( async ( { customOutDir, outFormat, segmentPaths, ffmpegExperimental, onProgress, preserveMovData, movFastStart, autoDeleteMergedSegments, chapterNames, preserveMetadataOnMerge, mergedOutFilePath } ) => {
503
504
const outDir = getOutDir ( customOutDir , filePath ) ;
@@ -576,7 +577,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
576
577
await transferTimestamps ( { inPath : filePath , outPath, treatOutputFileModifiedTimeAsStart } ) ;
577
578
578
579
return outPath ;
579
- } , [ filePath , treatOutputFileModifiedTimeAsStart ] ) ;
580
+ } , [ appendFfmpegCommandLog , filePath , treatOutputFileModifiedTimeAsStart ] ) ;
580
581
581
582
return {
582
583
cutMultiple, concatFiles, html5ify, html5ifyDummy, fixInvalidDuration, autoConcatCutSegments,
0 commit comments