Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clip downloader sometimes getting stuck when encoding metadata #926

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions TwitchDownloaderCore/ClipDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void DownloadProgressHandler(StreamCopyProgress streamProgress)
if (!File.Exists(downloadOptions.Filename))
{
File.Move(tempFile, downloadOptions.Filename);
throw new FileNotFoundException("Unable to serialize metadata (is FFmpeg missing?). The download has been completed without custom metadata.");
_progress.Report(new ProgressReport(ReportType.Log, "Unable to serialize metadata. The download has been completed without custom metadata."));
}

_progress.Report(new ProgressReport(ReportType.SameLineStatus, "Encoding Clip Metadata 100%"));
Expand Down 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 @@ -169,16 +170,22 @@ await FfmpegMetadata.SerializeAsync(metadataFile, clipMetadata.broadcaster.displ
};

process.Start();
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
Loading