How to use the moviepy.video.VideoClip.ImageClip function in moviepy

To help you get started, we’ve selected a few moviepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Zulko / moviepy / tests / test_PR.py View on Github external
def test_PR_528():
    with ImageClip("media/vacation_2017.jpg") as clip:
        new_clip = scroll(clip, w=1000, x_speed=50)
        new_clip = new_clip.set_duration(1)
        new_clip.fps = 24
        new_clip.write_videofile(os.path.join(TMP_DIR, "pano.mp4"))
github Zulko / moviepy / moviepy / video / tools / credits.py View on Github external
stroke_width=stroke_width,font=font,
                                fontsize=fontsize,align=al)
               for txt,al in [(left,'East'),(right,'West')]]
               

    cc = CompositeVideoClip( [left, right.set_pos((left.w+gap,0))],
                             size = (left.w+right.w+gap,right.h),
                             transparent=True)
    
    # SCALE TO THE REQUIRED SIZE
    
    scaled = cc.fx(resize , width=width)
    
    # TRANSFORM THE WHOLE CREDIT CLIP INTO AN ImageCLip
    
    imclip = ImageClip(scaled.get_frame(0))
    amask = ImageClip(scaled.mask.get_frame(0),ismask=True)
    
    return imclip.set_mask(amask)
github Zulko / moviepy / moviepy / video / fx / freeze_at_end.py View on Github external
def freeze_at_end(clip, freeze_duration=None,
                  total_duration=None, delta=0.05):
    """
    Makes the clip freeze on its last frame.  With ``duration`` you can
    specify the duration of the freeze. With ``total_duration`` you can
    specify the total duration of the clip and the freeze (i.e. the
    duration of the freeze is automatically calculated). If neither
    is provided, the freeze will have an infinite length.
    
    The clip is frozen on the frame at time (clip.duration - delta)
    """
    
    freezed_clip = ImageClip(clip.get_frame(clip.end - delta))
    if total_duration:
        freeze_duration = total_duration - clip.duration
    if freeze_duration:
        freezed_clip = freezed_clip.set_duration(freeze_duration)
    
    return CompositeVideoClip([clip,freezed_clip.set_start(clip.end)])
github Zulko / moviepy / moviepy / video / VideoClip.py View on Github external
def to_ImageClip(self, t=0, with_mask=True, duration=None):
        """
        Returns an ImageClip made out of the clip's frame at time ``t``,
        which can be expressed in seconds (15.35), in (min, sec),
        in (hour, min, sec), or as a string: '01:03:05.35'.
        """
        newclip = ImageClip(self.get_frame(t), ismask=self.ismask,
                            duration=duration)
        if with_mask and self.mask is not None:
            newclip.mask = self.mask.to_ImageClip(t)
        return newclip
github achalddave / vid / vid / utils / moviepy_wrappers / text_clip.py View on Github external
if print_cmd:
            print(" ".join(cmd))

        try:
            subprocess_call(cmd, verbose=False)
        except (IOError, OSError) as err:
            error = ("MoviePy Error: creation of %s failed because of the "
                     "following error:\n\n%s.\n\n." % (tempfilename, str(err))
                     + ("This error can be due to the fact that ImageMagick "
                        "is not installed on your computer, or (for Windows "
                        "users) that you didn't specify the path to the "
                        "ImageMagick binary in file conf.py, or that the path "
                        "you specified is incorrect"))
            raise IOError(error)

        ImageClip.__init__(self, tempfilename, transparent=transparent)
        self.txt = txt
        self.color = color
        self.stroke_color = stroke_color

        if remove_temp:
            if os.path.exists(tempfilename):
                os.remove(tempfilename)
            if os.path.exists(temptxt):
                os.remove(temptxt)
github achalddave / vid / vid / vid.py View on Github external
def clip_from_path(path):
    if path == '':
        return None
    elif path.suffix.lower() in IMAGE_EXTENSIONS:
        from moviepy.video.VideoClip import ImageClip
        return ImageClip(str(path))
    else:
        from moviepy.video.io.VideoFileClip import VideoFileClip
        return VideoFileClip(str(path))
