public static async Task <int> GetInputFrameCountAsync(string path) { long filesize = IOUtils.GetFilesize(path); PseudoUniqueFile hash = new PseudoUniqueFile(path, filesize); if (filesize > 0 && FrameCountCacheContains(hash)) { Logger.Log($"FrameCountCache contains this hash, using cached frame count.", true); return(GetFrameCountFromCache(hash)); } else { Logger.Log($"Hash not cached, reading frame count.", true); } int frameCount; if (IOUtils.IsPathDirectory(path)) { frameCount = IOUtils.GetAmountOfFiles(path, false); } else { frameCount = await FfmpegCommands.GetFrameCountAsync(path); } Logger.Log($"Adding hash with frame count {frameCount} to cache.", true); frameCountCache.Add(hash, frameCount); return(frameCount); }
public static async Task <int> GetFrameCountAsync(string path, int retryCount = 3) { Logger.Log($"Getting frame count ({path})", true); long filesize = IoUtils.GetFilesize(path); QueryInfo hash = new QueryInfo(path, filesize); if (filesize > 0 && CacheContains(hash)) { Logger.Log($"Cache contains this hash, using cached value.", true); return(GetFromCache(hash)); } else { Logger.Log($"Hash not cached, reading frame count.", true); } int frameCount; if (IoUtils.IsPathDirectory(path)) { frameCount = IoUtils.GetAmountOfFiles(path, false); } else { frameCount = await FfmpegCommands.GetFrameCountAsync(path); } if (frameCount > 0) { Logger.Log($"Adding hash with value {frameCount} to cache.", true); cache.Add(hash, frameCount); } else { if (retryCount > 0) { Logger.Log($"Got {frameCount} frames, retrying ({retryCount} left)", true); Clear(); frameCount = await GetFrameCountAsync(path, retryCount - 1); } else { Logger.Log($"Failed to get frames and out of retries ({frameCount} frames for {path})", true); } } return(frameCount); }