-
-
Save HolyWu/c73b296c802f657be7b4b8f8a90b4cf2 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 hashlib | |
import random | |
import sys | |
import vapoursynth as vs | |
from vapoursynth import core | |
def hash_frame(frame): | |
sha256 = hashlib.sha256() | |
for plane in range(frame.format.num_planes): | |
sha256.update(frame[plane].tobytes()) | |
return sha256.hexdigest() | |
clip = core.bs.VideoSource(sys.argv[1], cachesize=0) | |
# clip = core.d2v.Source(sys.argv[1], rff=False) | |
# clip = core.dgdecode.MPEG2Source(sys.argv[1]) | |
# clip = core.dgdecodenv.DGSource(sys.argv[1]) | |
# clip = core.ffms2.Source(sys.argv[1]) | |
# clip = core.lsmas.LWLibavSource(sys.argv[1], repeat=0) | |
if len(sys.argv) == 4: | |
start = int(sys.argv[2]) | |
end = int(sys.argv[3]) | |
clip = clip.std.Trim(start, end) | |
print(f"Clip has {clip.num_frames} frames.") | |
reference = [] | |
for i in range(clip.num_frames): | |
reference.append(hash_frame(clip.get_frame(i))) | |
if i % 10 == 0: | |
print(f"Hashing: {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(f"Requested frame {i}, ", end="") | |
try: | |
print(f"got frame {reference.index(result)}.") | |
except ValueError: | |
print(f"got new frame with hash {result}.") | |
if test.index(i) % 10 == 0: | |
print(f"Seeking: {test.index(i) * 100 // (clip.num_frames - 1)}%", end="\r") | |
except vs.Error as e: | |
print(f"requesting frame {i} broke source filter. total: {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