- const playlistFiles: string[] = []
-
- for (const file of rootFiles) {
- // Move remaining files in the replay directory
- if (file.endsWith('.ts') || file.endsWith('.m3u8')) {
- await copy(join(hlsDirectory, file), join(replayDirectory, file))
- }
-
- if (file.endsWith('.m3u8') && file !== 'master.m3u8') {
- playlistFiles.push(file)
- }
- }
-
- const replayFiles = await readdir(replayDirectory)
-
- const resolutions: number[] = []
- let duration: number
-
- for (const playlistFile of playlistFiles) {
- const playlistPath = join(replayDirectory, playlistFile)
- const { videoFileResolution } = await getVideoFileResolution(playlistPath)
-
- // Put the final mp4 in the hls directory, and not in the replay directory
- const mp4TmpPath = buildMP4TmpPath(hlsDirectory, videoFileResolution)
-
- // Playlist name is for example 3.m3u8
- // Segments names are 3-0.ts 3-1.ts etc
- const shouldStartWith = playlistFile.replace(/\.m3u8$/, '') + '-'
-
- const segmentFiles = replayFiles.filter(f => f.startsWith(shouldStartWith) && f.endsWith('.ts'))
- await hlsPlaylistToFragmentedMP4(replayDirectory, segmentFiles, mp4TmpPath)
-
- if (!duration) {
- duration = await getDurationFromVideoFile(mp4TmpPath)
- }
-
- resolutions.push(videoFileResolution)
- }