mirror of
https://github.com/master-of-zen/Av1an.git
synced 2024-11-25 02:29:40 +00:00
bar refactoring
This commit is contained in:
parent
28a09d5f46
commit
1b972f9a4d
1 changed files with 53 additions and 47 deletions
58
Av1an/bar.py
58
Av1an/bar.py
|
@ -48,24 +48,28 @@ 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
|
||||
|
||||
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
|
||||
|
||||
|
@ -73,18 +77,12 @@ def tqdm_bar(i, encoder, counter, frame_probe_source, passes):
|
|||
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)
|
||||
match = match_aom_vpx(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 'output file' in line:
|
||||
if 'nul' in line.lower():
|
||||
|
@ -99,18 +97,26 @@ def tqdm_bar(i, encoder, counter, frame_probe_source, passes):
|
|||
if new > frame:
|
||||
counter.update(new - frame)
|
||||
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':
|
||||
# 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}')
|
||||
|
|
Loading…
Reference in a new issue