+// Generate an HLS playlist from an input file, and update the master playlist
+function generateHlsPlaylistResolution (options: {
+ video: MVideoFullLight
+ videoInputPath: string
+ resolution: VideoResolution
+ copyCodecs: boolean
+ isPortraitMode: boolean
+ job?: Job
+}) {
+ return generateHlsPlaylistCommon({
+ video: options.video,
+ resolution: options.resolution,
+ copyCodecs: options.copyCodecs,
+ isPortraitMode: options.isPortraitMode,
+ inputPath: options.videoInputPath,
+ type: 'hls' as 'hls',
+ job: options.job
+ })
+}
+
+function getEnabledResolutions (type: 'vod' | 'live') {
+ const transcoding = type === 'vod'
+ ? CONFIG.TRANSCODING
+ : CONFIG.LIVE.TRANSCODING
+
+ return Object.keys(transcoding.RESOLUTIONS)
+ .filter(key => transcoding.ENABLED && transcoding.RESOLUTIONS[key] === true)
+ .map(r => parseInt(r, 10))
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ generateHlsPlaylistResolution,
+ generateHlsPlaylistResolutionFromTS,
+ optimizeOriginalVideofile,
+ transcodeNewWebTorrentResolution,
+ mergeAudioVideofile,
+ getEnabledResolutions
+}
+
+// ---------------------------------------------------------------------------
+
+async function onWebTorrentVideoFileTranscoding (
+ video: MVideoFullLight,
+ videoFile: MVideoFile,
+ transcodingPath: string,
+ outputPath: string
+) {
+ const stats = await stat(transcodingPath)
+ const fps = await getVideoFileFPS(transcodingPath)
+ const metadata = await getMetadataFromFile(transcodingPath)
+
+ await move(transcodingPath, outputPath, { overwrite: true })
+
+ videoFile.size = stats.size
+ videoFile.fps = fps
+ videoFile.metadata = metadata
+
+ await createTorrentAndSetInfoHash(video, videoFile)
+
+ await VideoFileModel.customUpsert(videoFile, 'video', undefined)
+ video.VideoFiles = await video.$get('VideoFiles')
+
+ return video
+}
+
+async function generateHlsPlaylistCommon (options: {
+ type: 'hls' | 'hls-from-ts'
+ video: MVideoFullLight
+ inputPath: string
+ resolution: VideoResolution
+ copyCodecs?: boolean
+ isAAC?: boolean
+ isPortraitMode: boolean
+
+ job?: Job
+}) {
+ const { type, video, inputPath, resolution, copyCodecs, isPortraitMode, isAAC, job } = options
+ const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
+
+ const videoTranscodedBasePath = join(transcodeDirectory, type)
+ await ensureDir(videoTranscodedBasePath)
+
+ const videoFilename = generateVideoStreamingPlaylistName(video.uuid, resolution)
+ const playlistFilename = VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)
+ const playlistFileTranscodePath = join(videoTranscodedBasePath, playlistFilename)