@@ -270,18 +270,20 @@ async function generateHlsPlaylistCommon (options: {
270
270
job ?: Job
271
271
} ) {
272
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
- await ensureDir ( join ( HLS_STREAMING_PLAYLIST_DIRECTORY , video . uuid ) )
275
+ const videoTranscodedBasePath = join ( transcodeDirectory , type , video . uuid )
276
+ await ensureDir ( videoTranscodedBasePath )
276
277
277
- const outputPath = join ( baseHlsDirectory , VideoStreamingPlaylistModel . getHlsPlaylistFilename ( resolution ) )
278
278
const videoFilename = generateVideoStreamingPlaylistName ( video . uuid , resolution )
279
+ const playlistFilename = VideoStreamingPlaylistModel . getHlsPlaylistFilename ( resolution )
280
+ const playlistFileTranscodePath = join ( videoTranscodedBasePath , playlistFilename )
279
281
280
282
const transcodeOptions = {
281
283
type,
282
284
283
285
inputPath,
284
- outputPath,
286
+ outputPath : playlistFileTranscodePath ,
285
287
286
288
availableEncoders : VideoTranscodingProfilesManager . Instance . getAvailableEncoders ( ) ,
287
289
profile : CONFIG . TRANSCODING . PROFILE ,
@@ -303,6 +305,7 @@ async function generateHlsPlaylistCommon (options: {
303
305
304
306
const playlistUrl = WEBSERVER . URL + VideoStreamingPlaylistModel . getHlsMasterPlaylistStaticPath ( video . uuid )
305
307
308
+ // Create or update the playlist
306
309
const [ videoStreamingPlaylist ] = await VideoStreamingPlaylistModel . upsert ( {
307
310
videoId : video . id ,
308
311
playlistUrl,
@@ -314,6 +317,7 @@ async function generateHlsPlaylistCommon (options: {
314
317
} , { returning : true } ) as [ MStreamingPlaylistFilesVideo , boolean ]
315
318
videoStreamingPlaylist . Video = video
316
319
320
+ // Build the new playlist file
317
321
const newVideoFile = new VideoFileModel ( {
318
322
resolution,
319
323
extname : extnameUtil ( videoFilename ) ,
@@ -323,6 +327,19 @@ async function generateHlsPlaylistCommon (options: {
323
327
} )
324
328
325
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
343
const stats = await stat ( videoFilePath )
327
344
328
345
newVideoFile . size = stats . size
@@ -344,5 +361,5 @@ async function generateHlsPlaylistCommon (options: {
344
361
await updateMasterHLSPlaylist ( video )
345
362
await updateSha256VODSegments ( video )
346
363
347
- return outputPath
364
+ return playlistPath
348
365
}
0 commit comments