1
0
Fork 0

Reencode the video on cut

Unfortunately copying audio/video is not precise enough and could lead
to inconsistencies
This commit is contained in:
Chocobozzz 2023-02-14 13:55:21 +01:00
parent 98bd5e2256
commit 20321f2049
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 24 additions and 8 deletions

View file

@ -3,7 +3,7 @@ import { VIDEO_FILTERS } from '@server/initializers/constants'
import { AvailableEncoders } from '@shared/models' import { AvailableEncoders } from '@shared/models'
import { logger, loggerTagsFactory } from '../logger' import { logger, loggerTagsFactory } from '../logger'
import { getFFmpeg, runCommand } from './ffmpeg-commons' 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' import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS, hasAudioStream } from './ffprobe-utils'
const lTags = loggerTagsFactory('ffmpeg') const lTags = loggerTagsFactory('ffmpeg')
@ -13,25 +13,38 @@ async function cutVideo (options: {
outputPath: string outputPath: string
start?: number start?: number
end?: 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() }) 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') let command = getFFmpeg(inputPath, 'vod')
.output(outputPath) .output(outputPath)
command = presetCopy(command) command = await presetVOD({
command,
input: inputPath,
availableEncoders,
profile,
resolution,
fps,
canCopyAudio: false,
canCopyVideo: false
})
if (options.start) { if (options.start) {
// Using -ss as output option is more precise than using it as input option
command.outputOption('-ss ' + options.start) command.outputOption('-ss ' + options.start)
} }
if (options.end) { if (options.end) {
const endSeeking = options.end - (options.start || 0) command.outputOption('-to ' + options.end)
command.outputOption('-to ' + endSeeking)
} }
await runCommand({ command }) await runCommand({ command })

View file

@ -164,7 +164,10 @@ function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) {
...pick(options, [ 'inputPath', 'outputPath' ]), ...pick(options, [ 'inputPath', 'outputPath' ]),
start: task.options.start, start: task.options.start,
end: task.options.end end: task.options.end,
availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
profile: CONFIG.TRANSCODING.PROFILE
}) })
} }