Av1an/Encoders/aom.py

64 lines
2.1 KiB
Python
Raw Normal View History

import os
2020-08-21 13:31:09 +00:00
import re
from Av1an.arg_parse import Args
2020-09-14 17:45:21 +00:00
from Chunks.chunk import Chunk
from Av1an.commandtypes import MPCommands, CommandPair, Command
2020-09-14 17:45:21 +00:00
from Encoders.encoder import Encoder
2020-08-21 13:31:09 +00:00
from Av1an.utils import list_index_of_regex, terminate
class Aom(Encoder):
def __init__(self):
super().__init__(
encoder_bin='aomenc',
2020-09-15 17:36:23 +00:00
encoder_help='aomenc --help',
default_args=['--threads=4', '--cpu-used=6', '--end-usage=q', '--cq-level=30'],
default_passes=2,
default_q_range=(25, 50),
output_extension='ivf'
)
2020-08-22 15:15:47 +00:00
def compose_1_pass(self, a: Args, c: Chunk, output: str) -> MPCommands:
return [
2020-08-19 07:06:42 +00:00
CommandPair(
Encoder.compose_ffmpeg_pipe(a),
['aomenc', '--passes=1', *a.video_params, '-o', output, '-']
2020-08-19 07:06:42 +00:00
)
]
2020-08-22 15:15:47 +00:00
def compose_2_pass(self, a: Args, c: Chunk, output: str) -> MPCommands:
return [
2020-08-19 07:06:42 +00:00
CommandPair(
Encoder.compose_ffmpeg_pipe(a),
['aomenc', '--passes=2', '--pass=1', *a.video_params, f'--fpf={c.fpf}.log', '-o', os.devnull, '-']
),
CommandPair(
Encoder.compose_ffmpeg_pipe(a),
['aomenc', '--passes=2', '--pass=2', *a.video_params, f'--fpf={c.fpf}.log', '-o', output, '-']
2020-08-19 07:06:42 +00:00
)
]
def man_q(self, command: Command, q: int) -> Command:
"""Return command with new cq value"""
adjusted_command = command.copy()
i = list_index_of_regex(adjusted_command, r"--cq-level=.+")
adjusted_command[i] = f'--cq-level={q}'
return adjusted_command
2020-08-21 13:31:09 +00:00
2020-08-22 15:15:47 +00:00
def match_line(self, line: str):
2020-08-21 13:31:09 +00:00
"""Extract number of encoded frames from line.
:param line: one line of text output from the encoder
:return: match object from re.search matching the number of encoded frames"""
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)