private async Task UpscaleFrames(IWaifu2x waifu2X) { List <Frame> processableFrames = this._frames.Where(f => f.IsUpscaled == false).OrderBy(f => f.FrameName).ToList(); int processingIndex = 0; while (true) { if (processingIndex >= processableFrames.Count) { break; } this.OnStartScaling(); Task t1 = Task.Run(() => this.UpscaleOneFrame(waifu2X, processableFrames, processingIndex)); processingIndex++; await Task.Delay(200); Task t2 = Task.Run(() => this.UpscaleOneFrame(waifu2X, processableFrames, processingIndex)); processingIndex++; await Task.Delay(400); Task t3 = Task.Run(() => this.UpscaleOneFrame(waifu2X, processableFrames, processingIndex)); processingIndex++; await Task.Delay(200); Task t4 = Task.Run(() => this.UpscaleOneFrame(waifu2X, processableFrames, processingIndex)); processingIndex++; await Task.WhenAll(t1, t2, t3, t4); this.OnScalingFinished(4, processableFrames.Count, processingIndex); } }
public async Task Upscale(IWaifu2x waifu2X, IVideoConverter videoConverter) { if (this._resume) { await this.ReadFrames(waifu2X, videoConverter); } else { List <Frame> extractFrames = await videoConverter.ExtractFrames(this); this._frames.AddRange(extractFrames); } while (this.IsUpscaleFrameAvailable()) { await this.UpscaleFrames(waifu2X); // read frames again because sometimes upscale does not work await this.ReadFrames(waifu2X, videoConverter); } var intermediateVideo = new IntermediateVideo(this); await intermediateVideo.CreateVideoFromUpscaledFrames(videoConverter, waifu2X.GetScaledPath()); await intermediateVideo.CreateFinaleVideo(videoConverter); }
public UpscaleApp(ILoggerFactory loggerFactory, IWaifu2x waifu2X, IVideoConverter videoConverter, UpscaleSettings upscaleSettings) { this._loggerFactory = loggerFactory; this._waifu2X = waifu2X; this._videoConverter = videoConverter; this._upscaleSettings = upscaleSettings; }
private async Task ReadFrames(IWaifu2x waifu2X, IVideoConverter videoConverter) { this._logger.LogInformation("Resume from previous upscaling"); this._frames.AddRange(videoConverter.GetFrames()); foreach (Frame frame in this._frames) { if (!await waifu2X.IsAlreadyUpscaled(frame)) { continue; } this._logger.LogInformation($"{frame} already scaled"); frame.SetToUpscaled(); } }