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

Disable audio copy after first video finalization failure #1122

Merged
merged 1 commit into from
Jun 30, 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
12 changes: 9 additions & 3 deletions TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ await FfmpegMetadata.SerializeAsync(metadataPath, videoInfo.owner.displayName, d
var ffmpegRetries = 0;
do
{
ffmpegExitCode = await RunFfmpegVideoCopy(downloadFolder, outputFileInfo, concatListPath, metadataPath, startOffset, endDuration, videoLength, cancellationToken);
ffmpegExitCode = await RunFfmpegVideoCopy(downloadFolder, outputFileInfo, concatListPath, metadataPath, startOffset, endDuration, videoLength, ffmpegRetries > 0, cancellationToken);
if (ffmpegExitCode != 0)
{
_progress.LogError($"Failed to finalize video (code {ffmpegExitCode}), retrying in 10 seconds...");
Expand Down Expand Up @@ -317,7 +317,7 @@ private async Task VerifyDownloadedParts(ICollection<M3U8.Stream> playlist, Rang
}
}

private async Task<int> RunFfmpegVideoCopy(string tempFolder, FileInfo outputFile, string concatListPath, string metadataPath, decimal startOffset, decimal endDuration, TimeSpan videoLength, CancellationToken cancellationToken)
private async Task<int> RunFfmpegVideoCopy(string tempFolder, FileInfo outputFile, string concatListPath, string metadataPath, decimal startOffset, decimal endDuration, TimeSpan videoLength, bool disableAudioCopy, CancellationToken cancellationToken)
{
using var process = new Process
{
Expand All @@ -344,10 +344,16 @@ private async Task<int> RunFfmpegVideoCopy(string tempFolder, FileInfo outputFil
"-i", concatListPath,
"-i", metadataPath,
"-map_metadata", "1",
"-c", "copy",
(disableAudioCopy ? "-c:v" : "-c"), "copy",
outputFile.FullName
};

if (disableAudioCopy)
{
// Some VODs have bad audio data which FFmpeg doesn't like in copy mode. See lay295#1121 for more info
_progress.LogVerbose("Running with audio copy disabled.");
}

if (endDuration > 0)
{
args.Insert(0, "-t");
Expand Down
Loading