20.03.2024, 15:25
good!
Unfortunately it seems that there is something wrong with Average Frames.
Here an example using 7 frames, with average: center, left, right
https://imgsli.com/MjQ4ODEx
The situation get worse if the number of frames is increased.
https://imgsli.com/MjQ4ODEy
I'm trying to write my own average filter, but it is seem that is not possible to access past frames using Vapoursynth
Here my code
The problem is in the call: frame_to_image(clip.get_frame(n-i))
When nframes>1 Vapoursynth freeze.
Do you have any idea on how to access past frames from Vapoursynth ?
Thanks,
Dan
Unfortunately it seems that there is something wrong with Average Frames.
Here an example using 7 frames, with average: center, left, right
https://imgsli.com/MjQ4ODEx
The situation get worse if the number of frames is increased.
https://imgsli.com/MjQ4ODEy
I'm trying to write my own average filter, but it is seem that is not possible to access past frames using Vapoursynth
Here my code
def clip_color_stabilizer(clip: vs.VideoNode = None, nframes: int = 5, smooth_type: int = 0) -> vs.VideoNode:
max_frames = max(1, min(nframes, 31))
def smooth_frame(n, f):
f_out = f.copy()
if n < max_frames:
return f_out
img_f = list()
img_f.append(frame_to_image(f))
for i in range(1, max_frames):
img_f.append(frame_to_image(clip.get_frame(n-i)))
img_m = color_temporal_stabilizer(img_f, max_frames)
return image_to_frame(img_m, f_out)
clip = clip.std.ModifyFrame(clips=[clip], selector=smooth_frame)
return clip
#-----------------------------------------------------------------------
def color_temporal_stabilizer(img_f: list, nframes: int = 5) -> Image:
img_new = np.copy(np.asarray(img_f[0]))
yuv_new = cv2.cvtColor(img_new, cv2.COLOR_RGB2YUV)
weight: float = 1.0/nframes
yuv_m = np.multiply(yuv_new, weight).clip(0, 255).astype(int)
for i in range (1, nframes):
yuv_i = cv2.cvtColor(np.asarray(img_f[i]), cv2.COLOR_RGB2YUV)
yuv_m += np.multiply(yuv_i, weight).clip(0, 255).astype(int)
yuv_new[:, :, 1] = yuv_m[:, :, 1]
yuv_new[:, :, 2] = yuv_m[:, :, 2]
return Image.fromarray(cv2.cvtColor(yuv_new, cv2.COLOR_YUV2RGB))
The problem is in the call: frame_to_image(clip.get_frame(n-i))
When nframes>1 Vapoursynth freeze.
Do you have any idea on how to access past frames from Vapoursynth ?
Thanks,
Dan