2020-08-13 23:02:59 +00:00
|
|
|
import os
|
2020-08-21 13:31:09 +00:00
|
|
|
import re
|
2020-08-13 23:02:59 +00:00
|
|
|
|
2020-11-25 07:32:26 +00:00
|
|
|
from Projects import Project
|
2020-09-14 17:45:21 +00:00
|
|
|
from Chunks.chunk import Chunk
|
2020-08-19 22:10:29 +00:00
|
|
|
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
|
2020-08-13 23:02:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Rav1e(Encoder):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
|
|
|
encoder_bin='rav1e',
|
2020-09-15 17:36:23 +00:00
|
|
|
encoder_help='rav1e --fullhelp',
|
2020-08-13 23:02:59 +00:00
|
|
|
default_args=['--tiles', '8', '--speed', '6', '--quantizer', '100'],
|
2020-08-19 19:50:31 +00:00
|
|
|
default_passes=1,
|
2020-11-25 07:46:37 +00:00
|
|
|
default_q_range=(50, 170),
|
2020-08-13 23:02:59 +00:00
|
|
|
output_extension='ivf'
|
|
|
|
)
|
|
|
|
|
2020-11-25 07:32:26 +00:00
|
|
|
def compose_1_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
|
2020-08-13 23:02:59 +00:00
|
|
|
return [
|
2020-08-19 07:06:42 +00:00
|
|
|
CommandPair(
|
|
|
|
Encoder.compose_ffmpeg_pipe(a),
|
2020-11-11 15:10:30 +00:00
|
|
|
['rav1e', '-', '-y', *a.video_params, '--output', output]
|
2020-08-19 07:06:42 +00:00
|
|
|
)
|
2020-08-13 23:02:59 +00:00
|
|
|
]
|
|
|
|
|
2020-11-25 07:32:26 +00:00
|
|
|
def compose_2_pass(self, a: Project, c: Chunk, output: str) -> MPCommands:
|
2020-08-13 23:02:59 +00:00
|
|
|
return [
|
2020-08-19 07:06:42 +00:00
|
|
|
CommandPair(
|
|
|
|
Encoder.compose_ffmpeg_pipe(a),
|
2020-11-11 15:10:30 +00:00
|
|
|
['rav1e', '-', '-q', '-y', '--first-pass', f'{c.fpf}.stat', *a.video_params, '--output', os.devnull]
|
2020-08-19 07:06:42 +00:00
|
|
|
),
|
|
|
|
CommandPair(
|
|
|
|
Encoder.compose_ffmpeg_pipe(a),
|
2020-11-11 15:10:30 +00:00
|
|
|
['rav1e', '-', '-y', '--second-pass', f'{c.fpf}.stat', *a.video_params, '--output', output]
|
2020-08-19 07:06:42 +00:00
|
|
|
)
|
2020-08-13 23:02:59 +00:00
|
|
|
]
|
2020-08-19 22:10:29 +00:00
|
|
|
|
2020-08-22 19:24:09 +00:00
|
|
|
def man_q(self, command: Command, q: int) -> Command:
|
2020-08-19 22:10:29 +00:00
|
|
|
"""Return command with new cq value
|
|
|
|
|
|
|
|
:param command: old command
|
|
|
|
:param q: new cq value
|
|
|
|
:return: command with new cq value"""
|
|
|
|
|
|
|
|
adjusted_command = command.copy()
|
|
|
|
|
|
|
|
i = list_index_of_regex(adjusted_command, r"--quantizer")
|
|
|
|
adjusted_command[i + 1] = f'{q}'
|
|
|
|
|
|
|
|
return adjusted_command
|
2020-08-21 13:31:09 +00:00
|
|
|
|
2020-08-22 19:24:09 +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 'error' in line.lower():
|
|
|
|
print('\n\nERROR IN ENCODING PROCESS\n\n', line)
|
|
|
|
terminate()
|
2020-08-22 19:24:09 +00:00
|
|
|
return re.search(r"encoded.*? ([^ ]+?) ", line)
|