HLS is only supported by ffmpeg 4

Because of c8f625f529
pull/1631/head
Chocobozzz 2019-02-11 17:20:28 +01:00
parent 66d332340e
commit 7f8f8bdb4a
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 33 additions and 9 deletions

1
.gitignore vendored
View File

@ -17,6 +17,7 @@
/config/local*
/ffmpeg/
/ffmpeg-4/
/ffmpeg-3/
/thumbnails/
/torrents/
/videos/

View File

@ -140,12 +140,12 @@ transcoding:
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

View File

@ -153,12 +153,12 @@ transcoding:
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

View File

@ -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<any>((res, rej) => {
ffmpeg.ffprobe(path, (err, metadata) => {