From: Chocobozzz Date: Wed, 17 May 2023 14:52:56 +0000 (+0200) Subject: Force ffmpeg to exit on abort X-Git-Tag: v5.2.0-rc.1~121 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=ef2e6aabf755feeec96011e70ff2522a491c5cb3;p=github%2FChocobozzz%2FPeerTube.git Force ffmpeg to exit on abort --- diff --git a/server/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts b/server/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts index c82970b88..3c2cf51b7 100644 --- a/server/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts +++ b/server/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts @@ -10,6 +10,9 @@ import { AbstractTranscodingWrapper } from './abstract-transcoding-wrapper' export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper { private ffmpegCommand: FfmpegCommand + + private aborted = false + private errored = false private ended = false async run () { @@ -63,7 +66,12 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper { } abort () { - // Nothing to do, ffmpeg will automatically exit + if (this.ended || this.errored || this.aborted) return + + this.ffmpegCommand.kill('SIGINT') + + this.aborted = true + this.emit('end') } private onFFmpegError (options: { @@ -76,14 +84,16 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper { // Don't care that we killed the ffmpeg process if (err?.message?.includes('Exiting normally')) return + if (this.ended || this.errored || this.aborted) return logger.error('FFmpeg transcoding error.', { err, stdout, stderr, ffmpegShellCommand, ...this.lTags() }) + this.errored = true this.emit('error', { err }) } private onFFmpegEnded () { - if (this.ended) return + if (this.ended || this.errored || this.aborted) return this.ended = true this.emit('end')