Skip to content

Commit

Permalink
Kill FFmpeg on error if it hasn't exited yet
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Jan 5, 2024
1 parent 27985ab commit c10b8d2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions TwitchDownloaderCore/ClipDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ private async Task EncodeClipWithMetadata(string inputFile, string destinationFi
{
var metadataFile = $"{inputFile}_metadata.txt";

Process process = null;
try
{
await FfmpegMetadata.SerializeAsync(metadataFile, clipMetadata.broadcaster.displayName, downloadOptions.Id, clipMetadata.title, clipMetadata.createdAt, clipMetadata.viewCount,
videoMomentEdges: new[] { clipChapter }, cancellationToken: cancellationToken);

var process = new Process
process = new Process
{
StartInfo =
{
Expand All @@ -172,14 +173,19 @@ await FfmpegMetadata.SerializeAsync(metadataFile, clipMetadata.broadcaster.displ
process.BeginErrorReadLine();

// If the process has exited before we call WaitForExitAsync, the thread locks up.
// This was probably not intended by the .NET team, but it's an issue regardless.
if (process.HasExited)
return;

await process.WaitForExitAsync(cancellationToken);
}
finally
{
if (process is { HasExited: false })
{
process.Kill();
await Task.Delay(100, cancellationToken);
}

File.Delete(metadataFile);
}
}
Expand Down

0 comments on commit c10b8d2

Please sign in to comment.