From 10ea5f766a484a34648b8738ed1f22bb3b2af92d Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Wed, 6 May 2020 10:41:29 -0600 Subject: [PATCH] Simplify process_input cognitive complexity, move extra steps from arg_parsing to main_thread so arg_parsing only handles args Signed-off-by: Luis Garcia --- av1an.py | 60 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/av1an.py b/av1an.py index 53397e0..feef85f 100755 --- a/av1an.py +++ b/av1an.py @@ -75,25 +75,22 @@ class Av1an: def process_inputs(self): # Check input file for being valid - if self.d.get('mode') == 2: - if self.d.get('input'): - print("Server mode, input file ignored") - elif self.d.get('input'): - inputs = self.d.get('input') - valid = np.array([i.exists() for i in inputs]) - - if not all(valid): - print(f'File(s) do not exist: {", ".join([str(inputs[i]) for i in np.where(valid == False)[0]])}') - sys.exit() - - if len(inputs) > 1: - self.d['queue'] = inputs - else: - self.d['input'] = inputs[0] - else: + if not self.d.get('input'): print('No input file') sys.exit() + inputs = self.d.get('input') + valid = np.array([i.exists() for i in inputs]) + + if not all(valid): + print(f'File(s) do not exist: {", ".join([str(inputs[i]) for i in np.where(valid == False)[0]])}') + sys.exit() + + if len(inputs) > 1: + self.d['queue'] = inputs + else: + self.d['input'] = inputs[0] + def read_config(self): """Creation and reading of config files with saved settings""" cfg = self.d.get('config') @@ -167,19 +164,6 @@ class Av1an: # Store all vars in dictionary self.d = vars(parser.parse_args()) - self.read_config() - self.check_executables() - self.process_inputs() - - # Changing pixel format, bit format - self.d['pix_format'] = f' -strict -1 -pix_fmt {self.d.get("pix_format")}' - - self.d['ffmpeg_pipe'] = f' {self.d.get("ffmpeg")} {self.d.get("pix_format")} -f yuv4mpegpipe - |' - - if self.d.get('vmaf_steps') < 5: - print('Target vmaf require more than 4 probes/steps') - sys.exit() - def outputs_filenames(self): if self.d.get('output_file'): self.d['output_file'] = self.d.get('output_file').with_suffix('.mkv') @@ -965,6 +949,24 @@ class Av1an: # Parse initial arguments self.arg_parsing() + self.read_config() + self.check_executables() + + if self.d.get('mode') == 2: + if self.d.get('input'): + print("Server mode, input file ignored") + else: + self.process_inputs() + + # Changing pixel format, bit format + self.d['pix_format'] = f' -strict -1 -pix_fmt {self.d.get("pix_format")}' + + self.d['ffmpeg_pipe'] = f' {self.d.get("ffmpeg")} {self.d.get("pix_format")} -f yuv4mpegpipe - |' + + if self.d.get('vmaf_steps') < 5: + print('Target vmaf require more than 4 probes/steps') + sys.exit() + # Video Mode. Encoding on local machine if self.d.get('mode') == 0: # Batch processing