-
Notifications
You must be signed in to change notification settings - Fork 4
/
eval.py
executable file
·51 lines (42 loc) · 1.85 KB
/
eval.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
#!/usr/bin/python
# Given input video files, we prepare them, evaluate their quality, print the result and clean up.
# Kah Keng Tay
import sys, utils
if len(sys.argv) != 3:
print "Syntax: eval.py <refvideo> <testvideo>"
sys.exit(1)
d = {}
[d['refvideo'], d['testvideo']] = sys.argv[1:]
d['ffmpeg'] = '/path/to/ffmpeg'
d['vqats'] = '/path/to/vqatsAx'
d['resize'] = '160x120'
d['suffix'] = 'resized.mpg'
if len(d['resize']) > 0:
# check if resized version of refvideo exists, if so, no need to recreate
if not utils.file_exists('%(refvideo)s.%(suffix)s' % d):
utils.shell_exec('%(ffmpeg)s -i %(refvideo)s -s 160x120 %(refvideo)s.%(suffix)s > /dev/null' % d)
# check if resized version of testvideo exists, if so, delete it first before recreating
if utils.file_exists('%(testvideo)s.%(suffix)s' % d):
utils.shell_exec('rm -f %(testvideo)s.%(suffix)s' % d)
# resize the testvideo again
utils.shell_exec('%(ffmpeg)s -i %(testvideo)s -s 160x120 %(testvideo)s.%(suffix)s > /dev/null' % d)
d['refvideo'] = '%(refvideo)s.%(suffix)s' % d
d['testvideo'] = '%(testvideo)s.%(suffix)s' % d
# create temporary directories to prepare the videos
utils.shell_exec('mkdir -p %(refvideo)s.tmp' % d)
utils.shell_exec('mkdir -p %(testvideo)s.tmp' % d)
try:
# prepare videos
d['ref'] = utils.prepare_video_file(d['refvideo'], d['refvideo']+'.tmp', d['ffmpeg'])
d['test'] = utils.prepare_video_file(d['testvideo'], d['testvideo']+'.tmp', d['ffmpeg'])
# run evaluation
output = utils.shell_exec('%(vqats)s %(ref)s %(test)s' % d)
print "vqats = " + output[-1].strip().split(' ')[-1]
except:
print "vqats = -1"
pass
# clean up
utils.shell_exec('rm -rf %(refvideo)s.tmp' % d)
utils.shell_exec('rm -rf %(testvideo)s.tmp' % d)
if len(d['resize']) > 0:
utils.shell_exec('rm -f %(testvideo)s' % d) # this is the resized file