+async function fixHLSPlaylistIfNeeded (options: TranscodeOptions) {
+ if (options.type !== 'hls' && options.type !== 'hls-from-ts') return
+
+ const fileContent = await readFile(options.outputPath)
+
+ const videoFileName = options.hlsPlaylist.videoFilename
+ const videoFilePath = getHLSVideoPath(options)
+
+ // Fix wrong mapping with some ffmpeg versions
+ const newContent = fileContent.toString()
+ .replace(`#EXT-X-MAP:URI="${videoFilePath}",`, `#EXT-X-MAP:URI="${videoFileName}",`)
+
+ await writeFile(options.outputPath, newContent)
+}
+
+function getHLSVideoPath (options: HLSTranscodeOptions | HLSFromTSTranscodeOptions) {
+ return `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}`
+}
+
+// ---------------------------------------------------------------------------
+// Transcoding presets
+// ---------------------------------------------------------------------------
+
+// Run encoder builder depending on available encoders
+// Try encoders by priority: if the encoder is available, run the chosen profile or fallback to the default one
+// If the default one does not exist, check the next encoder
+async function getEncoderBuilderResult (options: EncoderOptionsBuilderParams & {
+ streamType: 'video' | 'audio'
+ input: string
+
+ availableEncoders: AvailableEncoders
+ profile: string
+
+ videoType: 'vod' | 'live'
+}) {
+ const { availableEncoders, profile, streamType, videoType } = options
+
+ const encodersToTry = availableEncoders.encodersToTry[videoType][streamType]
+ const encoders = availableEncoders.available[videoType]
+
+ for (const encoder of encodersToTry) {
+ if (!(await checkFFmpegEncoders(availableEncoders)).get(encoder)) {
+ logger.debug('Encoder %s not available in ffmpeg, skipping.', encoder)
+ continue