diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 133b1b03b..b6b64de3f 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -5,7 +5,7 @@ import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/cons | |||
5 | import { processImage } from './image-utils' | 5 | import { processImage } from './image-utils' |
6 | import { logger } from './logger' | 6 | import { logger } from './logger' |
7 | import { checkFFmpegEncoders } from '../initializers/checker-before-init' | 7 | import { checkFFmpegEncoders } from '../initializers/checker-before-init' |
8 | import { remove } from 'fs-extra' | 8 | import { remove, readFile, writeFile } from 'fs-extra' |
9 | 9 | ||
10 | function computeResolutionsToTranscode (videoFileHeight: number) { | 10 | function computeResolutionsToTranscode (videoFileHeight: number) { |
11 | const resolutionsEnabled: number[] = [] | 11 | const resolutionsEnabled: number[] = [] |
@@ -164,7 +164,7 @@ function transcode (options: TranscodeOptions) { | |||
164 | } | 164 | } |
165 | 165 | ||
166 | if (options.hlsPlaylist) { | 166 | if (options.hlsPlaylist) { |
167 | const videoPath = `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}` | 167 | const videoPath = getHLSVideoPath(options) |
168 | 168 | ||
169 | command = command.outputOption('-hls_time 4') | 169 | command = command.outputOption('-hls_time 4') |
170 | .outputOption('-hls_list_size 0') | 170 | .outputOption('-hls_list_size 0') |
@@ -180,7 +180,11 @@ function transcode (options: TranscodeOptions) { | |||
180 | logger.error('Error in transcoding job.', { stdout, stderr }) | 180 | logger.error('Error in transcoding job.', { stdout, stderr }) |
181 | return rej(err) | 181 | return rej(err) |
182 | }) | 182 | }) |
183 | .on('end', res) | 183 | .on('end', () => { |
184 | return onTranscodingSuccess(options) | ||
185 | .then(() => res()) | ||
186 | .catch(err => rej(err)) | ||
187 | }) | ||
184 | .run() | 188 | .run() |
185 | } catch (err) { | 189 | } catch (err) { |
186 | return rej(err) | 190 | return rej(err) |
@@ -204,6 +208,25 @@ export { | |||
204 | 208 | ||
205 | // --------------------------------------------------------------------------- | 209 | // --------------------------------------------------------------------------- |
206 | 210 | ||
211 | function getHLSVideoPath (options: TranscodeOptions) { | ||
212 | return `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}` | ||
213 | } | ||
214 | |||
215 | async function onTranscodingSuccess (options: TranscodeOptions) { | ||
216 | if (!options.hlsPlaylist) return | ||
217 | |||
218 | // Fix wrong mapping with some ffmpeg versions | ||
219 | const fileContent = await readFile(options.outputPath) | ||
220 | |||
221 | const videoFileName = options.hlsPlaylist.videoFilename | ||
222 | const videoFilePath = getHLSVideoPath(options) | ||
223 | |||
224 | const newContent = fileContent.toString() | ||
225 | .replace(`#EXT-X-MAP:URI="${videoFilePath}",`, `#EXT-X-MAP:URI="${videoFileName}",`) | ||
226 | |||
227 | await writeFile(options.outputPath, newContent) | ||
228 | } | ||
229 | |||
207 | function getVideoFileStream (path: string) { | 230 | function getVideoFileStream (path: string) { |
208 | return new Promise<any>((res, rej) => { | 231 | return new Promise<any>((res, rej) => { |
209 | ffmpeg.ffprobe(path, (err, metadata) => { | 232 | ffmpeg.ffprobe(path, (err, metadata) => { |