Last active
July 11, 2023 14:28
-
-
Save dubhater/3a2c8a59841cae49ecae25cd47ff78d2 to your computer and use it in GitHub Desktop.
Test the reliability of your favourite source filter
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
# Usage: | |
# python3 seek-test.py file.mkv [start_frame end_frame] | |
# | |
# Change the source filter as needed. | |
# Note: this script is slow because making the source filter decode frames randomly is slow. | |
import vapoursynth as vs | |
import sys, hashlib, random | |
c = vs.get_core(add_cache=False) | |
clip = c.d2v.Source(sys.argv[1], rff=False) | |
#clip = c.ffms2.Source(sys.argv[1]) | |
#clip = c.lsmas.LWLibavSource(sys.argv[1]) | |
start = 0 | |
end = clip.num_frames - 1 | |
if len(sys.argv) == 4: | |
start = int(sys.argv[2]) | |
end = int(sys.argv[3]) | |
clip = c.std.Trim(clip, start, end) | |
print("Clip has {} frames.".format(clip.num_frames)) | |
def hash_frame(frame): | |
md5 = hashlib.md5() | |
for plane in range(frame.format.num_planes): | |
for line in frame.get_read_array(plane): | |
md5.update(line) | |
return md5.hexdigest() | |
reference = [] | |
for i in range(clip.num_frames): | |
reference.append(hash_frame(clip.get_frame(i))) | |
if i % 100 == 0: | |
print("Hashing: {}%".format(i * 100 // (clip.num_frames - 1)), end='\r') | |
print("\nClip hashed.\n") | |
test = list(range(clip.num_frames)) | |
random.shuffle(test) | |
for i in test: | |
try: | |
result = hash_frame(clip.get_frame(i)) | |
if (result != reference[i]): | |
print("Requested frame {}, ".format(i), end='') | |
try: | |
print("got frame {}.".format(reference.index(result))) | |
except ValueError: | |
print("got new frame with hash {}.".format(result)) | |
print(" Previous requests:", end='') | |
start = test.index(i) - 10 | |
if (start < 0): | |
start = 0 | |
for j in range(start, test.index(i) + 1): | |
print(" {}".format(test[j]), end='') | |
print("") | |
if test.index(i) % 100 == 0: | |
print("Seeking: {}%".format(test.index(i) * 100 // (clip.num_frames - 1)), end='\r') | |
except vs.Error as e: | |
print("requesting frame {} broke d2vsource. total: {}".format(i, len(test))) | |
raise e | |
print("Test complete.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment