diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-29 08:37:25 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-02-11 09:13:02 +0100 |
commit | 092092969633bbcf6d4891a083ea497a7d5c3154 (patch) | |
tree | 69e82fe4f60c444cca216830e96afe143a9dac71 /server/helpers/ffmpeg-utils.ts | |
parent | 4348a27d252a3349bafa7ef4859c0e2cf060c255 (diff) | |
download | PeerTube-092092969633bbcf6d4891a083ea497a7d5c3154.tar.gz PeerTube-092092969633bbcf6d4891a083ea497a7d5c3154.tar.zst PeerTube-092092969633bbcf6d4891a083ea497a7d5c3154.zip |
Add hls support on server
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 132f4690e..5ad8ed48e 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as ffmpeg from 'fluent-ffmpeg' | 1 | import * as ffmpeg from 'fluent-ffmpeg' |
2 | import { join } from 'path' | 2 | import { dirname, join } from 'path' |
3 | import { getTargetBitrate, VideoResolution } from '../../shared/models/videos' | 3 | import { getTargetBitrate, VideoResolution } from '../../shared/models/videos' |
4 | import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' | 4 | import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' |
5 | import { processImage } from './image-utils' | 5 | import { processImage } from './image-utils' |
@@ -29,12 +29,21 @@ function computeResolutionsToTranscode (videoFileHeight: number) { | |||
29 | return resolutionsEnabled | 29 | return resolutionsEnabled |
30 | } | 30 | } |
31 | 31 | ||
32 | async function getVideoFileResolution (path: string) { | 32 | async function getVideoFileSize (path: string) { |
33 | const videoStream = await getVideoFileStream(path) | 33 | const videoStream = await getVideoFileStream(path) |
34 | 34 | ||
35 | return { | 35 | return { |
36 | videoFileResolution: Math.min(videoStream.height, videoStream.width), | 36 | width: videoStream.width, |
37 | isPortraitMode: videoStream.height > videoStream.width | 37 | height: videoStream.height |
38 | } | ||
39 | } | ||
40 | |||
41 | async function getVideoFileResolution (path: string) { | ||
42 | const size = await getVideoFileSize(path) | ||
43 | |||
44 | return { | ||
45 | videoFileResolution: Math.min(size.height, size.width), | ||
46 | isPortraitMode: size.height > size.width | ||
38 | } | 47 | } |
39 | } | 48 | } |
40 | 49 | ||
@@ -110,8 +119,10 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima | |||
110 | type TranscodeOptions = { | 119 | type TranscodeOptions = { |
111 | inputPath: string | 120 | inputPath: string |
112 | outputPath: string | 121 | outputPath: string |
113 | resolution?: VideoResolution | 122 | resolution: VideoResolution |
114 | isPortraitMode?: boolean | 123 | isPortraitMode?: boolean |
124 | |||
125 | generateHlsPlaylist?: boolean | ||
115 | } | 126 | } |
116 | 127 | ||
117 | function transcode (options: TranscodeOptions) { | 128 | function transcode (options: TranscodeOptions) { |
@@ -150,6 +161,16 @@ function transcode (options: TranscodeOptions) { | |||
150 | command = command.withFPS(fps) | 161 | command = command.withFPS(fps) |
151 | } | 162 | } |
152 | 163 | ||
164 | if (options.generateHlsPlaylist) { | ||
165 | const segmentFilename = `${dirname(options.outputPath)}/${options.resolution}_%03d.ts` | ||
166 | |||
167 | command = command.outputOption('-hls_time 4') | ||
168 | .outputOption('-hls_list_size 0') | ||
169 | .outputOption('-hls_playlist_type vod') | ||
170 | .outputOption('-hls_segment_filename ' + segmentFilename) | ||
171 | .outputOption('-f hls') | ||
172 | } | ||
173 | |||
153 | command | 174 | command |
154 | .on('error', (err, stdout, stderr) => { | 175 | .on('error', (err, stdout, stderr) => { |
155 | logger.error('Error in transcoding job.', { stdout, stderr }) | 176 | logger.error('Error in transcoding job.', { stdout, stderr }) |
@@ -166,6 +187,7 @@ function transcode (options: TranscodeOptions) { | |||
166 | // --------------------------------------------------------------------------- | 187 | // --------------------------------------------------------------------------- |
167 | 188 | ||
168 | export { | 189 | export { |
190 | getVideoFileSize, | ||
169 | getVideoFileResolution, | 191 | getVideoFileResolution, |
170 | getDurationFromVideoFile, | 192 | getDurationFromVideoFile, |
171 | generateImageFromVideoFile, | 193 | generateImageFromVideoFile, |