當前位置: 首頁>>代碼示例>>Python>>正文


Python editor.CompositeVideoClip方法代碼示例

本文整理匯總了Python中moviepy.editor.CompositeVideoClip方法的典型用法代碼示例。如果您正苦於以下問題:Python editor.CompositeVideoClip方法的具體用法?Python editor.CompositeVideoClip怎麽用?Python editor.CompositeVideoClip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在moviepy.editor的用法示例。


在下文中一共展示了editor.CompositeVideoClip方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: movie_in_movie

# 需要導入模塊: from moviepy import editor [as 別名]
# 或者: from moviepy.editor import CompositeVideoClip [as 別名]
def movie_in_movie(movie1_fname, movie2_fname, output_fname, pos=('right', 'bottom'), movie2_ratio=(1/3, 1/3),
                   margin=6, margin_color=(255, 255, 255), audio=False, fps=24, codec='libx264'):
    from moviepy import editor
    movie1 = editor.VideoFileClip(movie1_fname, audio=audio)
    w, h = movie1.size

    # THE PIANO FOOTAGE IS DOWNSIZED, HAS A WHITE MARGIN, IS
    # IN THE BOTTOM RIGHT CORNER
    movie2 = (editor.VideoFileClip(movie2_fname, audio=False).
             resize((w * movie2_ratio[0], h * movie2_ratio[1])).  # one third of the total screen
             margin(margin, color=margin_color).  # white margin
             margin(bottom=20, right=20, top=20, opacity=0).  # transparent
             set_pos(pos))

    final = editor.CompositeVideoClip([movie1, movie2])
    final.write_videofile(output_fname, fps=fps, codec=codec) 
開發者ID:pelednoam,項目名稱:mmvt,代碼行數:18,代碼來源:movies_utils.py

示例2: add_text_to_movie

# 需要導入模塊: from moviepy import editor [as 別名]
# 或者: from moviepy.editor import CompositeVideoClip [as 別名]
def add_text_to_movie(movie_fol, movie_name, out_movie_name, subs, fontsize=50, txt_color='red', font='Xolonium-Bold',
                      subs_delim=' ', bg_color=None):
    # Should install ImageMagick
    # For centos6: https://www.vultr.com/docs/install-imagemagick-on-centos-6
    # For centos7: http://helostore.com/blog/install-imagemagick-on-centos-7
    from moviepy import editor

    def annotate(clip, txt, txt_color=txt_color, fontsize=fontsize):
        """ Writes a text at the bottom of the clip. """
        # To make this code works the policy.xml should be editted
        #  identify -list policy
        # sudo gedit /etc/ImageMagick/policy.xml &
        # Put under comment the TEXT and LABEL lines
        txtclip = editor.TextClip(txt, fontsize=fontsize, color=txt_color)  # font=font
        # txtclip = txtclip.on_color((clip.w, txtclip.h + 6), color=(0, 0, 255), pos=(6, 'center'))
        cvc = editor.CompositeVideoClip([clip, txtclip.set_pos(('center', 'bottom'))])
        return cvc.set_duration(clip.duration)

    if isinstance(subs, str):
        subs = import_subs(movie_fol, subs, subs_delim)
    video = editor.VideoFileClip(op.join(movie_fol, movie_name))
    annotated_clips = [annotate(video.subclip(from_t, to_t), txt) for (from_t, to_t), txt in subs]
    final_clip = editor.concatenate_videoclips(annotated_clips)
    final_clip.write_videofile(op.join(movie_fol, out_movie_name)) 
開發者ID:pelednoam,項目名稱:mmvt,代碼行數:26,代碼來源:movies_utils.py

示例3: create_mtg_gif

# 需要導入模塊: from moviepy import editor [as 別名]
# 或者: from moviepy.editor import CompositeVideoClip [as 別名]
def create_mtg_gif(name, id, border):
    if border == 'm':   # Modern (post-8th Ed)
        card_upper_corner = (19, 38)
        gif_width = 202 - card_upper_corner[0]
        gif_height = 172 - card_upper_corner[1]
    elif border == 'c':   # Current (post-Magic 2015)
        card_upper_corner = (17, 34)
        gif_width = 204 - card_upper_corner[0]
        gif_height = 173 - card_upper_corner[1]
    else:   # Old (pre-8th Ed)
        card_upper_corner = (25, 30)
        gif_width = 196 - card_upper_corner[0]
        gif_height = 168 - card_upper_corner[1]

    mtg_card = Image.open(BytesIO(requests.get(get_mtg_image(id)).content))
    mtg_card = ImageClip(np.asarray(mtg_card)).resize((222, 310))

    get_giphy_gif(name)
    giphy_gif = (VideoFileClip('giphy_gif.mp4',
                               target_resolution=(gif_height, gif_width))
                 .set_pos(card_upper_corner)

                 )

    if giphy_gif.duration < 2:
        giphy_gif = giphy_gif.fx(loop, n=1+int(2 // giphy_gif.duration))

    mtg_gif = CompositeVideoClip([mtg_card, giphy_gif])
    mtg_gif = mtg_gif.set_start(0).set_duration(giphy_gif.duration)
    # mtg_gif.write_gif("mtg_gif.gif")
    mtg_gif.write_videofile("mtg_gif.mp4", codec='libx264',
                            bitrate=str(np.power(10, 7)), verbose=False,
                            progress_bar=False,
                            audio=False, ffmpeg_params=['-pix_fmt', 'yuv420p']) 
開發者ID:minimaxir,項目名稱:magic-the-gifening,代碼行數:36,代碼來源:utils.py

示例4: edit_video

# 需要導入模塊: from moviepy import editor [as 別名]
# 或者: from moviepy.editor import CompositeVideoClip [as 別名]
def edit_video(video):
  clips = [mp.VideoFileClip(video['file_or_url'])]

  for effect in video['effects']:
    clips.extend(get_effects(clips[0], effect))
 
  video = mp.CompositeVideoClip(clips)

  return video 
開發者ID:google,項目名稱:starthinker,代碼行數:11,代碼來源:run.py

示例5: make_crab

# 需要導入模塊: from moviepy import editor [as 別名]
# 或者: from moviepy.editor import CompositeVideoClip [as 別名]
def make_crab(self, t: str, u_id: int) -> bool:
        """Non blocking crab rave video generation from DankMemer bot

        https://github.com/DankMemer/meme-server/blob/master/endpoints/crab.py
        """
        fp = str(cog_data_path(self) / f"Verdana.ttf")
        clip = VideoFileClip(str(cog_data_path(self)) + "/template.mp4")
        # clip.volume(0.5)
        text = TextClip(t[0], fontsize=48, color="white", font=fp)
        text2 = (
            TextClip("____________________", fontsize=48, color="white", font=fp)
            .set_position(("center", 210))
            .set_duration(15.4)
        )
        text = text.set_position(("center", 200)).set_duration(15.4)
        text3 = (
            TextClip(t[1], fontsize=48, color="white", font=fp)
            .set_position(("center", 270))
            .set_duration(15.4)
        )

        video = CompositeVideoClip(
            [clip, text.crossfadein(1), text2.crossfadein(1), text3.crossfadein(1)]
        ).set_duration(15.4)
        video = video.volumex(0.1)
        video.write_videofile(
            str(cog_data_path(self)) + f"/{u_id}crabrave.mp4",
            threads=1,
            preset="superfast",
            verbose=False,
            logger=None,
            temp_audiofile=str(cog_data_path(self) / f"{u_id}crabraveaudio.mp3")
            # ffmpeg_params=["-filter:a", "volume=0.5"]
        )
        clip.close()
        video.close()
        return True 
開發者ID:TrustyJAID,項目名稱:Trusty-cogs,代碼行數:39,代碼來源:crabrave.py

示例6: add_text_example

# 需要導入模塊: from moviepy import editor [as 別名]
# 或者: from moviepy.editor import CompositeVideoClip [as 別名]
def add_text_example(movie):
    from moviepy import editor
    # A CLIP WITH A TEXT AND A BLACK SEMI-OPAQUE BACKGROUND
    txt = editor.TextClip("V. Zulkoninov - Ukulele Sonata", font='Amiri-regular',
                   color='white', fontsize=24)

    txt_col = txt.on_color(size=(movie.w + txt.w, txt.h - 10),
                           color=(0, 0, 0), pos=(6, 'center'), col_opacity=0.6)

    # THE TEXT CLIP IS ANIMATED.
    # I am *NOT* explaining the formula, understands who can/want.
    w, h = movie.size
    txt_mov = txt_col.set_pos(lambda t: (max(w / 30, int(w - 0.5 * w * t)),
                                         max(5 * h / 6, int(100 * t))))

    # FINAL ASSEMBLY
    final = editor.CompositeVideoClip([ukulele, txt_mov, piano])
    final.subclip(0, 5).write_videofile("../../ukulele.avi", fps=24, codec='libx264')


# import tempfile, os
# tempfile_fd, tempfilename = tempfile.mkstemp(suffix='.png', dir='/home/npeled/temp')
# os.close(tempfile_fd)
# temptxt_fd, temptxt = tempfile.mkstemp(suffix='.txt', dir='/home/npeled/temp')
# os.write(temptxt_fd, bytes(txt, 'UTF8'))
# os.close(temptxt_fd) 
開發者ID:pelednoam,項目名稱:mmvt,代碼行數:28,代碼來源:movies_utils.py


注:本文中的moviepy.editor.CompositeVideoClip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。