Skip to content

Commit d3e34f0

Browse files
committed
Improved bitrate util (show stats of all video/audio/sub tracks combined)
1 parent 4da5562 commit d3e34f0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

ff-utils-winforms/UI/Tasks/UtilReadBitrates.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,52 @@ public static async Task Run()
2121
Program.mainForm.SetWorking(true);
2222
Logger.Log("Analyzing streams... This can take a few minutes on slower hard drives.");
2323

24+
int totalKbpsVid = 0;
25+
int totalKbpsAud = 0;
26+
int totalKbpsSub = 0;
27+
28+
long totalBytesVid = 0;
29+
long totalBytesAud = 0;
30+
long totalBytesSub = 0;
31+
2432
foreach (MediaStreamListEntry entry in Program.mainForm.streamListBox.Items)
2533
{
2634
if (RunTask.canceled || !Program.mainForm.streamListBox.GetItemChecked(Program.mainForm.streamListBox.Items.IndexOf(entry)))
2735
continue;
2836

2937
Stream s = entry.Stream;
3038
FfmpegUtils.StreamSizeInfo info = await FfmpegUtils.GetStreamSizeBytes(TrackList.current.TruePath, s.Index);
31-
string percent = FormatUtils.RatioInt(info.Bytes, TrackList.current.Size).ToString("0.0");
39+
string percent = FormatUtils.RatioFloat(info.Bytes, TrackList.current.Size).ToString("0.0");
3240
string br = info.Kbps > 1 ? FormatUtils.Bitrate(info.Kbps.RoundToInt()) : info.Kbps.ToString("0.0") + " kbps";
3341
Logger.Log($"Stream #{s.Index} ({s.Type}) - Bitrate: {br} - Size: {FormatUtils.Bytes(info.Bytes)} ({percent}%)");
42+
43+
if (s.Type == Stream.StreamType.Video)
44+
{
45+
totalKbpsVid += info.Kbps.RoundToInt();
46+
totalBytesVid += info.Bytes;
47+
}
48+
49+
if (s.Type == Stream.StreamType.Audio)
50+
{
51+
totalKbpsAud += info.Kbps.RoundToInt();
52+
totalBytesAud += info.Bytes;
53+
}
54+
55+
if (s.Type == Stream.StreamType.Subtitle)
56+
{
57+
totalKbpsSub += info.Kbps.RoundToInt();
58+
totalBytesSub += info.Bytes;
59+
}
3460
}
3561

62+
string totalPercentVid = FormatUtils.RatioFloat(totalBytesVid, TrackList.current.Size).ToString("0.0");
63+
string totalPercentAud = FormatUtils.RatioFloat(totalBytesAud, TrackList.current.Size).ToString("0.0");
64+
string totalPercentSub = FormatUtils.RatioFloat(totalBytesSub, TrackList.current.Size).ToString("0.0");
65+
66+
Logger.Log($"Total Video Bitrate: {FormatUtils.Bitrate(totalKbpsVid)} - Total Video Size: {FormatUtils.Bytes(totalBytesVid)} ({totalPercentVid}%)");
67+
Logger.Log($"Total Audio Bitrate: {FormatUtils.Bitrate(totalKbpsAud)} - Total Audio Size: {FormatUtils.Bytes(totalBytesAud)} ({totalPercentAud}%)");
68+
Logger.Log($"Total Subtitle Bitrate: {FormatUtils.Bitrate(totalKbpsSub)} - Total Subtitle Size: {FormatUtils.Bytes(totalBytesSub)} ({totalPercentSub}%)");
69+
3670
Program.mainForm.SetWorking(false);
3771
}
3872
}

ff-utils-winforms/Utils/FormatUtils.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ public static string Ratio(long numFrom, long numTo)
134134
return ratio.ToString("0.00") + "%";
135135
}
136136

137+
public static float RatioFloat(long numFrom, long numTo)
138+
{
139+
double ratio = ((float)numFrom / (float)numTo) * 100f;
140+
141+
if (ratio < 0f)
142+
ratio = 0f;
143+
144+
return (float)ratio;
145+
}
146+
137147
public static int RatioInt(long numFrom, long numTo)
138148
{
139149
double ratio = Math.Round(((float)numFrom / (float)numTo) * 100f);

0 commit comments

Comments
 (0)