Skip to content

Commit f7bfce6

Browse files
committed
Don't use command cache when getting stream sizes
1 parent ed96a9e commit f7bfce6

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

ff-utils-winforms/Media/FfmpegUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ public struct StreamSizeInfo { public float Kbps; public long Bytes; }
213213

214214
public static async Task<StreamSizeInfo> GetStreamSizeBytes(string path, int streamIndex = 0)
215215
{
216-
string[] outputLines = (await GetFfmpegOutputAsync(path, $"-map 0:{streamIndex} -c copy -f matroska NUL 2>&1 1>nul | findstr /L \"time video\"")).SplitIntoLines().Where(x => !x.Contains("FINDSTR")).ToArray();
216+
string decodeOutput = await GetFfmpegOutputAsync(path, $"-map 0:{streamIndex} -c copy -f matroska NUL 2>&1 1>nul | findstr /L \"time video\"", "", true);
217+
string[] outputLines = decodeOutput.SplitIntoLines().Where(x => !x.Contains("FINDSTR")).ToArray();
217218
string sizeLine = outputLines[outputLines.Length - 1];
218219
string bitrateLine = outputLines[outputLines.Length - 2];
219220

ff-utils-winforms/Media/GetVideoInfo.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ public enum FfprobeMode { ShowFormat, ShowStreams, ShowBoth };
1818

1919
static Dictionary<QueryInfo, string> cmdCache = new Dictionary<QueryInfo, string>();
2020

21-
public static async Task<string> GetFfmpegInfoAsync(string path, string lineFilter = "")
21+
public static async Task<string> GetFfmpegInfoAsync(string path, string lineFilter = "", bool noCache = false)
2222
{
23-
return await GetFfmpegOutputAsync(path, "", lineFilter);
23+
return await GetFfmpegOutputAsync(path, "", lineFilter, noCache);
2424
}
2525

26-
public static async Task<string> GetFfmpegOutputAsync(string path, string args, string lineFilter = "")
26+
public static async Task<string> GetFfmpegOutputAsync(string path, string args, string lineFilter = "", bool noCache = false)
2727
{
28-
return await GetFfmpegOutputAsync(path, "", args, lineFilter);
28+
return await GetFfmpegOutputAsync(path, "", args, lineFilter, noCache);
2929
}
3030

31-
public static async Task<string> GetFfmpegOutputAsync(string path, string argsIn, string argsOut, string lineFilter = "")
31+
public static async Task<string> GetFfmpegOutputAsync(string path, string argsIn, string argsOut, string lineFilter = "", bool noCache = false)
3232
{
3333
Process process = OsUtils.NewProcess(true);
3434
process.StartInfo.Arguments = $"/C cd /D {Paths.GetBinPath().Wrap()} & " +
3535
$"ffmpeg.exe -hide_banner -y {argsIn} {path.GetConcStr()} -i {path.Wrap()} {argsOut}";
36-
return await GetInfoAsync(path, process, lineFilter);
36+
return await GetInfoAsync(path, process, lineFilter, noCache);
3737
}
3838

3939
public static async Task<string> GetFfprobeInfoAsync(string path, FfprobeMode mode, string lineFilter = "", int streamIndex = -1, bool stripKeyName = true)
@@ -50,19 +50,19 @@ public static async Task<string> GetFfprobeInfoAsync(string path, FfprobeMode mo
5050
return output;
5151
}
5252

53-
static async Task<string> GetInfoAsync(string path, Process process, string lineFilter) // for ffmpeg
53+
static async Task<string> GetInfoAsync(string path, Process process, string lineFilter, bool noCache = false) // for ffmpeg
5454
{
55-
string output = await GetOutputCached(path, process);
55+
string output = await GetOutputCached(path, process, noCache);
5656

5757
if (!string.IsNullOrWhiteSpace(lineFilter.Trim()))
5858
output = string.Join("\n", output.SplitIntoLines().Where(x => x.Contains(lineFilter)).ToArray());
5959

6060
return output;
6161
}
6262

63-
static async Task<string> GetInfoAsync(string path, Process process, string lineFilter, int streamIndex = -1, bool stripKeyName = true) // for ffprobe
63+
static async Task<string> GetInfoAsync(string path, Process process, string lineFilter, int streamIndex = -1, bool stripKeyName = true, bool noCache = false) // for ffprobe
6464
{
65-
string output = await GetOutputCached(path, process);
65+
string output = await GetOutputCached(path, process, noCache);
6666

6767
try
6868
{
@@ -92,12 +92,12 @@ public static async Task<string> GetFfprobeInfoAsync(string path, FfprobeMode mo
9292
return output;
9393
}
9494

95-
static async Task<string> GetOutputCached (string path, Process process)
95+
static async Task<string> GetOutputCached (string path, Process process, bool noCache = false)
9696
{
9797
long filesize = IoUtils.GetFilesize(path);
9898
QueryInfo hash = new QueryInfo(path, filesize, process.StartInfo.Arguments);
9999

100-
if (filesize > 0 && CacheContains(hash, ref cmdCache))
100+
if (!noCache && filesize > 0 && CacheContains(hash, ref cmdCache))
101101
{
102102
Logger.Log($"GetVideoInfo: '{process.StartInfo.FileName} {process.StartInfo.Arguments}' cached, won't re-run.", true, false, "ffmpeg");
103103
return GetFromCache(hash, ref cmdCache);

0 commit comments

Comments
 (0)