From 20321f2049f46a7bfaadcc5da2f1eb53b9bb4d76 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Feb 2023 13:55:21 +0100 Subject: Reencode the video on cut Unfortunately copying audio/video is not precise enough and could lead to inconsistencies --- server/helpers/ffmpeg/ffmpeg-edition.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/ffmpeg/ffmpeg-edition.ts b/server/helpers/ffmpeg/ffmpeg-edition.ts index 78de8f3b3..02c5ea8de 100644 --- a/server/helpers/ffmpeg/ffmpeg-edition.ts +++ b/server/helpers/ffmpeg/ffmpeg-edition.ts @@ -3,7 +3,7 @@ import { VIDEO_FILTERS } from '@server/initializers/constants' import { AvailableEncoders } from '@shared/models' import { logger, loggerTagsFactory } from '../logger' import { getFFmpeg, runCommand } from './ffmpeg-commons' -import { presetCopy, presetVOD } from './ffmpeg-presets' +import { presetVOD } from './ffmpeg-presets' import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS, hasAudioStream } from './ffprobe-utils' const lTags = loggerTagsFactory('ffmpeg') @@ -13,25 +13,38 @@ async function cutVideo (options: { outputPath: string start?: number end?: number + + availableEncoders: AvailableEncoders + profile: string }) { - const { inputPath, outputPath } = options + const { inputPath, outputPath, availableEncoders, profile } = options logger.debug('Will cut the video.', { options, ...lTags() }) + const mainProbe = await ffprobePromise(inputPath) + const fps = await getVideoStreamFPS(inputPath, mainProbe) + const { resolution } = await getVideoStreamDimensionsInfo(inputPath, mainProbe) + let command = getFFmpeg(inputPath, 'vod') .output(outputPath) - command = presetCopy(command) + command = await presetVOD({ + command, + input: inputPath, + availableEncoders, + profile, + resolution, + fps, + canCopyAudio: false, + canCopyVideo: false + }) if (options.start) { - // Using -ss as output option is more precise than using it as input option command.outputOption('-ss ' + options.start) } if (options.end) { - const endSeeking = options.end - (options.start || 0) - - command.outputOption('-to ' + endSeeking) + command.outputOption('-to ' + options.end) } await runCommand({ command }) -- cgit v1.2.3