-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_vmaf-psnr.py
53 lines (43 loc) · 1.53 KB
/
check_vmaf-psnr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import os
import subprocess
import sys
def install_dependencies():
if sys.platform.startswith("linux"):
os.system("sudo apt-get update")
os.system("sudo apt-get install ffmpeg")
elif sys.platform.startswith("darwin"):
os.system("brew update")
os.system("brew install ffmpeg")
else:
print("Unsupported operating system")
sys.exit(1)
def check_dependencies():
try:
subprocess.check_output(["ffmpeg", "-version"])
subprocess.check_output(["ffprobe", "-version"])
except FileNotFoundError:
print("FFmpeg and FFprobe not found, installing...")
install_dependencies()
def calculate_vmaf_psnr(source, converted):
command = (
f'ffmpeg -i {source} -i {converted} -lavfi '
f'"[0:v]setpts=PTS-STARTPTS[ref];[1:v]setpts=PTS-STARTPTS[main];'
f'[main][ref]libvmaf=model_path=vmaf_v0.6.1.pkl:psnr=1:log_fmt=json" '
f'-f null -'
)
output = subprocess.check_output(command, shell=True, text=True)
print(output)
def main():
check_dependencies()
if len(sys.argv) != 3:
print("Usage: python check_vmaf_psnr.py <source_video> <converted_video>")
sys.exit(1)
source_video = sys.argv[1]
converted_video = sys.argv[2]
if not os.path.isfile(source_video) or not os.path.isfile(converted_video):
print("One or both of the input files do not exist.")
sys.exit(1)
calculate_vmaf_psnr(source_video, converted_video)
if __name__ == "__main__":
main()