diff options
Diffstat (limited to 'server/helpers/ffmpeg')
-rw-r--r-- | server/helpers/ffmpeg/ffmpeg-vod.ts | 13 | ||||
-rw-r--r-- | server/helpers/ffmpeg/ffprobe-utils.ts | 9 |
2 files changed, 19 insertions, 3 deletions
diff --git a/server/helpers/ffmpeg/ffmpeg-vod.ts b/server/helpers/ffmpeg/ffmpeg-vod.ts index 7a81a1313..d84703eb9 100644 --- a/server/helpers/ffmpeg/ffmpeg-vod.ts +++ b/server/helpers/ffmpeg/ffmpeg-vod.ts | |||
@@ -1,14 +1,15 @@ | |||
1 | import { MutexInterface } from 'async-mutex' | ||
1 | import { Job } from 'bullmq' | 2 | import { Job } from 'bullmq' |
2 | import { FfmpegCommand } from 'fluent-ffmpeg' | 3 | import { FfmpegCommand } from 'fluent-ffmpeg' |
3 | import { readFile, writeFile } from 'fs-extra' | 4 | import { readFile, writeFile } from 'fs-extra' |
4 | import { dirname } from 'path' | 5 | import { dirname } from 'path' |
6 | import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' | ||
5 | import { pick } from '@shared/core-utils' | 7 | import { pick } from '@shared/core-utils' |
6 | import { AvailableEncoders, VideoResolution } from '@shared/models' | 8 | import { AvailableEncoders, VideoResolution } from '@shared/models' |
7 | import { logger, loggerTagsFactory } from '../logger' | 9 | import { logger, loggerTagsFactory } from '../logger' |
8 | import { getFFmpeg, runCommand } from './ffmpeg-commons' | 10 | import { getFFmpeg, runCommand } from './ffmpeg-commons' |
9 | import { presetCopy, presetOnlyAudio, presetVOD } from './ffmpeg-presets' | 11 | import { presetCopy, presetOnlyAudio, presetVOD } from './ffmpeg-presets' |
10 | import { computeFPS, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS } from './ffprobe-utils' | 12 | import { computeFPS, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS } from './ffprobe-utils' |
11 | import { VIDEO_TRANSCODING_FPS } from '@server/initializers/constants' | ||
12 | 13 | ||
13 | const lTags = loggerTagsFactory('ffmpeg') | 14 | const lTags = loggerTagsFactory('ffmpeg') |
14 | 15 | ||
@@ -22,6 +23,10 @@ interface BaseTranscodeVODOptions { | |||
22 | inputPath: string | 23 | inputPath: string |
23 | outputPath: string | 24 | outputPath: string |
24 | 25 | ||
26 | // Will be released after the ffmpeg started | ||
27 | // To prevent a bug where the input file does not exist anymore when running ffmpeg | ||
28 | inputFileMutexReleaser: MutexInterface.Releaser | ||
29 | |||
25 | availableEncoders: AvailableEncoders | 30 | availableEncoders: AvailableEncoders |
26 | profile: string | 31 | profile: string |
27 | 32 | ||
@@ -94,6 +99,12 @@ async function transcodeVOD (options: TranscodeVODOptions) { | |||
94 | 99 | ||
95 | command = await builders[options.type](command, options) | 100 | command = await builders[options.type](command, options) |
96 | 101 | ||
102 | command.on('start', () => { | ||
103 | setTimeout(() => { | ||
104 | options.inputFileMutexReleaser() | ||
105 | }, 1000) | ||
106 | }) | ||
107 | |||
97 | await runCommand({ command, job: options.job }) | 108 | await runCommand({ command, job: options.job }) |
98 | 109 | ||
99 | await fixHLSPlaylistIfNeeded(options) | 110 | await fixHLSPlaylistIfNeeded(options) |
diff --git a/server/helpers/ffmpeg/ffprobe-utils.ts b/server/helpers/ffmpeg/ffprobe-utils.ts index 2c6253d44..fb270b3cb 100644 --- a/server/helpers/ffmpeg/ffprobe-utils.ts +++ b/server/helpers/ffmpeg/ffprobe-utils.ts | |||
@@ -15,6 +15,7 @@ import { | |||
15 | import { VideoResolution, VideoTranscodingFPS } from '@shared/models' | 15 | import { VideoResolution, VideoTranscodingFPS } from '@shared/models' |
16 | import { CONFIG } from '../../initializers/config' | 16 | import { CONFIG } from '../../initializers/config' |
17 | import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' | 17 | import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' |
18 | import { toEven } from '../core-utils' | ||
18 | import { logger } from '../logger' | 19 | import { logger } from '../logger' |
19 | 20 | ||
20 | /** | 21 | /** |
@@ -96,8 +97,9 @@ function computeResolutionsToTranscode (options: { | |||
96 | type: 'vod' | 'live' | 97 | type: 'vod' | 'live' |
97 | includeInput: boolean | 98 | includeInput: boolean |
98 | strictLower: boolean | 99 | strictLower: boolean |
100 | hasAudio: boolean | ||
99 | }) { | 101 | }) { |
100 | const { input, type, includeInput, strictLower } = options | 102 | const { input, type, includeInput, strictLower, hasAudio } = options |
101 | 103 | ||
102 | const configResolutions = type === 'vod' | 104 | const configResolutions = type === 'vod' |
103 | ? CONFIG.TRANSCODING.RESOLUTIONS | 105 | ? CONFIG.TRANSCODING.RESOLUTIONS |
@@ -125,12 +127,15 @@ function computeResolutionsToTranscode (options: { | |||
125 | if (input < resolution) continue | 127 | if (input < resolution) continue |
126 | // We only want lower resolutions than input file | 128 | // We only want lower resolutions than input file |
127 | if (strictLower && input === resolution) continue | 129 | if (strictLower && input === resolution) continue |
130 | // Audio resolutio but no audio in the video | ||
131 | if (resolution === VideoResolution.H_NOVIDEO && !hasAudio) continue | ||
128 | 132 | ||
129 | resolutionsEnabled.add(resolution) | 133 | resolutionsEnabled.add(resolution) |
130 | } | 134 | } |
131 | 135 | ||
132 | if (includeInput) { | 136 | if (includeInput) { |
133 | resolutionsEnabled.add(input) | 137 | // Always use an even resolution to avoid issues with ffmpeg |
138 | resolutionsEnabled.add(toEven(input)) | ||
134 | } | 139 | } |
135 | 140 | ||
136 | return Array.from(resolutionsEnabled) | 141 | return Array.from(resolutionsEnabled) |