+ const videoOutputPath = getVideoFilePath(video, inputVideoFile)
+ // ffmpeg generated a new video file, so update the video duration
+ // See https://trac.ffmpeg.org/ticket/5456
+ video.duration = await getDurationFromVideoFile(videoTranscodedPath)
+ await video.save()
+
+ return onWebTorrentVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath)
+}
+
+// Concat TS segments from a live video to a fragmented mp4 HLS playlist
+async function generateHlsPlaylistResolutionFromTS (options: {
+ video: MVideoWithFile
+ concatenatedTsFilePath: string
+ resolution: VideoResolution
+ isPortraitMode: boolean
+ isAAC: boolean
+}) {
+ return generateHlsPlaylistCommon({
+ video: options.video,
+ resolution: options.resolution,
+ isPortraitMode: options.isPortraitMode,
+ inputPath: options.concatenatedTsFilePath,
+ type: 'hls-from-ts' as 'hls-from-ts',
+ isAAC: options.isAAC
+ })
+}
+
+// Generate an HLS playlist from an input file, and update the master playlist
+function generateHlsPlaylistResolution (options: {
+ video: MVideoWithFile
+ 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: MVideoWithFile,
+ 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)