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

Add FFmpeg command verbose log #1248

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ private FfmpegProcess GetFfmpegProcess(FileInfo fileInfo)
}
};

_progress.LogVerbose($"Running \"{renderOptions.FfmpegPath}\" in \"{process.StartInfo.WorkingDirectory}\" with args: {process.StartInfo.Arguments}");

process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
Expand Down
34 changes: 32 additions & 2 deletions TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@

CheckAvailableStorageSpace(qualityPlaylist.StreamInfo.Bandwidth, videoLength);

var streamIds = GetStreamIds(playlist);

if (Directory.Exists(downloadFolder))
Directory.Delete(downloadFolder, true);
TwitchHelper.CreateDirectory(downloadFolder);
Expand All @@ -109,7 +111,7 @@
videoChapterResponse.data.video.moments.edges);

var concatListPath = Path.Combine(downloadFolder, "concat.txt");
await FfmpegConcatList.SerializeAsync(concatListPath, playlist, videoListCrop, cancellationToken);
await FfmpegConcatList.SerializeAsync(concatListPath, playlist, videoListCrop, streamIds, cancellationToken);

outputFs.Close();

Expand Down Expand Up @@ -145,6 +147,20 @@
}
}

private FfmpegConcatList.StreamIds GetStreamIds(M3U8 playlist)

Check failure on line 150 in TwitchDownloaderCore/VideoDownloader.cs

View workflow job for this annotation

GitHub Actions / run-tests

The type name 'StreamIds' does not exist in the type 'FfmpegConcatList'

Check failure on line 150 in TwitchDownloaderCore/VideoDownloader.cs

View workflow job for this annotation

GitHub Actions / build-gui

The type name 'StreamIds' does not exist in the type 'FfmpegConcatList'
{
var path = DownloadTools.RemoveQueryString(playlist.Streams.FirstOrDefault()?.Path ?? "");
var extension = Path.GetExtension(path);
if (extension is ".mp4")
return FfmpegConcatList.StreamIds.Mp4;

if (extension is ".ts")
return FfmpegConcatList.StreamIds.TransportStream;

_progress.LogWarning("No file extension was found! Assuming TS.");
return FfmpegConcatList.StreamIds.TransportStream;
}

private void CheckAvailableStorageSpace(int bandwidth, TimeSpan videoLength)
{
var videoSizeInBytes = VideoSizeEstimator.EstimateVideoSize(bandwidth,
Expand Down Expand Up @@ -318,7 +334,8 @@
}
}

private async Task<int> RunFfmpegVideoCopy(string tempFolder, FileInfo outputFile, string concatListPath, string metadataPath, decimal startOffset, decimal endDuration, TimeSpan videoLength, bool disableAudioCopy, 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 Down Expand Up @@ -386,6 +403,8 @@
HandleFfmpegOutput(e.Data, encodingTimeRegex, videoLength);
};

_progress.LogVerbose($"Running \"{downloadOptions.FfmpegPath}\" in \"{process.StartInfo.WorkingDirectory}\" with args: {CombineArguments(process.StartInfo.ArgumentList)}");

process.Start();
process.BeginErrorReadLine();

Expand All @@ -401,6 +420,17 @@
} while (!process.HasExited || !logQueue.IsEmpty);

return process.ExitCode;

static string CombineArguments(IEnumerable<string> args)
{
return string.Join(' ', args.Select(x =>
{
if (!x.StartsWith('"') && !x.StartsWith('\'') && x.Contains(' '))
return $"\"{x}\"";

return x;
}));
}
}

private void HandleFfmpegOutput(string output, Regex encodingTimeRegex, TimeSpan videoLength)
Expand Down
Loading