aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/video-transcoding.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers/video-transcoding.ts')
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts26
1 files changed, 18 insertions, 8 deletions
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index b6b8d9071..04143eec3 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -18,6 +18,7 @@ import { federateVideoIfNeeded } from '../../activitypub/videos'
18import { Notifier } from '../../notifier' 18import { Notifier } from '../../notifier'
19import { generateHlsPlaylist, mergeAudioVideofile, optimizeOriginalVideofile, transcodeNewResolution } from '../../video-transcoding' 19import { generateHlsPlaylist, mergeAudioVideofile, optimizeOriginalVideofile, transcodeNewResolution } from '../../video-transcoding'
20import { JobQueue } from '../job-queue' 20import { JobQueue } from '../job-queue'
21import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils'
21 22
22async function processVideoTranscoding (job: Bull.Job) { 23async function processVideoTranscoding (job: Bull.Job) {
23 const payload = job.data as VideoTranscodingPayload 24 const payload = job.data as VideoTranscodingPayload
@@ -56,9 +57,9 @@ async function processVideoTranscoding (job: Bull.Job) {
56 57
57 await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload) 58 await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload)
58 } else { 59 } else {
59 await optimizeOriginalVideofile(video) 60 const transcodeType = await optimizeOriginalVideofile(video)
60 61
61 await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload) 62 await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload, transcodeType)
62 } 63 }
63 64
64 return video 65 return video
@@ -83,10 +84,14 @@ async function onHlsPlaylistGenerationSuccess (video: MVideoFullLight) {
83async function publishNewResolutionIfNeeded (video: MVideoUUID, payload?: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload) { 84async function publishNewResolutionIfNeeded (video: MVideoUUID, payload?: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload) {
84 await publishAndFederateIfNeeded(video) 85 await publishAndFederateIfNeeded(video)
85 86
86 await createHlsJobIfEnabled(payload) 87 createHlsJobIfEnabled(Object.assign({}, payload, { copyCodecs: true })
87} 88}
88 89
89async function onVideoFileOptimizerSuccess (videoArg: MVideoWithFile, payload: OptimizeTranscodingPayload) { 90async function onVideoFileOptimizerSuccess (
91 videoArg: MVideoWithFile,
92 payload: OptimizeTranscodingPayload,
93 transcodeType: TranscodeOptionsType
94) {
90 if (videoArg === undefined) return undefined 95 if (videoArg === undefined) return undefined
91 96
92 // Outside the transaction (IO on disk) 97 // Outside the transaction (IO on disk)
@@ -108,8 +113,13 @@ async function onVideoFileOptimizerSuccess (videoArg: MVideoWithFile, payload: O
108 let videoPublished = false 113 let videoPublished = false
109 114
110 // Generate HLS version of the max quality file 115 // Generate HLS version of the max quality file
111 const hlsPayload = Object.assign({}, payload, { resolution: videoDatabase.getMaxQualityFile().resolution }) 116 const originalFileHLSPayload = Object.assign({}, payload, {
112 await createHlsJobIfEnabled(hlsPayload) 117 isPortraitMode,
118 resolution: videoDatabase.getMaxQualityFile().resolution,
119 // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
120 copyCodecs: transcodeType !== 'quick-transcode'
121 })
122 createHlsJobIfEnabled(originalFileHLSPayload)
113 123
114 if (resolutionsEnabled.length !== 0) { 124 if (resolutionsEnabled.length !== 0) {
115 for (const resolution of resolutionsEnabled) { 125 for (const resolution of resolutionsEnabled) {
@@ -161,7 +171,7 @@ export {
161 171
162// --------------------------------------------------------------------------- 172// ---------------------------------------------------------------------------
163 173
164function createHlsJobIfEnabled (payload?: { videoUUID: string, resolution: number, isPortraitMode?: boolean }) { 174function createHlsJobIfEnabled (payload: { videoUUID: string, resolution: number, isPortraitMode?: boolean, copyCodecs: boolean }) {
165 // Generate HLS playlist? 175 // Generate HLS playlist?
166 if (payload && CONFIG.TRANSCODING.HLS.ENABLED) { 176 if (payload && CONFIG.TRANSCODING.HLS.ENABLED) {
167 const hlsTranscodingPayload = { 177 const hlsTranscodingPayload = {
@@ -169,7 +179,7 @@ function createHlsJobIfEnabled (payload?: { videoUUID: string, resolution: numbe
169 videoUUID: payload.videoUUID, 179 videoUUID: payload.videoUUID,
170 resolution: payload.resolution, 180 resolution: payload.resolution,
171 isPortraitMode: payload.isPortraitMode, 181 isPortraitMode: payload.isPortraitMode,
172 copyCodecs: true 182 copyCodecs: payload.copyCodecs
173 } 183 }
174 184
175 return JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload }) 185 return JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload })