]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/hls.ts
Generate random uuid for video files
[github/Chocobozzz/PeerTube.git] / server / lib / hls.ts
index 84539e2c1f5cd00fc7a9bf3e5649b153994e31f6..212bd095be9cb01fdd7b3fbb3c194c8fefc52cb3 100644 (file)
@@ -36,8 +36,10 @@ async function updateMasterHLSPlaylist (video: MVideoWithFile) {
   const streamingPlaylist = video.getHLSPlaylist()
 
   for (const file of streamingPlaylist.VideoFiles) {
+    const playlistFilename = VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution)
+
     // If we did not generated a playlist for this resolution, skip
-    const filePlaylistPath = join(directory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution))
+    const filePlaylistPath = join(directory, playlistFilename)
     if (await pathExists(filePlaylistPath) === false) continue
 
     const videoFilePath = getVideoFilePath(streamingPlaylist, file)
@@ -50,16 +52,15 @@ async function updateMasterHLSPlaylist (video: MVideoWithFile) {
     let line = `#EXT-X-STREAM-INF:${bandwidth},${resolution}`
     if (file.fps) line += ',FRAME-RATE=' + file.fps
 
-    const videoCodec = await getVideoStreamCodec(videoFilePath)
-    line += `,CODECS="${videoCodec}`
-
-    const audioCodec = await getAudioStreamCodec(videoFilePath)
-    if (audioCodec) line += `,${audioCodec}`
+    const codecs = await Promise.all([
+      getVideoStreamCodec(videoFilePath),
+      getAudioStreamCodec(videoFilePath)
+    ])
 
-    line += '"'
+    line += `,CODECS="${codecs.filter(c => !!c).join(',')}"`
 
     masterPlaylists.push(line)
-    masterPlaylists.push(VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution))
+    masterPlaylists.push(playlistFilename)
   }
 
   await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n')