mirror of
https://github.com/master-of-zen/Av1an.git
synced 2024-11-25 02:29:40 +00:00
Tiles enabled
-row-mt 1 -tiles 2x2
This commit is contained in:
parent
3511db64ee
commit
c69ce9ce6a
1 changed files with 25 additions and 9 deletions
34
main.py
34
main.py
|
@ -3,8 +3,8 @@
|
|||
mkvmerge required (python-pymkv)
|
||||
ffmpeg required
|
||||
TODO:
|
||||
make encoding queue with limiting by workers,
|
||||
make concatenating videos,
|
||||
DONE make encoding queue with limiting by workers
|
||||
DONE make concatenating videos after encoding
|
||||
make passing your arguments for encoding,
|
||||
make separate audio and encode it separately,
|
||||
"""
|
||||
|
@ -26,6 +26,10 @@ def get_ram():
|
|||
return round((os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')) / (1024. ** 3), 3)
|
||||
|
||||
|
||||
def extract_audio(input_vid):
|
||||
cmd = f'ffmpeg -i {os.getcwd()}/{input_vid} -vn -acodec copy {os.getcwd()}/temp/audio.aac'
|
||||
|
||||
|
||||
def split_video(input_vid):
|
||||
cmd2 = f'scenedetect -i {input_vid} --output temp/split detect-content split-video -c'
|
||||
subprocess.call(cmd2, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
@ -43,14 +47,23 @@ def get_video_queue(source_path):
|
|||
|
||||
|
||||
def encode(commands):
|
||||
print('encoding')
|
||||
cmd = f'ffmpeg {commands}'
|
||||
subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()
|
||||
subprocess.Popen(cmd, shell=True).wait()
|
||||
|
||||
|
||||
def concat(directory):
|
||||
cmd = ''
|
||||
subprocess.call(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
def concat():
|
||||
"""
|
||||
Using FFMPEG to concatenate all encoded videos to 1 file.
|
||||
Reading all files in A-Z order and saving it to concat.txt
|
||||
"""
|
||||
with open(f'{os.getcwd()}/temp/concat.txt', 'w') as f:
|
||||
|
||||
for root, firs, files in os.walk(f'{os.getcwd()}/temp/encoded'):
|
||||
for file in sorted(files):
|
||||
f.write(f"file '{os.path.join(root, file)}'\n")
|
||||
|
||||
cmd = f'ffmpeg -f concat -safe 0 -i {os.getcwd()}/temp/concat.txt -c copy output.mp4'
|
||||
subprocess.Popen(cmd, shell=True).wait()
|
||||
|
||||
|
||||
def main(input_video):
|
||||
|
@ -60,7 +73,8 @@ def main(input_video):
|
|||
os.makedirs(f'{os.getcwd()}/temp/encoded', exist_ok=True)
|
||||
|
||||
# Passing encoding parameters
|
||||
encoding_params = ' -an -c:v libaom-av1 -strict -2 -cpu-used 8 -crf 60'
|
||||
# no audio av1 codec adding tiles speed quality
|
||||
encoding_params = ' -an -c:v libaom-av1 -strict -2 -row-mt 1 -tiles 2x2 -cpu-used 8 -crf 60 '
|
||||
|
||||
# Spliting video and sorting big-first
|
||||
split_video(input_video)
|
||||
|
@ -71,9 +85,11 @@ def main(input_video):
|
|||
commands = [f'-i {os.getcwd()}/temp/split/{file} {encoding_params} {os.getcwd()}/temp/encoded/{file}' for file in files]
|
||||
|
||||
# Creating threading pool to encode fixed amount of files at the same time
|
||||
pool = Pool(4)
|
||||
pool = Pool(6)
|
||||
pool.map(encode, commands)
|
||||
|
||||
# Merging all encoded videos to 1
|
||||
concat()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main('bruh.mp4')
|
Loading…
Reference in a new issue