From 7f8f8bdb4a1fb695a114874c4679605ac8911e2d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 11 Feb 2019 17:20:28 +0100 Subject: HLS is only supported by ffmpeg 4 Because of https://github.com/FFmpeg/FFmpeg/commit/c8f625f52998faa9bf0fe22701f1684e51edfc07 --- server/helpers/ffmpeg-utils.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 133b1b03b..b6b64de3f 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -5,7 +5,7 @@ import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/cons import { processImage } from './image-utils' import { logger } from './logger' import { checkFFmpegEncoders } from '../initializers/checker-before-init' -import { remove } from 'fs-extra' +import { remove, readFile, writeFile } from 'fs-extra' function computeResolutionsToTranscode (videoFileHeight: number) { const resolutionsEnabled: number[] = [] @@ -164,7 +164,7 @@ function transcode (options: TranscodeOptions) { } if (options.hlsPlaylist) { - const videoPath = `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}` + const videoPath = getHLSVideoPath(options) command = command.outputOption('-hls_time 4') .outputOption('-hls_list_size 0') @@ -180,7 +180,11 @@ function transcode (options: TranscodeOptions) { logger.error('Error in transcoding job.', { stdout, stderr }) return rej(err) }) - .on('end', res) + .on('end', () => { + return onTranscodingSuccess(options) + .then(() => res()) + .catch(err => rej(err)) + }) .run() } catch (err) { return rej(err) @@ -204,6 +208,25 @@ export { // --------------------------------------------------------------------------- +function getHLSVideoPath (options: TranscodeOptions) { + return `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}` +} + +async function onTranscodingSuccess (options: TranscodeOptions) { + if (!options.hlsPlaylist) return + + // Fix wrong mapping with some ffmpeg versions + const fileContent = await readFile(options.outputPath) + + const videoFileName = options.hlsPlaylist.videoFilename + const videoFilePath = getHLSVideoPath(options) + + const newContent = fileContent.toString() + .replace(`#EXT-X-MAP:URI="${videoFilePath}",`, `#EXT-X-MAP:URI="${videoFileName}",`) + + await writeFile(options.outputPath, newContent) +} + function getVideoFileStream (path: string) { return new Promise((res, rej) => { ffmpeg.ffprobe(path, (err, metadata) => { -- cgit v1.2.3