Add hls support on server

This commit is contained in:
Chocobozzz 2019-01-29 08:37:25 +01:00 committed by Chocobozzz
parent 4348a27d25
commit 0920929696
81 changed files with 2000 additions and 407 deletions

View file

@ -1,5 +1,5 @@
import * as ffmpeg from 'fluent-ffmpeg'
import { join } from 'path'
import { dirname, join } from 'path'
import { getTargetBitrate, VideoResolution } from '../../shared/models/videos'
import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants'
import { processImage } from './image-utils'
@ -29,12 +29,21 @@ function computeResolutionsToTranscode (videoFileHeight: number) {
return resolutionsEnabled
}
async function getVideoFileResolution (path: string) {
async function getVideoFileSize (path: string) {
const videoStream = await getVideoFileStream(path)
return {
videoFileResolution: Math.min(videoStream.height, videoStream.width),
isPortraitMode: videoStream.height > videoStream.width
width: videoStream.width,
height: videoStream.height
}
}
async function getVideoFileResolution (path: string) {
const size = await getVideoFileSize(path)
return {
videoFileResolution: Math.min(size.height, size.width),
isPortraitMode: size.height > size.width
}
}
@ -110,8 +119,10 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima
type TranscodeOptions = {
inputPath: string
outputPath: string
resolution?: VideoResolution
resolution: VideoResolution
isPortraitMode?: boolean
generateHlsPlaylist?: boolean
}
function transcode (options: TranscodeOptions) {
@ -150,6 +161,16 @@ function transcode (options: TranscodeOptions) {
command = command.withFPS(fps)
}
if (options.generateHlsPlaylist) {
const segmentFilename = `${dirname(options.outputPath)}/${options.resolution}_%03d.ts`
command = command.outputOption('-hls_time 4')
.outputOption('-hls_list_size 0')
.outputOption('-hls_playlist_type vod')
.outputOption('-hls_segment_filename ' + segmentFilename)
.outputOption('-f hls')
}
command
.on('error', (err, stdout, stderr) => {
logger.error('Error in transcoding job.', { stdout, stderr })
@ -166,6 +187,7 @@ function transcode (options: TranscodeOptions) {
// ---------------------------------------------------------------------------
export {
getVideoFileSize,
getVideoFileResolution,
getDurationFromVideoFile,
generateImageFromVideoFile,