Kill FFMPEG after stream is closed (#582)

This commit is contained in:
Max Isom 2022-03-17 19:17:22 -04:00 committed by GitHub
parent 5497b22e49
commit b206254c77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- There are no longer FFMPEG orphan processes after listening to a livestream
## [1.6.1] - 2022-03-15
### Fixed

View file

@ -527,14 +527,18 @@ export default class {
capacitor.createReadStream().pipe(cacheStream);
}
const returnedStream = capacitor.createReadStream();
let hasReturnedStreamClosed = false;
const stream = ffmpeg(url)
.inputOptions(options?.ffmpegInputOptions ?? ['-re'])
.noVideo()
.audioCodec('libopus')
.outputFormat('webm')
.on('error', error => {
console.error(error);
reject(error);
if (!hasReturnedStreamClosed) {
reject(error);
}
})
.on('start', command => {
debug(`Spawned ffmpeg with ${command as string}`);
@ -542,7 +546,12 @@ export default class {
stream.pipe(capacitor);
resolve(capacitor.createReadStream());
returnedStream.on('close', () => {
stream.kill('SIGKILL');
hasReturnedStreamClosed = true;
});
resolve(returnedStream);
});
}
}