bar refactoring

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

View file

@ -48,69 +48,75 @@ def make_pipes(command):
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 tqdm_bar(i, encoder, counter, frame_probe_source, passes):
def process_encoding_pipe(pipe, encoder, counter):
encoder_history = deque(maxlen=20)
frame = 0
pass_1_check = True
skip_1_pass = False
match = None
while True:
line = pipe.stdout.readline().strip()
if len(line) == 0 and pipe.poll() is not None:
break
if len(line) == 0:
continue
if encoder in ('aom', 'vpx'):
match = match_aom_vpx(line)
elif encoder == 'rav1e':
match = match_rav1e(line)
if encoder in ('x265'):
if not skip_1_pass and pass_1_check:
if 'output file' in line:
if 'nul' in line.lower():
skip_1_pass = True
else:
pass_1_check = False
if not skip_1_pass:
match = re.search(r"^(\d+)", line)
if match:
new = int(match.group(1))
if new > frame:
counter.update(new - frame)
frame = new
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'):
while True:
line = pipe.stdout.readline().strip()
if line:
encoder_history.append(line)
if len(line) == 0 and pipe.poll() is not None:
break
if len(line) == 0:
continue
if encoder in ('aom', 'vpx'):
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:
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'):
if not skip_1_pass and pass_1_check:
if 'output file' in line:
if 'nul' in line.lower():
skip_1_pass = True
else:
pass_1_check = False
if not skip_1_pass:
match = re.search(r"^(\d+)", line)
if match:
new = int(match.group(1))
if new > frame:
counter.update(new - frame)
frame = new
match = None
process_encoding_pipe(pipe, encoder, counter)
if encoder == 'svt_av1':
# SVT-AV1 developer: SVT-AV1 is special in the way it outputs to console
pipe.wait()
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:
_, _, exc_tb = sys.exc_info()
print(f'Error at encode {e}\nAt line {exc_tb.tb_lineno}')