yt_de_study/compare.py
Daniel Tsvetkov 438683ca10 syncing
2020-09-06 17:36:01 +02:00

39 lines
1.1 KiB
Python

from common import run_os_cmd
SEARCH_RANGE = 5.000
SEARCH_STEP = 0.100
DEBUG = False
def compare_at_time(t):
run_os_cmd("ffmpeg -y -ss {} -i de.mp4 -vframes 1 -q:v 2 tmp/de.png 2>/dev/null".format(t), False)
run_os_cmd("compare -metric AE -fuzz 5% tmp/en.png tmp/de.png tmp/diff.png >tmp/diff_value 2>&1", False)
with open("tmp/diff_value") as f:
diff_value = f.read()
if DEBUG:
print("{:6.3f},{}".format(t, diff_value))
return int(diff_value)
def linear_compare(en_time, search_range=SEARCH_RANGE, search_step=SEARCH_STEP):
run_os_cmd("ffmpeg -y -ss {} -i en.mp4 -vframes 1 -q:v 2 tmp/en.png 2>/dev/null".format(en_time), False)
min_time, min_val, de_time = en_time, float('+inf'), en_time - search_range
while de_time < en_time + search_range:
de_time += search_step
val = compare_at_time(de_time)
if val < min_val:
min_val, min_time = val, de_time
compare_at_time(min_time)
return min_time, min_val
def main():
en_time = 10.000
de_time, min_val = linear_compare(en_time)
de_delta = de_time - en_time
return de_delta
if __name__ == "__main__":
main()