Last active
October 26, 2024 17:17
-
-
Save RyougiKukoc/ed4f4ecd88ccef7cfc8344e32bd25a40 to your computer and use it in GitHub Desktop.
Need to keepthe same number of m2ts and mkv
This file contains hidden or 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
import vapoursynth as vs | |
import rksfunc as rks | |
import os | |
import random | |
from awsmfunc import FrameInfo | |
from math import ceil | |
from mvsfunc import ToRGB | |
core = vs.core | |
core.max_cache_size = 25600 | |
# Control Panel | |
random.seed(19260817) # 随机种子不变抽出来的图不变 | |
sample_itv = 5000 # 平均每多少帧抽检一次 | |
start_num = 1 | |
num_len = 4 # 比如你最多有 7654 张对比图,这里就填 4(位数) | |
crop_param = {'left': 0, 'right': 0, 'top': 0, 'bottom': 0} | |
src_ext = '.m2ts' # 源文件后缀名 | |
rip_ext = '.mkv' # 压制文件后缀名 | |
style = ("Consolas,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,0,7,10,10,10,1") | |
os.makedirs('src', exist_ok=True) | |
os.makedirs('rip', exist_ok=True) | |
filelist = os.listdir() | |
srclist = [fn for fn in filelist if fn.endswith(src_ext)] | |
dstlist = [fn for fn in filelist if fn.endswith(rip_ext)] | |
for srcfn, dstfn in zip(srclist, dstlist): | |
src = rks.sourcer(srcfn).std.Crop(**crop_param) | |
dst = rks.sourcer(dstfn) | |
src = FrameInfo(ToRGB(rks.uvsr(src), depth=8), 'Source', style) | |
dst = FrameInfo(ToRGB(rks.uvsr(dst), depth=8), 'Rip', style) | |
num_frames = src.num_frames if src.num_frames == dst.num_frames else 0 | |
if num_frames == 0: | |
continue | |
sample_num = ceil(num_frames / sample_itv) | |
sample_idx = random.sample(list(range(num_frames)), min(sample_num, num_frames)) | |
srcset, dstset = None, None | |
for idx in sample_idx: | |
src.get_frame(idx) | |
if srcset is None: | |
srcset = src[idx] | |
else: | |
srcset = srcset + src[idx] | |
if dstset is None: | |
dstset = dst[idx] | |
else: | |
dstset = dstset + dst[idx] | |
out = srcset.imwri.Write('PNG', f'./src/%0{num_len}dsrc.png', start_num, overwrite=True) + \ | |
dstset.imwri.Write('PNG', f'./rip/%0{num_len}drip.png', start_num, overwrite=True) | |
for frame in out.frames(close=True): | |
pass | |
start_num += srcset.num_frames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment