Skip to content

Instantly share code, notes, and snippets.

@dubhater
Last active April 24, 2022 13:01
Show Gist options
  • Save dubhater/983e992f5469140355497361094bd7da to your computer and use it in GitHub Desktop.
Save dubhater/983e992f5469140355497361094bd7da to your computer and use it in GitHub Desktop.
import vapoursynth as vs
import sys
import os
import argparse
parser = argparse.ArgumentParser(description="Detect combed frames and write them in a log file.")
parser.add_argument("folder", help="path to a folder to process")
parser.add_argument("--applyrff", help="tell d2vsource to apply the RFF flags", action="store_true")
parser.add_argument("--vfm", help="use VFM after the source filter", action="store_true")
parser.add_argument("--vdecimate", help="use VDecimate", action="store_true")
allowed_extensions = [".mkv", ".d2v", ".264", ".vpy"]
parser.add_argument("--extensions", help="video file extensions to process", nargs="+", default=allowed_extensions, choices=allowed_extensions)
args = parser.parse_args()
core = vs.core
files_to_process = []
with os.scandir(args.folder) as it:
extensions = tuple(args.extensions)
for entry in it:
if entry.is_file() and entry.name.endswith(extensions):
files_to_process.append(os.path.join(args.folder, entry.name))
files_to_process.sort()
def callback(node, n, result):
pass
for i in range(len(files_to_process)):
src_file = files_to_process[i]
print("[{}/{}] Processing {}".format(i + 1, len(files_to_process), src_file))
if src_file.endswith("d2v"):
src = core.d2v.Source(src_file, rff=args.applyrff)
elif src_file.endswith("vpy"):
with open(src_file, "r") as script:
exec(script.read())
src = vs.get_output(index=0)
else:
src = core.ffms2.Source(src_file)
if args.vfm:
src = core.vivtc.VFM(src, order=1, cthresh=8)
if args.vdecimate:
src = core.vivtc.VDecimate(src)
src = core.tdm.IsCombed(src, cthresh=8)
with open(src_file + ".combed.txt", "w") as f:
next_frame = 0
for i in range(core.num_threads):
src.get_frame_async_raw(next_frame, callback)
next_frame += 1
for i in range(src.num_frames):
if src.get_frame(i).props["_Combed"] == 1:
f.write("{}\n".format(i))
if next_frame <= src.num_frames - 1:
src.get_frame_async_raw(next_frame, callback)
next_frame += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment