WolframRhodium / muvsfunc

Muonium's VapourSynth functions
75 stars 19 forks source link

Error getting frame: all input arrays must have the same shape #32

Closed sosie-js closed 3 years ago

sosie-js commented 3 years ago

Hello, I am starting to use opencv with vapoursynth.

I tried to play the pencilsketch sample, but I get the message when rendered with mpv using video test.webm [ffmpeg/demuxer] vapoursynth: Error getting frame: all input arrays must have the same shape

my test code is:


import numpy as np
import cv2
import muvsfunc_numpy as mufnp

import vapoursynth as vs
from  vapoursynth import core

video ="tests/test.webm"
import os
script_dir = os.path.dirname(__file__)
rel_path = video
abs_file_path=os.path.join(script_dir, rel_path)
rgb = core.ffms2.Source(source= abs_file_path)

def resize_core2(img, w, h):
    return cv2.resize(img, dsize=(w, h), interpolation=cv2.INTER_CUBIC)

#clip=rgb
#pencil_core2 = lambda img: cv2.pencilSketch(img)[1]
# This time we define a function explicitly rather than using anonymous function
def pencil_core(original_img):
    w=1280
    h=720
    # resize image fix it? no
    resized_img = resize_core2(original_img, w, h)
    img=cv2.pencilSketch(resized_img)[1]
    return img

#clip = mufnp.numpy_process(rgb, pencil_core2, input_per_plane=False, output_per_plane=False)
clip = mufnp.numpy_process(rgb, pencil_core, input_per_plane=False, output_per_plane=False)
#clip=rgb
#print(clip)

import mvsfunc as mvf
clip = mvf.ToYUV(clip,matrix = "709", css = "420", depth = 8) 
clip.set_output()   

Normaly video frames have the same image size as video so I don't understand

WolframRhodium commented 3 years ago

Hi. Sorry for the late response.

There are two places that need to be changed:

1.

rgb = core.ffms2.Source(source= abs_file_path)

should be changed to

rgb = mvf.ToRGB(core.ffms2.Source(source= abs_file_path))

to ensure the clip is in RGB format.

  1. clip = mufnp.numpy_process(rgb, pencil_core, input_per_plane=False, output_per_plane=False)

    should be changed to

    empty = core.std.BlankClip(rgb, width=1280, height=720)
    clip = mufnp.numpy_process([empty, rgb], pencil_core, input_per_plane=False, output_per_plane=False, omit_first_clip=True)

    since the size of the output is not equal to the input. If the cv2.resize is removed, this change is not necessary.

It should work after above changes.

sosie-js commented 3 years ago

That sounds cool! Big thanks WolframRhodium, here is the resulting file version_opencv.vpy