aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-01-21 14:42:43 +0100
committerChocobozzz <me@florianbigard.com>2021-01-21 14:42:43 +0100
commit3b01f4c0ac764ecb70efaadfd939ca868c28769c (patch)
tree99c0cdef6dac0d43dd16c02b8bae3c132037cda6 /server/helpers
parentd44cdcd766fbccbe4b96f34c11a64f0e2168c3b9 (diff)
downloadPeerTube-3b01f4c0ac764ecb70efaadfd939ca868c28769c.tar.gz
PeerTube-3b01f4c0ac764ecb70efaadfd939ca868c28769c.tar.zst
PeerTube-3b01f4c0ac764ecb70efaadfd939ca868c28769c.zip
Support progress for ffmpeg tasks
Diffstat (limited to 'server/helpers')
-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}