aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r--server/helpers/ffmpeg-utils.ts20
1 files changed, 14 insertions, 6 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 6f7c186d9..a4d02908d 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -1,3 +1,4 @@
1import { Job } from 'bull'
1import * as ffmpeg from 'fluent-ffmpeg' 2import * as ffmpeg from 'fluent-ffmpeg'
2import { readFile, remove, writeFile } from 'fs-extra' 3import { readFile, remove, writeFile } from 'fs-extra'
3import { dirname, join } from 'path' 4import { dirname, join } from 'path'
@@ -124,6 +125,8 @@ interface BaseTranscodeOptions {
124 resolution: VideoResolution 125 resolution: VideoResolution
125 126
126 isPortraitMode?: boolean 127 isPortraitMode?: boolean
128
129 job?: Job
127} 130}
128 131
129interface HLSTranscodeOptions extends BaseTranscodeOptions { 132interface HLSTranscodeOptions extends BaseTranscodeOptions {
@@ -188,7 +191,7 @@ async function transcode (options: TranscodeOptions) {
188 191
189 command = await builders[options.type](command, options) 192 command = await builders[options.type](command, options)
190 193
191 await runCommand(command) 194 await runCommand(command, options.job)
192 195
193 await fixHLSPlaylistIfNeeded(options) 196 await fixHLSPlaylistIfNeeded(options)
194} 197}
@@ -611,11 +614,9 @@ function getFFmpeg (input: string, type: 'live' | 'vod') {
611 return command 614 return command
612} 615}
613 616
614async function runCommand (command: ffmpeg.FfmpegCommand, onEnd?: Function) { 617async function runCommand (command: ffmpeg.FfmpegCommand, job?: Job) {
615 return new Promise<void>((res, rej) => { 618 return new Promise<void>((res, rej) => {
616 command.on('error', (err, stdout, stderr) => { 619 command.on('error', (err, stdout, stderr) => {
617 if (onEnd) onEnd()
618
619 logger.error('Error in transcoding job.', { stdout, stderr }) 620 logger.error('Error in transcoding job.', { stdout, stderr })
620 rej(err) 621 rej(err)
621 }) 622 })
@@ -623,11 +624,18 @@ async function runCommand (command: ffmpeg.FfmpegCommand, onEnd?: Function) {
623 command.on('end', (stdout, stderr) => { 624 command.on('end', (stdout, stderr) => {
624 logger.debug('FFmpeg command ended.', { stdout, stderr }) 625 logger.debug('FFmpeg command ended.', { stdout, stderr })
625 626
626 if (onEnd) onEnd()
627
628 res() 627 res()
629 }) 628 })
630 629
630 if (job) {
631 command.on('progress', progress => {
632 if (!progress.percent) return
633
634 job.progress(Math.round(progress.percent))
635 .catch(err => logger.warn('Cannot set ffmpeg job progress.', { err }))
636 })
637 }
638
631 command.run() 639 command.run()
632 }) 640 })
633} 641}