Пример #1
0
def test_margin():
    clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
    clip1 = margin(clip)  #does the default values change anything?
    clip1.write_videofile(os.path.join(TMP_DIR, "margin1.webm"))

    clip2 = margin(clip, mar=100) # all margins are 100px
    clip2.write_videofile(os.path.join(TMP_DIR, "margin2.webm"))

    clip3 = margin(clip, mar=100, color=(255,0,0))  #red margin
    clip3.write_videofile(os.path.join(TMP_DIR, "margin3.webm"))
Пример #2
0
def test_margin():
    clip = VideoFileClip("media/big_buck_bunny_432_433.webm")
    clip1 = margin(clip)  #does the default values change anything?
    clip1.write_videofile(os.path.join(TMP_DIR, "margin1.webm"))

    clip2 = margin(clip, mar=100)  # all margins are 100px
    clip2.write_videofile(os.path.join(TMP_DIR, "margin2.webm"))

    clip3 = margin(clip, mar=100, color=(255, 0, 0))  #red margin
    clip3.write_videofile(os.path.join(TMP_DIR, "margin3.webm"))
Пример #3
0
def test_margin():
    clip = get_test_video()
    clip1 = margin(clip)  # does the default values change anything?
    clip1.write_videofile(os.path.join(TMP_DIR, "margin1.webm"))

    clip2 = margin(clip, mar=100)  # all margins are 100px
    clip2.write_videofile(os.path.join(TMP_DIR, "margin2.webm"))

    clip3 = margin(clip, mar=100, color=(255, 0, 0))  # red margin
    clip3.write_videofile(os.path.join(TMP_DIR, "margin3.webm"))
    close_all_clips(locals())
Пример #4
0
def test_margin():
    clip = get_test_video()
    clip1 = margin(clip)  # does the default values change anything?
    clip1.write_videofile(os.path.join(TMP_DIR, "margin1.webm"))

    clip2 = margin(clip, mar=100)  # all margins are 100px
    clip2.write_videofile(os.path.join(TMP_DIR, "margin2.webm"))

    clip3 = margin(clip, mar=100, color=(255, 0, 0))  # red margin
    clip3.write_videofile(os.path.join(TMP_DIR, "margin3.webm"))
    close_all_clips(locals())
Пример #5
0
def test_margin():
    clip = BitmapClip([["RRR", "RRR"], ["RRB", "RRB"]], fps=1)

    # Make sure that the default values leave clip unchanged
    clip1 = margin(clip)
    assert clip == clip1

    # 1 pixel black margin
    clip2 = margin(clip, mar=1)
    target = BitmapClip(
        [
            [
                "OOOOO",
                "ORRRO",
                "ORRRO",
                "OOOOO",
            ],
            [
                "OOOOO",
                "ORRBO",
                "ORRBO",
                "OOOOO",
            ],
        ],
        fps=1,
    )
    assert target == clip2

    # 1 pixel green margin
    clip3 = margin(clip, mar=1, color=(0, 255, 0))
    target = BitmapClip(
        [
            [
                "GGGGG",
                "GRRRG",
                "GRRRG",
                "GGGGG",
            ],
            [
                "GGGGG",
                "GRRBG",
                "GRRBG",
                "GGGGG",
            ],
        ],
        fps=1,
    )
    assert target == clip3
Пример #6
0
def add_subtitle(video_path, default_subtitle_path, translated_subtitle_path):
    if default_subtitle_path is None:
        return
    default_subtitle = margin(clip=SubtitlesClip(
        default_subtitle_path, default_subtitle_generator()).set_position(
            ('center', 'bottom')),
                              bottom=80,
                              opacity=0)
    translated_subtitle = margin(clip=SubtitlesClip(
        translated_subtitle_path,
        translation_subtitle_generator()).set_position(('center', 'bottom')),
                                 bottom=40,
                                 opacity=0)
    video = VideoFileClip(video_path, audio=True)
    composed_video = CompositeVideoClip(
        [video, default_subtitle, translated_subtitle])
    output_filename = replace_extension(
        add_prefix_to_filename(video_path, '[WITH-SUBTITLE] '), '.mp4')
    composed_video.write_videofile(output_filename, threads=2, fps=video.fps)
Пример #7
0
def add_subtitle(video_path, subtitle_path, filename=None):
    generator: Callable[[Any], TextClip] = lambda txt: TextClip(txt,
                                                                font='assets/font/GothamMedium.ttf',
                                                                fontsize=45, color='white',
                                                                bg_color='#00000066')
    subtitle = margin(clip=SubtitlesClip(subtitle_path, generator).set_position(('center', 'bottom')), bottom=35, opacity=0)
    video = VideoFileClip(video_path, audio=True)
    composed_video = CompositeVideoClip([video, subtitle])
    output_filename = filename or replace_extension(add_prefix_to_filename(video_path, '[WITH-SUBTITLE] '), '.mp4')
    composed_video.write_videofile(output_filename,
                                   threads=2,
                                   fps=video.fps)
Пример #8
0
 def clip(self, frames_and_durations):
     if self.dynamic:
         clip = super().clip(frames_and_durations)
     else:
         clip = ImageClip(imageio.imread(
             next((output_path / self.dirname).glob('*.png'))),
                          duration=sum(frames_and_durations.values()))
     if self.margin:
         params = self.margin.copy()
         params['mar'] = params.pop('margin')
         params['color'] = white
         clip = margin(clip, **params)
     return clip
Пример #9
0
def add_subtitle(video_path, subtitle_path):
    generator: Callable[
        [Any],
        TextClip] = lambda txt: TextClip(txt,
                                         font='./fonts/GothamMedium.ttf',
                                         fontsize=45,
                                         color='white',
                                         bg_color='#00000066')
    subtitle = margin(clip=SubtitlesClip(subtitle_path,
                                         generator).set_position(
                                             ('center', 'bottom')),
                      bottom=35,
                      opacity=0)
    video = VideoFileClip(video_path, audio=True)
    composed_video = CompositeVideoClip([video, subtitle])
    composed_video.write_videofile("out.mp4", threads=4, fps=video.fps)