diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/job-queue/handlers/video-transcoding.ts | 9 | ||||
-rw-r--r-- | server/lib/video-transcoding.ts | 36 |
2 files changed, 30 insertions, 15 deletions
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 20f8c3f50..083cec11a 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts | |||
@@ -44,20 +44,21 @@ async function processVideoTranscoding (job: Bull.Job) { | |||
44 | videoInputPath, | 44 | videoInputPath, |
45 | resolution: payload.resolution, | 45 | resolution: payload.resolution, |
46 | copyCodecs: payload.copyCodecs, | 46 | copyCodecs: payload.copyCodecs, |
47 | isPortraitMode: payload.isPortraitMode || false | 47 | isPortraitMode: payload.isPortraitMode || false, |
48 | job | ||
48 | }) | 49 | }) |
49 | 50 | ||
50 | await retryTransactionWrapper(onHlsPlaylistGenerationSuccess, video) | 51 | await retryTransactionWrapper(onHlsPlaylistGenerationSuccess, video) |
51 | } else if (payload.type === 'new-resolution') { | 52 | } else if (payload.type === 'new-resolution') { |
52 | await transcodeNewResolution(video, payload.resolution, payload.isPortraitMode || false) | 53 | await transcodeNewResolution(video, payload.resolution, payload.isPortraitMode || false, job) |
53 | 54 | ||
54 | await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload) | 55 | await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload) |
55 | } else if (payload.type === 'merge-audio') { | 56 | } else if (payload.type === 'merge-audio') { |
56 | await mergeAudioVideofile(video, payload.resolution) | 57 | await mergeAudioVideofile(video, payload.resolution, job) |
57 | 58 | ||
58 | await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload) | 59 | await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload) |
59 | } else { | 60 | } else { |
60 | const transcodeType = await optimizeOriginalVideofile(video) | 61 | const transcodeType = await optimizeOriginalVideofile(video, video.getMaxQualityFile(), job) |
61 | 62 | ||
62 | await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload, transcodeType) | 63 | await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload, transcodeType) |
63 | } | 64 | } |
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index a6b79eaea..beef78b44 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { Job } from 'bull' | ||
1 | import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' | 2 | import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' |
2 | import { basename, extname as extnameUtil, join } from 'path' | 3 | import { basename, extname as extnameUtil, join } from 'path' |
3 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | 4 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
@@ -23,11 +24,10 @@ import { availableEncoders } from './video-transcoding-profiles' | |||
23 | */ | 24 | */ |
24 | 25 | ||
25 | // Optimize the original video file and replace it. The resolution is not changed. | 26 | // Optimize the original video file and replace it. The resolution is not changed. |
26 | async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFileArg?: MVideoFile) { | 27 | async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFile: MVideoFile, job?: Job) { |
27 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | 28 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR |
28 | const newExtname = '.mp4' | 29 | const newExtname = '.mp4' |
29 | 30 | ||
30 | const inputVideoFile = inputVideoFileArg || video.getMaxQualityFile() | ||
31 | const videoInputPath = getVideoFilePath(video, inputVideoFile) | 31 | const videoInputPath = getVideoFilePath(video, inputVideoFile) |
32 | const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) | 32 | const videoTranscodedPath = join(transcodeDirectory, video.id + '-transcoded' + newExtname) |
33 | 33 | ||
@@ -44,7 +44,9 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFileA | |||
44 | availableEncoders, | 44 | availableEncoders, |
45 | profile: 'default', | 45 | profile: 'default', |
46 | 46 | ||
47 | resolution: inputVideoFile.resolution | 47 | resolution: inputVideoFile.resolution, |
48 | |||
49 | job | ||
48 | } | 50 | } |
49 | 51 | ||
50 | // Could be very long! | 52 | // Could be very long! |
@@ -70,7 +72,7 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFileA | |||
70 | } | 72 | } |
71 | 73 | ||
72 | // Transcode the original video file to a lower resolution. | 74 | // Transcode the original video file to a lower resolution. |
73 | async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoResolution, isPortrait: boolean) { | 75 | async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoResolution, isPortrait: boolean, job: Job) { |
74 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | 76 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR |
75 | const extname = '.mp4' | 77 | const extname = '.mp4' |
76 | 78 | ||
@@ -96,7 +98,9 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR | |||
96 | availableEncoders, | 98 | availableEncoders, |
97 | profile: 'default', | 99 | profile: 'default', |
98 | 100 | ||
99 | resolution | 101 | resolution, |
102 | |||
103 | job | ||
100 | } | 104 | } |
101 | : { | 105 | : { |
102 | type: 'video' as 'video', | 106 | type: 'video' as 'video', |
@@ -107,7 +111,9 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR | |||
107 | profile: 'default', | 111 | profile: 'default', |
108 | 112 | ||
109 | resolution, | 113 | resolution, |
110 | isPortraitMode: isPortrait | 114 | isPortraitMode: isPortrait, |
115 | |||
116 | job | ||
111 | } | 117 | } |
112 | 118 | ||
113 | await transcode(transcodeOptions) | 119 | await transcode(transcodeOptions) |
@@ -116,7 +122,7 @@ async function transcodeNewResolution (video: MVideoWithFile, resolution: VideoR | |||
116 | } | 122 | } |
117 | 123 | ||
118 | // Merge an image with an audio file to create a video | 124 | // Merge an image with an audio file to create a video |
119 | async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: VideoResolution) { | 125 | async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: VideoResolution, job: Job) { |
120 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR | 126 | const transcodeDirectory = CONFIG.STORAGE.TMP_DIR |
121 | const newExtname = '.mp4' | 127 | const newExtname = '.mp4' |
122 | 128 | ||
@@ -140,7 +146,9 @@ async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: Video | |||
140 | profile: 'default', | 146 | profile: 'default', |
141 | 147 | ||
142 | audioPath: audioInputPath, | 148 | audioPath: audioInputPath, |
143 | resolution | 149 | resolution, |
150 | |||
151 | job | ||
144 | } | 152 | } |
145 | 153 | ||
146 | try { | 154 | try { |
@@ -190,6 +198,7 @@ function generateHlsPlaylist (options: { | |||
190 | resolution: VideoResolution | 198 | resolution: VideoResolution |
191 | copyCodecs: boolean | 199 | copyCodecs: boolean |
192 | isPortraitMode: boolean | 200 | isPortraitMode: boolean |
201 | job?: Job | ||
193 | }) { | 202 | }) { |
194 | return generateHlsPlaylistCommon({ | 203 | return generateHlsPlaylistCommon({ |
195 | video: options.video, | 204 | video: options.video, |
@@ -197,7 +206,8 @@ function generateHlsPlaylist (options: { | |||
197 | copyCodecs: options.copyCodecs, | 206 | copyCodecs: options.copyCodecs, |
198 | isPortraitMode: options.isPortraitMode, | 207 | isPortraitMode: options.isPortraitMode, |
199 | inputPath: options.videoInputPath, | 208 | inputPath: options.videoInputPath, |
200 | type: 'hls' as 'hls' | 209 | type: 'hls' as 'hls', |
210 | job: options.job | ||
201 | }) | 211 | }) |
202 | } | 212 | } |
203 | 213 | ||
@@ -251,8 +261,10 @@ async function generateHlsPlaylistCommon (options: { | |||
251 | copyCodecs?: boolean | 261 | copyCodecs?: boolean |
252 | isAAC?: boolean | 262 | isAAC?: boolean |
253 | isPortraitMode: boolean | 263 | isPortraitMode: boolean |
264 | |||
265 | job?: Job | ||
254 | }) { | 266 | }) { |
255 | const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC } = options | 267 | const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC, job } = options |
256 | 268 | ||
257 | const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) | 269 | const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) |
258 | await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) | 270 | await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) |
@@ -277,7 +289,9 @@ async function generateHlsPlaylistCommon (options: { | |||
277 | 289 | ||
278 | hlsPlaylist: { | 290 | hlsPlaylist: { |
279 | videoFilename | 291 | videoFilename |
280 | } | 292 | }, |
293 | |||
294 | job | ||
281 | } | 295 | } |
282 | 296 | ||
283 | await transcode(transcodeOptions) | 297 | await transcode(transcodeOptions) |