Force ffmpeg to exit on abort

pull/5817/head
Chocobozzz 2023-05-17 16:52:56 +02:00
parent e901579b00
commit ef2e6aabf7
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 12 additions and 2 deletions

View File

@ -10,6 +10,9 @@ import { AbstractTranscodingWrapper } from './abstract-transcoding-wrapper'
export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper { export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
private ffmpegCommand: FfmpegCommand private ffmpegCommand: FfmpegCommand
private aborted = false
private errored = false
private ended = false private ended = false
async run () { async run () {
@ -63,7 +66,12 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
} }
abort () { 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: { private onFFmpegError (options: {
@ -76,14 +84,16 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
// Don't care that we killed the ffmpeg process // Don't care that we killed the ffmpeg process
if (err?.message?.includes('Exiting normally')) return 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() }) logger.error('FFmpeg transcoding error.', { err, stdout, stderr, ffmpegShellCommand, ...this.lTags() })
this.errored = true
this.emit('error', { err }) this.emit('error', { err })
} }
private onFFmpegEnded () { private onFFmpegEnded () {
if (this.ended) return if (this.ended || this.errored || this.aborted) return
this.ended = true this.ended = true
this.emit('end') this.emit('end')