aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-02 11:50:29 +0100
committerChocobozzz <me@florianbigard.com>2021-02-02 11:50:29 +0100
commitaaedadd5386b580e9ebac540201399c25c7f0b0f (patch)
treedacc9a55c4356a4ea2c112658afee04dd3160877 /server/lib
parentd8ba4921191ee2b3dda976c3c3d5cf4b9dd17619 (diff)
downloadPeerTube-aaedadd5386b580e9ebac540201399c25c7f0b0f.tar.gz
PeerTube-aaedadd5386b580e9ebac540201399c25c7f0b0f.tar.zst
PeerTube-aaedadd5386b580e9ebac540201399c25c7f0b0f.zip
Transcode HLS playlists in a tmp directory
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/video-transcoding.ts27
1 files changed, 22 insertions, 5 deletions
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index 37a4f3019..d32372fe5 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -270,18 +270,20 @@ async function generateHlsPlaylistCommon (options: {
270 job?: Job 270 job?: Job
271}) { 271}) {
272 const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC, job } = options 272 const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC, job } = options
273 const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
273 274
274 const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) 275 const videoTranscodedBasePath = join(transcodeDirectory, type, video.uuid)
275 await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) 276 await ensureDir(videoTranscodedBasePath)
276 277
277 const outputPath = join(baseHlsDirectory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution))
278 const videoFilename = generateVideoStreamingPlaylistName(video.uuid, resolution) 278 const videoFilename = generateVideoStreamingPlaylistName(video.uuid, resolution)
279 const playlistFilename = VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)
280 const playlistFileTranscodePath = join(videoTranscodedBasePath, playlistFilename)
279 281
280 const transcodeOptions = { 282 const transcodeOptions = {
281 type, 283 type,
282 284
283 inputPath, 285 inputPath,
284 outputPath, 286 outputPath: playlistFileTranscodePath,
285 287
286 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(), 288 availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),
287 profile: CONFIG.TRANSCODING.PROFILE, 289 profile: CONFIG.TRANSCODING.PROFILE,
@@ -303,6 +305,7 @@ async function generateHlsPlaylistCommon (options: {
303 305
304 const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) 306 const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
305 307
308 // Create or update the playlist
306 const [ videoStreamingPlaylist ] = await VideoStreamingPlaylistModel.upsert({ 309 const [ videoStreamingPlaylist ] = await VideoStreamingPlaylistModel.upsert({
307 videoId: video.id, 310 videoId: video.id,
308 playlistUrl, 311 playlistUrl,
@@ -314,6 +317,7 @@ async function generateHlsPlaylistCommon (options: {
314 }, { returning: true }) as [ MStreamingPlaylistFilesVideo, boolean ] 317 }, { returning: true }) as [ MStreamingPlaylistFilesVideo, boolean ]
315 videoStreamingPlaylist.Video = video 318 videoStreamingPlaylist.Video = video
316 319
320 // Build the new playlist file
317 const newVideoFile = new VideoFileModel({ 321 const newVideoFile = new VideoFileModel({
318 resolution, 322 resolution,
319 extname: extnameUtil(videoFilename), 323 extname: extnameUtil(videoFilename),
@@ -323,6 +327,19 @@ async function generateHlsPlaylistCommon (options: {
323 }) 327 })
324 328
325 const videoFilePath = getVideoFilePath(videoStreamingPlaylist, newVideoFile) 329 const videoFilePath = getVideoFilePath(videoStreamingPlaylist, newVideoFile)
330
331 // Move files from tmp transcoded directory to the appropriate place
332 const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
333 await ensureDir(baseHlsDirectory)
334
335 // Move playlist file
336 const playlistPath = join(baseHlsDirectory, playlistFilename)
337 await move(playlistFileTranscodePath, playlistPath)
338 // Move video file
339 await move(join(videoTranscodedBasePath, videoFilename), videoFilePath)
340 // Cleanup directory
341 await remove(videoTranscodedBasePath)
342
326 const stats = await stat(videoFilePath) 343 const stats = await stat(videoFilePath)
327 344
328 newVideoFile.size = stats.size 345 newVideoFile.size = stats.size
@@ -344,5 +361,5 @@ async function generateHlsPlaylistCommon (options: {
344 await updateMasterHLSPlaylist(video) 361 await updateMasterHLSPlaylist(video)
345 await updateSha256VODSegments(video) 362 await updateSha256VODSegments(video)
346 363
347 return outputPath 364 return playlistPath
348} 365}