parent
66d332340e
commit
7f8f8bdb4a
|
@ -17,6 +17,7 @@
|
||||||
/config/local*
|
/config/local*
|
||||||
/ffmpeg/
|
/ffmpeg/
|
||||||
/ffmpeg-4/
|
/ffmpeg-4/
|
||||||
|
/ffmpeg-3/
|
||||||
/thumbnails/
|
/thumbnails/
|
||||||
/torrents/
|
/torrents/
|
||||||
/videos/
|
/videos/
|
||||||
|
|
|
@ -140,12 +140,12 @@ transcoding:
|
||||||
720p: false
|
720p: false
|
||||||
1080p: false
|
1080p: false
|
||||||
# /!\ EXPERIMENTAL /!\
|
# /!\ EXPERIMENTAL /!\
|
||||||
# /!\ Requires ffmpeg >= 3.4
|
# /!\ Requires ffmpeg >= 4
|
||||||
# Generate HLS playlist/segments. Better playback than with WebTorrent:
|
# Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent:
|
||||||
# * Resolution change is smoother
|
# * Resolution change is smoother
|
||||||
# * Faster playback in particular with long videos
|
# * Faster playback in particular with long videos
|
||||||
# * More stable playback (less bugs/infinite loading)
|
# * More stable playback (less bugs/infinite loading)
|
||||||
# /!\ Multiply videos storage by two /!\
|
# /!\ Multiply videos storage by 2 /!\
|
||||||
hls:
|
hls:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
|
|
|
@ -153,12 +153,12 @@ transcoding:
|
||||||
720p: false
|
720p: false
|
||||||
1080p: false
|
1080p: false
|
||||||
# /!\ EXPERIMENTAL /!\
|
# /!\ EXPERIMENTAL /!\
|
||||||
# /!\ Requires ffmpeg >= 3.4
|
# /!\ Requires ffmpeg >= 4
|
||||||
# Generate HLS playlist/segments. Better playback than with WebTorrent:
|
# Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent:
|
||||||
# * Resolution change is smoother
|
# * Resolution change is smoother
|
||||||
# * Faster playback in particular with long videos
|
# * Faster playback in particular with long videos
|
||||||
# * More stable playback (less bugs/infinite loading)
|
# * More stable playback (less bugs/infinite loading)
|
||||||
# /!\ Multiply videos storage by two /!\
|
# /!\ Multiply videos storage by 2 /!\
|
||||||
hls:
|
hls:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/cons
|
||||||
import { processImage } from './image-utils'
|
import { processImage } from './image-utils'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
import { checkFFmpegEncoders } from '../initializers/checker-before-init'
|
import { checkFFmpegEncoders } from '../initializers/checker-before-init'
|
||||||
import { remove } from 'fs-extra'
|
import { remove, readFile, writeFile } from 'fs-extra'
|
||||||
|
|
||||||
function computeResolutionsToTranscode (videoFileHeight: number) {
|
function computeResolutionsToTranscode (videoFileHeight: number) {
|
||||||
const resolutionsEnabled: number[] = []
|
const resolutionsEnabled: number[] = []
|
||||||
|
@ -164,7 +164,7 @@ function transcode (options: TranscodeOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.hlsPlaylist) {
|
if (options.hlsPlaylist) {
|
||||||
const videoPath = `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}`
|
const videoPath = getHLSVideoPath(options)
|
||||||
|
|
||||||
command = command.outputOption('-hls_time 4')
|
command = command.outputOption('-hls_time 4')
|
||||||
.outputOption('-hls_list_size 0')
|
.outputOption('-hls_list_size 0')
|
||||||
|
@ -180,7 +180,11 @@ function transcode (options: TranscodeOptions) {
|
||||||
logger.error('Error in transcoding job.', { stdout, stderr })
|
logger.error('Error in transcoding job.', { stdout, stderr })
|
||||||
return rej(err)
|
return rej(err)
|
||||||
})
|
})
|
||||||
.on('end', res)
|
.on('end', () => {
|
||||||
|
return onTranscodingSuccess(options)
|
||||||
|
.then(() => res())
|
||||||
|
.catch(err => rej(err))
|
||||||
|
})
|
||||||
.run()
|
.run()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return rej(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) {
|
function getVideoFileStream (path: string) {
|
||||||
return new Promise<any>((res, rej) => {
|
return new Promise<any>((res, rej) => {
|
||||||
ffmpeg.ffprobe(path, (err, metadata) => {
|
ffmpeg.ffprobe(path, (err, metadata) => {
|
||||||
|
|
Loading…
Reference in New Issue