bar refactoring

This commit is contained in:
Zen 2020-07-22 10:20:03 +03:00
parent 28a09d5f46
commit 1b972f9a4d

View file

@ -48,24 +48,28 @@ def make_pipes(command):
return pipe return pipe
def match_aom_vpx(line):
if 'fatal' in line.lower():
print('\n\nERROR IN ENCODING PROCESS\n\n', line)
terminate()
if 'Pass 2/2' in line or 'Pass 1/1' in line:
return re.search(r"frame.*?\/([^ ]+?) ", line)
def match_rav1e(line):
if 'error' in line.lower():
print('\n\nERROR IN ENCODING PROCESS\n\n', line)
terminate()
return re.search(r"encoded.*? ([^ ]+?) ", line)
def process_encoding_pipe(pipe, encoder, counter):
def tqdm_bar(i, encoder, counter, frame_probe_source, passes):
encoder_history = deque(maxlen=20) encoder_history = deque(maxlen=20)
frame = 0 frame = 0
pass_1_check = True pass_1_check = True
skip_1_pass = False skip_1_pass = False
match = None
try:
pipe = make_pipes(i)
if encoder in ('aom', 'vpx', 'rav1e','x265'):
while True: while True:
line = pipe.stdout.readline().strip() line = pipe.stdout.readline().strip()
if line:
encoder_history.append(line)
if len(line) == 0 and pipe.poll() is not None: if len(line) == 0 and pipe.poll() is not None:
break break
@ -73,18 +77,12 @@ def tqdm_bar(i, encoder, counter, frame_probe_source, passes):
continue continue
if encoder in ('aom', 'vpx'): if encoder in ('aom', 'vpx'):
if 'fatal' in line.lower(): match = match_aom_vpx(line)
print('\n\nERROR IN ENCODING PROCESS\n\n', line)
terminate()
if 'Pass 2/2' in line or 'Pass 1/1' in line:
match = re.search(r"frame.*?\/([^ ]+?) ", line)
elif encoder == 'rav1e':
if 'error' in line.lower():
print('\n\nERROR IN ENCODING PROCESS\n\n', line)
terminate()
match = re.search(r"encoded.*? ([^ ]+?) ", line)
elif encoder in ('x265'): elif encoder == 'rav1e':
match = match_rav1e(line)
if encoder in ('x265'):
if not skip_1_pass and pass_1_check: if not skip_1_pass and pass_1_check:
if 'output file' in line: if 'output file' in line:
if 'nul' in line.lower(): if 'nul' in line.lower():
@ -99,18 +97,26 @@ def tqdm_bar(i, encoder, counter, frame_probe_source, passes):
if new > frame: if new > frame:
counter.update(new - frame) counter.update(new - frame)
frame = new frame = new
match = None
if line:
encoder_history.append(line)
if pipe.returncode != 0 and pipe.returncode != -2: # -2 is Ctrl+C for aom
print(f"\nEncoder encountered an error: {pipe.returncode}")
print('\n'.join(encoder_history))
def tqdm_bar(i, encoder, counter, frame_probe_source, passes):
try:
pipe = make_pipes(i)
if encoder in ('aom', 'vpx', 'rav1e','x265'):
process_encoding_pipe(pipe, encoder, counter)
if encoder == 'svt_av1': if encoder == 'svt_av1':
# SVT-AV1 developer: SVT-AV1 is special in the way it outputs to console # SVT-AV1 developer: SVT-AV1 is special in the way it outputs to console
pipe.wait() pipe.wait()
counter.update(frame_probe_source // passes) counter.update(frame_probe_source // passes)
if pipe.returncode != 0 and pipe.returncode != -2: # -2 is Ctrl+C for aom
print(f"\nEncoder encountered an error: {pipe.returncode}")
print('\n'.join(encoder_history))
except Exception as e: except Exception as e:
_, _, exc_tb = sys.exc_info() _, _, exc_tb = sys.exc_info()
print(f'Error at encode {e}\nAt line {exc_tb.tb_lineno}') print(f'Error at encode {e}\nAt line {exc_tb.tb_lineno}')