diff options
author | Chocobozzz <me@florianbigard.com> | 2022-10-12 16:09:02 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-10-24 14:48:24 +0200 |
commit | 3545e72c686ff1725bbdfd8d16d693e2f4aa75a3 (patch) | |
tree | e7f1d12ef5dae1e1142c3a8d0b681c1dbbb0de10 /server/lib/job-queue/handlers/video-transcoding.ts | |
parent | 38a3ccc7f8ad0ea94362b58c732af7c387ab46be (diff) | |
download | PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.gz PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.tar.zst PeerTube-3545e72c686ff1725bbdfd8d16d693e2f4aa75a3.zip |
Put private videos under a specific subdirectory
Diffstat (limited to 'server/lib/job-queue/handlers/video-transcoding.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-transcoding.ts | 95 |
1 files changed, 55 insertions, 40 deletions
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index b0e92acf7..48c675678 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts | |||
@@ -94,15 +94,24 @@ async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, video: MV | |||
94 | 94 | ||
95 | const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist() | 95 | const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist() |
96 | 96 | ||
97 | await VideoPathManager.Instance.makeAvailableVideoFile(videoFileInput.withVideoOrPlaylist(videoOrStreamingPlaylist), videoInputPath => { | 97 | const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) |
98 | return generateHlsPlaylistResolution({ | 98 | |
99 | video, | 99 | try { |
100 | videoInputPath, | 100 | await videoFileInput.getVideo().reload() |
101 | resolution: payload.resolution, | 101 | |
102 | copyCodecs: payload.copyCodecs, | 102 | await VideoPathManager.Instance.makeAvailableVideoFile(videoFileInput.withVideoOrPlaylist(videoOrStreamingPlaylist), videoInputPath => { |
103 | job | 103 | return generateHlsPlaylistResolution({ |
104 | video, | ||
105 | videoInputPath, | ||
106 | inputFileMutexReleaser, | ||
107 | resolution: payload.resolution, | ||
108 | copyCodecs: payload.copyCodecs, | ||
109 | job | ||
110 | }) | ||
104 | }) | 111 | }) |
105 | }) | 112 | } finally { |
113 | inputFileMutexReleaser() | ||
114 | } | ||
106 | 115 | ||
107 | logger.info('HLS transcoding job for %s ended.', video.uuid, lTags(video.uuid)) | 116 | logger.info('HLS transcoding job for %s ended.', video.uuid, lTags(video.uuid)) |
108 | 117 | ||
@@ -177,38 +186,44 @@ async function onVideoFirstWebTorrentTranscoding ( | |||
177 | transcodeType: TranscodeVODOptionsType, | 186 | transcodeType: TranscodeVODOptionsType, |
178 | user: MUserId | 187 | user: MUserId |
179 | ) { | 188 | ) { |
180 | const { resolution, audioStream } = await videoArg.probeMaxQualityFile() | 189 | const mutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid) |
181 | 190 | ||
182 | // Maybe the video changed in database, refresh it | 191 | try { |
183 | const videoDatabase = await VideoModel.loadFull(videoArg.uuid) | 192 | // Maybe the video changed in database, refresh it |
184 | // Video does not exist anymore | 193 | const videoDatabase = await VideoModel.loadFull(videoArg.uuid) |
185 | if (!videoDatabase) return undefined | 194 | // Video does not exist anymore |
186 | 195 | if (!videoDatabase) return undefined | |
187 | // Generate HLS version of the original file | 196 | |
188 | const originalFileHLSPayload = { | 197 | const { resolution, audioStream } = await videoDatabase.probeMaxQualityFile() |
189 | ...payload, | 198 | |
190 | 199 | // Generate HLS version of the original file | |
191 | hasAudio: !!audioStream, | 200 | const originalFileHLSPayload = { |
192 | resolution: videoDatabase.getMaxQualityFile().resolution, | 201 | ...payload, |
193 | // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues | 202 | |
194 | copyCodecs: transcodeType !== 'quick-transcode', | 203 | hasAudio: !!audioStream, |
195 | isMaxQuality: true | 204 | resolution: videoDatabase.getMaxQualityFile().resolution, |
196 | } | 205 | // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues |
197 | const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload) | 206 | copyCodecs: transcodeType !== 'quick-transcode', |
198 | const hasNewResolutions = await createLowerResolutionsJobs({ | 207 | isMaxQuality: true |
199 | video: videoDatabase, | 208 | } |
200 | user, | 209 | const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload) |
201 | videoFileResolution: resolution, | 210 | const hasNewResolutions = await createLowerResolutionsJobs({ |
202 | hasAudio: !!audioStream, | 211 | video: videoDatabase, |
203 | type: 'webtorrent', | 212 | user, |
204 | isNewVideo: payload.isNewVideo ?? true | 213 | videoFileResolution: resolution, |
205 | }) | 214 | hasAudio: !!audioStream, |
206 | 215 | type: 'webtorrent', | |
207 | await VideoJobInfoModel.decrease(videoDatabase.uuid, 'pendingTranscode') | 216 | isNewVideo: payload.isNewVideo ?? true |
208 | 217 | }) | |
209 | // Move to next state if there are no other resolutions to generate | 218 | |
210 | if (!hasHls && !hasNewResolutions) { | 219 | await VideoJobInfoModel.decrease(videoDatabase.uuid, 'pendingTranscode') |
211 | await retryTransactionWrapper(moveToNextState, { video: videoDatabase, isNewVideo: payload.isNewVideo }) | 220 | |
221 | // Move to next state if there are no other resolutions to generate | ||
222 | if (!hasHls && !hasNewResolutions) { | ||
223 | await retryTransactionWrapper(moveToNextState, { video: videoDatabase, isNewVideo: payload.isNewVideo }) | ||
224 | } | ||
225 | } finally { | ||
226 | mutexReleaser() | ||
212 | } | 227 | } |
213 | } | 228 | } |
214 | 229 | ||