X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fffmpeg%2Fffmpeg-vod.ts;h=d84703eb9be66c82bc5082ff4cc412c5e7b048d2;hb=e65ef81cf51746616182a822bd6933bf0d16717a;hp=c3622ceb17f7538012a4cd84058f337080484488;hpb=c729caf6cc34630877a0e5a1bda1719384cd0c8a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/ffmpeg/ffmpeg-vod.ts b/server/helpers/ffmpeg/ffmpeg-vod.ts index c3622ceb1..d84703eb9 100644 --- a/server/helpers/ffmpeg/ffmpeg-vod.ts +++ b/server/helpers/ffmpeg/ffmpeg-vod.ts @@ -1,14 +1,15 @@ -import { Job } from 'bull' +import { MutexInterface } from 'async-mutex' +import { Job } from 'bullmq' import { FfmpegCommand } from 'fluent-ffmpeg' import { readFile, writeFile } from 'fs-extra' import { dirname } from 'path' +import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' import { pick } from '@shared/core-utils' import { AvailableEncoders, VideoResolution } from '@shared/models' import { logger, loggerTagsFactory } from '../logger' import { getFFmpeg, runCommand } from './ffmpeg-commons' import { presetCopy, presetOnlyAudio, presetVOD } from './ffmpeg-presets' -import { computeFPS, getVideoStreamFPS } from './ffprobe-utils' -import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' +import { computeFPS, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS } from './ffprobe-utils' const lTags = loggerTagsFactory('ffmpeg') @@ -22,13 +23,15 @@ interface BaseTranscodeVODOptions { inputPath: string outputPath: string + // Will be released after the ffmpeg started + // To prevent a bug where the input file does not exist anymore when running ffmpeg + inputFileMutexReleaser: MutexInterface.Releaser + availableEncoders: AvailableEncoders profile: string resolution: number - isPortraitMode?: boolean - job?: Job } @@ -96,6 +99,12 @@ async function transcodeVOD (options: TranscodeVODOptions) { command = await builders[options.type](command, options) + command.on('start', () => { + setTimeout(() => { + options.inputFileMutexReleaser() + }, 1000) + }) + await runCommand({ command, job: options.job }) await fixHLSPlaylistIfNeeded(options) @@ -115,13 +124,17 @@ export { // --------------------------------------------------------------------------- async function buildVODCommand (command: FfmpegCommand, options: TranscodeVODOptions) { - let fps = await getVideoStreamFPS(options.inputPath) + const probe = await ffprobePromise(options.inputPath) + + let fps = await getVideoStreamFPS(options.inputPath, probe) fps = computeFPS(fps, options.resolution) let scaleFilterValue: string if (options.resolution !== undefined) { - scaleFilterValue = options.isPortraitMode === true + const videoStreamInfo = await getVideoStreamDimensionsInfo(options.inputPath, probe) + + scaleFilterValue = videoStreamInfo?.isPortraitMode === true ? `w=${options.resolution}:h=-2` : `w=-2:h=${options.resolution}` }