Skip to content

Commit

Permalink
Disable audio copy after first finalization failure (#1122)
Browse files Browse the repository at this point in the history
ScrubN authored Jun 30, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
binghe Chun Tian
1 parent 82ebbca commit 15f31d1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
@@ -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...");
@@ -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
{
@@ -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");

0 comments on commit 15f31d1

Please sign in to comment.