add smartcut option `-bf` based on `has_b_frames`

#2690 #126
pull/2762/head
Mikael Finstad 6 months ago
parent 26013053cd
commit 26013077af
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -427,7 +427,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
}, [appendFfmpegCommandLog, cutFromAdjustmentFrames, cutToAdjustmentFrames, filePath, getOutputPlaybackRateArgs, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart]);
// inspired by https://gist.github.com/fernandoherreradelasheras/5eca67f4200f1a7cc8281747da08496e
const cutEncodeSmartPart = useCallback(async ({ cutFrom, cutTo, outPath, outFormat, videoCodec, videoBitrate, videoTimebase, allFilesMeta, copyFileStreams, videoStreamIndex, ffmpegExperimental }: {
const cutEncodeSmartPart = useCallback(async ({ cutFrom, cutTo, outPath, outFormat, videoCodec, videoBitrate, videoTimebase, allFilesMeta, copyFileStreams, videoStreamIndex, ffmpegExperimental, hasBFrames }: {
cutFrom: number,
cutTo: number,
outPath: string,
@ -439,6 +439,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
copyFileStreams: CopyfileStreams,
videoStreamIndex: number,
ffmpegExperimental: boolean,
hasBFrames: number | undefined,
}) => {
invariant(filePath != null);
@ -481,6 +482,8 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
...getVideoTimescaleArgs(videoTimebase),
...(hasBFrames ? ['-bf', String(hasBFrames)] : []),
...getExperimentalArgs(ffmpegExperimental),
'-f', outFormat, '-y', outPath,
@ -583,7 +586,7 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, trea
invariant(sourceCodecParams.videoTimebase != null);
invariant(filePath != null);
invariant(outFormat != null);
await cutEncodeSmartPart({ cutFrom, cutTo, outPath, outFormat, videoCodec, videoBitrate: encCustomBitrate != null ? encCustomBitrate * 1000 : sourceCodecParams.videoBitrate, videoStreamIndex: videoStream.index, videoTimebase: sourceCodecParams.videoTimebase, allFilesMeta, copyFileStreams: copyFileStreamsFiltered, ffmpegExperimental });
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 });
}
const cutEncodeWholePart = async () => {

@ -50,7 +50,7 @@ export async function needsSmartCut({ path, desiredCutFrom, videoStream }: {
export async function getCodecParams({ path, fileDuration, streams }: {
path: string,
fileDuration: number | undefined,
streams: Pick<FFprobeStream, 'time_base' | 'codec_type' | 'disposition' | 'index' | 'bit_rate' | 'codec_name'>[],
streams: Pick<FFprobeStream, 'has_b_frames' | 'time_base' | 'codec_type' | 'disposition' | 'index' | 'bit_rate' | 'codec_name'>[],
}) {
const videoStreams = getRealVideoStreams(streams);
if (videoStreams.length > 1) throw new Error('Can only smart cut video with exactly one video stream');

Loading…
Cancel
Save