MCPcopy Create free account
hub / github.com/Infiziert90/getnative / run

Method run

getnative/app.py:131–189  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

129 self.filename = self.get_filename()
130
131 async def run(self):
132 # change format to GrayS with bitdepth 32 for descale
133 src = self.src[self.frame]
134 matrix_s = '709' if src.format.color_family == vapoursynth.RGB else None
135 src_luma32 = core.resize.Point(src, format=vapoursynth.YUV444PS, matrix_s=matrix_s)
136 src_luma32 = core.std.ShufflePlanes(src_luma32, 0, vapoursynth.GRAY)
137
138 # descale each individual frame
139 clip_list = [self.scaler.descaler(src_luma32, self.getw(h, not src.width & 1), h) # allow odd resolutions for odd input
140 for h in range(self.min_h, self.max_h + 1, self.steps)]
141 full_clip = core.std.Splice(clip_list, mismatch=True)
142 full_clip = self.scaler.upscaler(full_clip, src.width, src.height)
143 if self.ar != src.width / src.height:
144 src_luma32 = self.scaler.upscaler(src_luma32, src.width, src.height)
145 expr_full = core.std.Expr([src_luma32 * full_clip.num_frames, full_clip], 'x y - abs dup 0.015 > swap 0 ?')
146 full_clip = core.std.CropRel(expr_full, 5, 5, 5, 5)
147 full_clip = core.std.PlaneStats(full_clip)
148
149 tasks_pending = set()
150 futures = {}
151 vals = []
152 full_clip_len = len(full_clip)
153 for frame_index in range(len(full_clip)):
154 print(f"\r{frame_index}/{full_clip_len-1}", end="", file=sys.stderr)
155 fut = asyncio.ensure_future(asyncio.wrap_future(full_clip.get_frame_async(frame_index)))
156 tasks_pending.add(fut)
157 futures[fut] = frame_index
158 while len(tasks_pending) >= core.num_threads + 2:
159 tasks_done, tasks_pending = await asyncio.wait(tasks_pending, return_when=asyncio.FIRST_COMPLETED)
160 vals += [(futures.pop(task), task.result().props.PlaneStatsAverage) for task in tasks_done]
161
162 tasks_done, _ = await asyncio.wait(tasks_pending)
163 vals += [(futures.pop(task), task.result().props.PlaneStatsAverage) for task in tasks_done]
164 vals = [v for _, v in sorted(vals)]
165 ratios, vals, best_value = self.analyze_results(vals)
166 print("\n", file=sys.stderr) # move the cursor, so that you not start at the end of the progress bar
167
168 self.txt_output += 'Raw data:\nResolution\t | Relative Error\t | Relative difference from last\n'
169 self.txt_output += '\n'.join([
170 f'{i * self.steps + self.min_h:4d}\t\t | {error:.10f}\t\t | {ratios[i]:.2f}'
171 for i, error in enumerate(vals)
172 ])
173
174 plot, fig = self.save_plot(vals)
175 if not self.no_save:
176 if not os.path.isdir(self.output_dir):
177 os.mkdir(self.output_dir)
178
179 print(f"Output Path: {self.output_dir}", file=sys.stderr)
180 for fmt in self.plot_format.replace(" ", "").split(','):
181 fig.savefig(f'{self.output_dir}/{self.filename}.{fmt}')
182
183 with open(f"{self.output_dir}/{self.filename}.txt", "w") as stream:
184 stream.writelines(self.txt_output)
185
186 if self.mask_out:
187 self.save_images(src_luma32)
188

Callers 1

getnativeFunction · 0.95

Calls 4

getwMethod · 0.95
analyze_resultsMethod · 0.95
save_plotMethod · 0.95
save_imagesMethod · 0.95

Tested by

no test coverage detected