github Zulko / moviepy / moviepy / video / VideoClip.py View on Github external
size = self.size
        if pos is None:
            pos = 'center'
        colorclip = ColorClip(size, color=color)

        if col_opacity is not None:
            colorclip = (ColorClip(size, color=color, duration=self.duration)
                         .set_opacity(col_opacity))
            result = CompositeVideoClip([colorclip, self.set_position(pos)])
        else:
            result = CompositeVideoClip([self.set_position(pos)],
                                        size=size,
                                        bg_color=color)

        if (isinstance(self, ImageClip) and (not hasattr(pos, "__call__"))
                and ((self.mask is None) or isinstance(self.mask, ImageClip))):
            new_result = result.to_ImageClip()
            if result.mask is not None:
                new_result.mask = result.mask.to_ImageClip()
            return new_result.set_duration(result.duration)

        return result
github Zulko / moviepy / moviepy / video / VideoClip.py View on Github external
def __init__(self, size, color=None, ismask=False, duration=None, col=None):
        if col is not None:
            warnings.warn("The `ColorClip` parameter `col` has been deprecated."
                          " Please use `color` instead.", DeprecationWarning)
            if color is not None:
                warnings.warn("The arguments `color` and `col` have both been "
                              "passed to `ColorClip` so `col` has been ignored.",
                              UserWarning)
            else:
                color = col
        w, h = size
        shape = (h, w) if np.isscalar(color) else (h, w, len(color))
        ImageClip.__init__(self, np.tile(color, w * h).reshape(shape),
                           ismask=ismask, duration=duration)
github Zulko / moviepy / moviepy / video / fx / freeze_at_start.py View on Github external
def freeze_at_start(clip, freeze_duration=None, total_duration=None):
    """ Momentarily freeze the clip on its first frame.

    With ``duration``you can specify the duration of the freeze.
    With ``total_duration`` you can specify the total duration of
    the clip and the freeze (i.e. the duration of the freeze is
    automatically calculated). If neither is provided, the freeze
    will have an infinite length.
    """
    
    freezed_clip = ImageClip(clip.get_frame(0))
    if clip.mask:
        freezed_clip.mask = ImageClip(clip.mask.get_frame(0))
    
    if total_duration:
        freeze_duration = total_duration - clip.duration
    if freeze_duration:
        freezed_clip = freezed_clip.set_duration(freeze_duration)
    
    return concatenate_videoclips([freezed_clip, clip])
github Zulko / moviepy / moviepy / video / io / html_tools.py View on Github external
>>> mpy.ipython_display('test.ogg')

    >>> clip.write_gif("test.gif")
    >>> mpy.ipython_display('test.gif')

    >>> clip.save_frame("first_frame.jpeg")
    >>> mpy.ipython_display("first_frame.jpeg")

    """  
    
    if rd_kwargs is None:
        rd_kwargs = {}

    if "Clip" in str(clip.__class__):
        TEMP_PREFIX = "__temp__"
        if isinstance(clip,ImageClip):
            filename = TEMP_PREFIX+".png"
            kwargs = {'filename':filename, 'withmask':True}
            kwargs.update(rd_kwargs)
            clip.save_frame(**kwargs)
        elif isinstance(clip,VideoClip):
            filename = TEMP_PREFIX+".mp4"
            kwargs = {'filename':filename, 'verbose':False, 'preset':'ultrafast'}
            kwargs.update(rd_kwargs)
            clip.write_videofile(**kwargs)
        elif isinstance(clip,AudioClip):
            filename = TEMP_PREFIX+".mp3"
            kwargs = {'filename': filename, 'verbose':False}
            kwargs.update(rd_kwargs)
            clip.write_audiofile(**kwargs)
        else:
          raise ValueError("Unknown class for the clip. Cannot embed and preview.")