Created
July 2, 2020 18:23
-
-
Save cdgriffith/20c8bbb220a05358da47710e2a512308 to your computer and use it in GitHub Desktop.
Compare a movie via VMAF to a lot of different encoding settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import run, PIPE, STDOUT | |
from pathlib import Path | |
from datetime import datetime | |
import os | |
movie_file = "video_compare/glass.mp4" | |
file_name = "glass" | |
output_directory = "video_compare/ffmpeg" | |
for crf in ["16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28"]: | |
for preset in ["ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow"]: | |
print(f"{datetime.now().isoformat()} - Running crf {crf} for preset {preset}") | |
a = run( | |
f'ffmpeg.exe -y -i "{movie_file}" -t 11 -map 0:0 -c:v libx265 -x265-params hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc::master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(0,0)L(40000000,50)" -crf {crf} -preset {preset} "{output_directory}/{file_name}_{crf}_{preset}.mkv"', | |
shell=True, stdout=PIPE, stderr=STDOUT, cwd=os.getcwd()) | |
Path(f"{output_directory}/glass_{crf}_{preset}.log").write_bytes(a.stdout) | |
print(f"{datetime.now().isoformat()} - Encoded done with crf {crf} for preset {preset}") | |
cmd2 = (f'ffmpeg.exe -y ' | |
f'-i "{output_directory}/{file_name}_{crf}_{preset}.mkv" ' | |
f'-i "{movie_file}" -t 10 -lavfi libvmaf="model_path=vmaf_4k_v0.6.1.pkl:log_path={output_directory}/{file_name}_{crf}_{preset}_details.txt;[0:v][1:v]ssim=1" -report -f null -\n') | |
b = run(cmd2, shell=True, stdout=PIPE, stderr=STDOUT, cwd="C:\\Users\\Chris") | |
Path(f"{output_directory}/{file_name}_{crf}_{preset}.score.log").write_bytes(b.stdout) | |
print(f"{datetime.now().isoformat()} - Done with crf {crf} for preset {preset}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment