720p: false
1080p: false
# /!\ EXPERIMENTAL /!\
- # /!\ Requires ffmpeg >= 3.4
- # Generate HLS playlist/segments. Better playback than with WebTorrent:
+ # /!\ Requires ffmpeg >= 4
+ # Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent:
# * Resolution change is smoother
# * Faster playback in particular with long videos
# * More stable playback (less bugs/infinite loading)
- # /!\ Multiply videos storage by two /!\
+ # /!\ Multiply videos storage by 2 /!\
hls:
enabled: false
720p: false
1080p: false
# /!\ EXPERIMENTAL /!\
- # /!\ Requires ffmpeg >= 3.4
- # Generate HLS playlist/segments. Better playback than with WebTorrent:
+ # /!\ Requires ffmpeg >= 4
+ # Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent:
# * Resolution change is smoother
# * Faster playback in particular with long videos
# * More stable playback (less bugs/infinite loading)
- # /!\ Multiply videos storage by two /!\
+ # /!\ Multiply videos storage by 2 /!\
hls:
enabled: false
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[] = []
}
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')
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)
// ---------------------------------------------------------------------------
+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<any>((res, rej) => {
ffmpeg.ffprobe(path, (err, metadata) => {