Moviepy - 以两种不同的方式修改相同的剪辑

时间:2017-04-03 07:09:14

标签: python copy clone clip moviepy

我正在尝试以两种不同的方式修改相同的剪辑:

clipA=original_clip.fx(filter1)
clipB=original_clip.fx(filter2)

我得到的是带有filter1和filter2的clipB。

我该如何避免这种行为?

代码(简化)如下所示:

_left, _right = horizontal( _msf ) # Takes a video and split it in two
ini = (0.5, 0.5)
end = (1., 1.)
_w, _h = _left.size
_cropped = _left.fx( vfx.crop, int(ini[0]*_w), int(ini[1]*_h), int(end[0]*_w), int(end[1]*_h)) # A new video with a cropped area
_left_hl = _left.fx( highlight, (0.5, 0.5), (1., 1.) )  # Highlights the area to be cropped in the original video

结果是剪辑“_cropped”会突出显示为副作用。

高亮显示功能如下:

def highlight(clip, ini, end, edge_color= (255,100,255), edge_size= 10, fill_color = (255,255,0), alpha = 0.3 ):
    w, h = clip.size

    def fl(im):
        """ Highlights an area"""
        _ini = (int(ini[0]*w), int(ini[1]*h))
        _end = (int(end[0]*w), int(end[1]*h))

        _overlay = im.copy()
        _overlay = cv2.rectangle(_overlay, _ini, _end, edge_color,edge_size)
        _overlay = cv2.rectangle(_overlay, _ini, _end,fill_color,-1)
        cv2.addWeighted(_overlay, alpha, im, 1 - alpha,0, im)
        return im

    return clip.fl_image(fl)

通过将过滤器更改为:

来修复
def highlight(clip, ini, end, edge_color= (255,100,255), edge_size= 10, fill_color = (255,255,0), alpha = 0.3 ):
    w, h = clip.size

    def fl(im):
        """ Highlights an area"""
        _tmp = im.copy()
        _ini = (int(ini[0]*w), int(ini[1]*h))
        _end = (int(end[0]*w), int(end[1]*h))

        _overlay = im.copy()
        _overlay = cv2.rectangle(_overlay, _ini, _end, edge_color,edge_size)
        _overlay = cv2.rectangle(_overlay, _ini, _end,fill_color,-1)
        cv2.addWeighted(_overlay, alpha, _tmp, 1 - alpha,0, _tmp)
        return _tmp

    return clip.fl_image(fl)

1 个答案:

答案 0 :(得分:0)

无需深度复制,您的原始代码应该有效。也许你在filter1和filter2中做错了什么?你能分享这些过滤器的代码吗?