diff options
author | Chocobozzz <me@florianbigard.com> | 2022-11-07 10:25:24 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-11-07 10:25:24 +0100 |
commit | a32bf8cd20212b903d3fa478e629f051eb77fecc (patch) | |
tree | 2a0372477ae2d76c31fc749054e78f1d067807d3 | |
parent | 11ae7e2917ddf6e3c8e53d0855fd786163112d59 (diff) | |
download | PeerTube-a32bf8cd20212b903d3fa478e629f051eb77fecc.tar.gz PeerTube-a32bf8cd20212b903d3fa478e629f051eb77fecc.tar.zst PeerTube-a32bf8cd20212b903d3fa478e629f051eb77fecc.zip |
Fix running again transcoding on a video only file
-rwxr-xr-x | scripts/create-transcoding-job.ts | 10 | ||||
-rw-r--r-- | server/controllers/api/videos/transcoding.ts | 6 | ||||
-rw-r--r-- | server/helpers/ffmpeg/ffprobe-utils.ts | 5 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-transcoding.ts | 5 | ||||
-rw-r--r-- | server/lib/live/live-manager.ts | 6 | ||||
-rw-r--r-- | server/lib/transcoding/transcoding.ts | 10 | ||||
-rw-r--r-- | server/models/video/video.ts | 4 |
7 files changed, 29 insertions, 17 deletions
diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts index ffdf55ae4..c77a5805f 100755 --- a/scripts/create-transcoding-job.ts +++ b/scripts/create-transcoding-job.ts | |||
@@ -49,11 +49,14 @@ async function run () { | |||
49 | const dataInput: VideoTranscodingPayload[] = [] | 49 | const dataInput: VideoTranscodingPayload[] = [] |
50 | const maxResolution = video.getMaxQualityFile().resolution | 50 | const maxResolution = video.getMaxQualityFile().resolution |
51 | 51 | ||
52 | // FIXME: check the file has audio | ||
53 | const hasAudio = true | ||
54 | |||
52 | // Generate HLS files | 55 | // Generate HLS files |
53 | if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { | 56 | if (options.generateHls || CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { |
54 | const resolutionsEnabled = options.resolution | 57 | const resolutionsEnabled = options.resolution |
55 | ? [ parseInt(options.resolution) ] | 58 | ? [ parseInt(options.resolution) ] |
56 | : computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false }) | 59 | : computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false, hasAudio }) |
57 | 60 | ||
58 | for (const resolution of resolutionsEnabled) { | 61 | for (const resolution of resolutionsEnabled) { |
59 | dataInput.push({ | 62 | dataInput.push({ |
@@ -61,7 +64,7 @@ async function run () { | |||
61 | videoUUID: video.uuid, | 64 | videoUUID: video.uuid, |
62 | resolution, | 65 | resolution, |
63 | 66 | ||
64 | hasAudio: true, | 67 | hasAudio, |
65 | 68 | ||
66 | copyCodecs: false, | 69 | copyCodecs: false, |
67 | isNewVideo: false, | 70 | isNewVideo: false, |
@@ -77,8 +80,7 @@ async function run () { | |||
77 | 80 | ||
78 | createHLSIfNeeded: true, | 81 | createHLSIfNeeded: true, |
79 | 82 | ||
80 | // FIXME: check the file has audio | 83 | hasAudio, |
81 | hasAudio: true, | ||
82 | 84 | ||
83 | isNewVideo: false, | 85 | isNewVideo: false, |
84 | resolution: parseInt(options.resolution) | 86 | resolution: parseInt(options.resolution) |
diff --git a/server/controllers/api/videos/transcoding.ts b/server/controllers/api/videos/transcoding.ts index 9aca761c1..a39e47dfe 100644 --- a/server/controllers/api/videos/transcoding.ts +++ b/server/controllers/api/videos/transcoding.ts | |||
@@ -32,9 +32,10 @@ async function createTranscoding (req: express.Request, res: express.Response) { | |||
32 | 32 | ||
33 | const body: VideoTranscodingCreate = req.body | 33 | const body: VideoTranscodingCreate = req.body |
34 | 34 | ||
35 | const { resolution: maxResolution, audioStream } = await video.probeMaxQualityFile() | 35 | const { resolution: maxResolution, hasAudio } = await video.probeMaxQualityFile() |
36 | |||
36 | const resolutions = await Hooks.wrapObject( | 37 | const resolutions = await Hooks.wrapObject( |
37 | computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false }), | 38 | computeResolutionsToTranscode({ input: maxResolution, type: 'vod', includeInput: true, strictLower: false, hasAudio }), |
38 | 'filter:transcoding.manual.resolutions-to-transcode.result', | 39 | 'filter:transcoding.manual.resolutions-to-transcode.result', |
39 | body | 40 | body |
40 | ) | 41 | ) |
@@ -46,7 +47,6 @@ async function createTranscoding (req: express.Request, res: express.Response) { | |||
46 | video.state = VideoState.TO_TRANSCODE | 47 | video.state = VideoState.TO_TRANSCODE |
47 | await video.save() | 48 | await video.save() |
48 | 49 | ||
49 | const hasAudio = !!audioStream | ||
50 | const childrenResolutions = resolutions.filter(r => r !== maxResolution) | 50 | const childrenResolutions = resolutions.filter(r => r !== maxResolution) |
51 | 51 | ||
52 | const children = await Bluebird.mapSeries(childrenResolutions, resolution => { | 52 | const children = await Bluebird.mapSeries(childrenResolutions, resolution => { |
diff --git a/server/helpers/ffmpeg/ffprobe-utils.ts b/server/helpers/ffmpeg/ffprobe-utils.ts index 2c6253d44..8cfdba4f9 100644 --- a/server/helpers/ffmpeg/ffprobe-utils.ts +++ b/server/helpers/ffmpeg/ffprobe-utils.ts | |||
@@ -96,8 +96,9 @@ function computeResolutionsToTranscode (options: { | |||
96 | type: 'vod' | 'live' | 96 | type: 'vod' | 'live' |
97 | includeInput: boolean | 97 | includeInput: boolean |
98 | strictLower: boolean | 98 | strictLower: boolean |
99 | hasAudio: boolean | ||
99 | }) { | 100 | }) { |
100 | const { input, type, includeInput, strictLower } = options | 101 | const { input, type, includeInput, strictLower, hasAudio } = options |
101 | 102 | ||
102 | const configResolutions = type === 'vod' | 103 | const configResolutions = type === 'vod' |
103 | ? CONFIG.TRANSCODING.RESOLUTIONS | 104 | ? CONFIG.TRANSCODING.RESOLUTIONS |
@@ -125,6 +126,8 @@ function computeResolutionsToTranscode (options: { | |||
125 | if (input < resolution) continue | 126 | if (input < resolution) continue |
126 | // We only want lower resolutions than input file | 127 | // We only want lower resolutions than input file |
127 | if (strictLower && input === resolution) continue | 128 | if (strictLower && input === resolution) continue |
129 | // Audio resolutio but no audio in the video | ||
130 | if (resolution === VideoResolution.H_NOVIDEO && !hasAudio) continue | ||
128 | 131 | ||
129 | resolutionsEnabled.add(resolution) | 132 | resolutionsEnabled.add(resolution) |
130 | } | 133 | } |
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 48c675678..3e6d23363 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts | |||
@@ -13,7 +13,6 @@ import { | |||
13 | MergeAudioTranscodingPayload, | 13 | MergeAudioTranscodingPayload, |
14 | NewWebTorrentResolutionTranscodingPayload, | 14 | NewWebTorrentResolutionTranscodingPayload, |
15 | OptimizeTranscodingPayload, | 15 | OptimizeTranscodingPayload, |
16 | VideoResolution, | ||
17 | VideoTranscodingPayload | 16 | VideoTranscodingPayload |
18 | } from '@shared/models' | 17 | } from '@shared/models' |
19 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 18 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
@@ -281,7 +280,7 @@ async function createLowerResolutionsJobs (options: { | |||
281 | 280 | ||
282 | // Create transcoding jobs if there are enabled resolutions | 281 | // Create transcoding jobs if there are enabled resolutions |
283 | const resolutionsEnabled = await Hooks.wrapObject( | 282 | const resolutionsEnabled = await Hooks.wrapObject( |
284 | computeResolutionsToTranscode({ input: videoFileResolution, type: 'vod', includeInput: false, strictLower: true }), | 283 | computeResolutionsToTranscode({ input: videoFileResolution, type: 'vod', includeInput: false, strictLower: true, hasAudio }), |
285 | 'filter:transcoding.auto.resolutions-to-transcode.result', | 284 | 'filter:transcoding.auto.resolutions-to-transcode.result', |
286 | options | 285 | options |
287 | ) | 286 | ) |
@@ -289,8 +288,6 @@ async function createLowerResolutionsJobs (options: { | |||
289 | const resolutionCreated: string[] = [] | 288 | const resolutionCreated: string[] = [] |
290 | 289 | ||
291 | for (const resolution of resolutionsEnabled) { | 290 | for (const resolution of resolutionsEnabled) { |
292 | if (resolution === VideoResolution.H_NOVIDEO && hasAudio === false) continue | ||
293 | |||
294 | let dataInput: VideoTranscodingPayload | 291 | let dataInput: VideoTranscodingPayload |
295 | 292 | ||
296 | if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED && type === 'webtorrent') { | 293 | if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED && type === 'webtorrent') { |
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 9470b530b..5e459f3c3 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts | |||
@@ -245,7 +245,7 @@ class LiveManager { | |||
245 | ) | 245 | ) |
246 | 246 | ||
247 | const allResolutions = await Hooks.wrapObject( | 247 | const allResolutions = await Hooks.wrapObject( |
248 | this.buildAllResolutionsToTranscode(resolution), | 248 | this.buildAllResolutionsToTranscode(resolution, hasAudio), |
249 | 'filter:transcoding.auto.resolutions-to-transcode.result', | 249 | 'filter:transcoding.auto.resolutions-to-transcode.result', |
250 | { video } | 250 | { video } |
251 | ) | 251 | ) |
@@ -460,11 +460,11 @@ class LiveManager { | |||
460 | return join(directory, files.sort().reverse()[0]) | 460 | return join(directory, files.sort().reverse()[0]) |
461 | } | 461 | } |
462 | 462 | ||
463 | private buildAllResolutionsToTranscode (originResolution: number) { | 463 | private buildAllResolutionsToTranscode (originResolution: number, hasAudio: boolean) { |
464 | const includeInput = CONFIG.LIVE.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION | 464 | const includeInput = CONFIG.LIVE.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION |
465 | 465 | ||
466 | const resolutionsEnabled = CONFIG.LIVE.TRANSCODING.ENABLED | 466 | const resolutionsEnabled = CONFIG.LIVE.TRANSCODING.ENABLED |
467 | ? computeResolutionsToTranscode({ input: originResolution, type: 'live', includeInput, strictLower: false }) | 467 | ? computeResolutionsToTranscode({ input: originResolution, type: 'live', includeInput, strictLower: false, hasAudio }) |
468 | : [] | 468 | : [] |
469 | 469 | ||
470 | if (resolutionsEnabled.length === 0) { | 470 | if (resolutionsEnabled.length === 0) { |
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts index d83c5419f..e6914db87 100644 --- a/server/lib/transcoding/transcoding.ts +++ b/server/lib/transcoding/transcoding.ts | |||
@@ -446,7 +446,15 @@ async function generateHlsPlaylistCommon (options: { | |||
446 | function buildOriginalFileResolution (inputResolution: number) { | 446 | function buildOriginalFileResolution (inputResolution: number) { |
447 | if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) return toEven(inputResolution) | 447 | if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) return toEven(inputResolution) |
448 | 448 | ||
449 | const resolutions = computeResolutionsToTranscode({ input: inputResolution, type: 'vod', includeInput: false, strictLower: false }) | 449 | const resolutions = computeResolutionsToTranscode({ |
450 | input: inputResolution, | ||
451 | type: 'vod', | ||
452 | includeInput: false, | ||
453 | strictLower: false, | ||
454 | // We don't really care about the audio resolution in this context | ||
455 | hasAudio: true | ||
456 | }) | ||
457 | |||
450 | if (resolutions.length === 0) return toEven(inputResolution) | 458 | if (resolutions.length === 0) return toEven(inputResolution) |
451 | 459 | ||
452 | return Math.max(...resolutions) | 460 | return Math.max(...resolutions) |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index f3907bed4..56cc45cfe 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -34,7 +34,7 @@ import { isVideoInPrivateDirectory } from '@server/lib/video-privacy' | |||
34 | import { getServerActor } from '@server/models/application/application' | 34 | import { getServerActor } from '@server/models/application/application' |
35 | import { ModelCache } from '@server/models/model-cache' | 35 | import { ModelCache } from '@server/models/model-cache' |
36 | import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils' | 36 | import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils' |
37 | import { ffprobePromise, getAudioStream, uuidToShort } from '@shared/extra-utils' | 37 | import { ffprobePromise, getAudioStream, hasAudioStream, uuidToShort } from '@shared/extra-utils' |
38 | import { | 38 | import { |
39 | ResultList, | 39 | ResultList, |
40 | ThumbnailType, | 40 | ThumbnailType, |
@@ -1751,9 +1751,11 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1751 | const probe = await ffprobePromise(originalFilePath) | 1751 | const probe = await ffprobePromise(originalFilePath) |
1752 | 1752 | ||
1753 | const { audioStream } = await getAudioStream(originalFilePath, probe) | 1753 | const { audioStream } = await getAudioStream(originalFilePath, probe) |
1754 | const hasAudio = await hasAudioStream(originalFilePath, probe) | ||
1754 | 1755 | ||
1755 | return { | 1756 | return { |
1756 | audioStream, | 1757 | audioStream, |
1758 | hasAudio, | ||
1757 | 1759 | ||
1758 | ...await getVideoStreamDimensionsInfo(originalFilePath, probe) | 1760 | ...await getVideoStreamDimensionsInfo(originalFilePath, probe) |
1759 | } | 1761 | } |