mirror of
https://github.com/master-of-zen/Av1an.git
synced 2024-11-25 02:29:40 +00:00
Refactoring, Couting frames on resume
This commit is contained in:
parent
2a369aa162
commit
09b6de3a6c
1 changed files with 70 additions and 54 deletions
70
av1an.py
70
av1an.py
|
@ -149,6 +149,7 @@ class Av1an:
|
||||||
self.workers += 1
|
self.workers += 1
|
||||||
|
|
||||||
def setup(self, input_file: Path):
|
def setup(self, input_file: Path):
|
||||||
|
|
||||||
if not input_file.exists():
|
if not input_file.exists():
|
||||||
print(f'File: {input_file} not exist')
|
print(f'File: {input_file} not exist')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -429,11 +430,11 @@ class Av1an:
|
||||||
print('Concatenation failed')
|
print('Concatenation failed')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def image(self, image_path: Path):
|
def image_encoding(self):
|
||||||
print('Encoding Image..', end='')
|
print('Encoding Image..', end='')
|
||||||
|
|
||||||
image_pipe = rf'{self.FFMPEG} -i {image_path} -pix_fmt yuv420p10le -f yuv4mpegpipe -strict -1 - | '
|
image_pipe = rf'{self.FFMPEG} -i {self.args.file_path} -pix_fmt yuv420p10le -f yuv4mpegpipe -strict -1 - | '
|
||||||
output = image_path.with_suffix('.ivf')
|
output = self.args.file_path.with_suffix('.ivf')
|
||||||
|
|
||||||
if self.encoder == 'aom':
|
if self.encoder == 'aom':
|
||||||
aom = ' aomenc --passes=1 --pass=1 --end-usage=q -b 10 --input-bit-depth=10 '
|
aom = ' aomenc --passes=1 --pass=1 --end-usage=q -b 10 --input-bit-depth=10 '
|
||||||
|
@ -449,13 +450,36 @@ class Av1an:
|
||||||
print(f'Not valid encoder: {self.encoder}')
|
print(f'Not valid encoder: {self.encoder}')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def main(self):
|
def encoding_loop(self, commands):
|
||||||
|
# Creating threading pool to encode bunch of files at the same time and show progress bar
|
||||||
|
with Pool(self.workers) as pool:
|
||||||
|
|
||||||
# Parse initial arguments
|
self.workers = min(len(commands), self.workers)
|
||||||
self.arg_parsing()
|
enc_path = self.temp_dir / 'split'
|
||||||
|
if self.args.resume:
|
||||||
|
done_path = Path('.temp/done.txt')
|
||||||
|
if done_path.exists():
|
||||||
|
with open(done_path, 'r') as f:
|
||||||
|
done = literal_eval(f.read())
|
||||||
|
|
||||||
# Video Mode
|
initial = sum([self.frame_probe(x) for x in enc_path.iterdir() if x.name in done])
|
||||||
if self.mode == 0:
|
else:
|
||||||
|
initial = 0
|
||||||
|
print(
|
||||||
|
f'\rClips: {initial} Workers: {self.workers} Passes: {self.encode_pass}\nParams: {self.encoding_params}')
|
||||||
|
|
||||||
|
bar = tqdm(total=self.frame_probe(self.args.file_path),
|
||||||
|
initial=initial, dynamic_ncols=True, unit="fr",
|
||||||
|
leave=False)
|
||||||
|
loop = pool.imap_unordered(self.encode, commands)
|
||||||
|
try:
|
||||||
|
for enc_frames in loop:
|
||||||
|
bar.update(n=enc_frames)
|
||||||
|
except (ValueError, Exception):
|
||||||
|
print('Encoding error')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
def video_encoding(self):
|
||||||
|
|
||||||
if not (self.args.resume and self.temp_dir.exists()):
|
if not (self.args.resume and self.temp_dir.exists()):
|
||||||
# Check validity of request and create temp folders/files
|
# Check validity of request and create temp folders/files
|
||||||
|
@ -483,32 +507,24 @@ class Av1an:
|
||||||
else:
|
else:
|
||||||
self.determine_resources()
|
self.determine_resources()
|
||||||
|
|
||||||
# Creating threading pool to encode bunch of files at the same time and show progress bar
|
self.encoding_loop(commands)
|
||||||
with Pool(self.workers) as pool:
|
|
||||||
|
|
||||||
self.workers = min(len(commands), self.workers)
|
|
||||||
enc_path = self.temp_dir / 'split'
|
|
||||||
initial = len([x for x in enc_path.iterdir() if x.suffix == '.mkv'])
|
|
||||||
print(f'\rClips: {initial} Workers: {self.workers} Passes: {self.encode_pass}\nParams: {self.encoding_params}')
|
|
||||||
|
|
||||||
bar = tqdm(total=self.frame_probe(self.args.file_path),
|
|
||||||
initial=0, dynamic_ncols=True, unit="fr",
|
|
||||||
leave=False)
|
|
||||||
loop = pool.imap_unordered(self.encode, commands)
|
|
||||||
try:
|
|
||||||
for b in loop:
|
|
||||||
bar.update(n=b)
|
|
||||||
except ValueError:
|
|
||||||
print('Encoding error')
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
self.concatenate_video()
|
self.concatenate_video()
|
||||||
|
|
||||||
# Delete temp folders
|
# Delete temp folders
|
||||||
shutil.rmtree(self.temp_dir)
|
shutil.rmtree(self.temp_dir)
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
|
||||||
|
# Parse initial arguments
|
||||||
|
self.arg_parsing()
|
||||||
|
|
||||||
|
# Video Mode
|
||||||
|
if self.mode == 0:
|
||||||
|
self.video_encoding()
|
||||||
|
|
||||||
elif self.mode == 1:
|
elif self.mode == 1:
|
||||||
self.image(self.args.file_path)
|
self.image_encoding()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('No valid work mode')
|
print('No valid work mode')
|
||||||
|
|
Loading…
Reference in a new issue