Пример #1
0
 def _make_circle(radius, color=(0, 255, 0)):
     circle_clip = ImageClip(
         circle((2 * radius, 2 * radius), (radius, radius), radius, color,
                (0, 0, 0)))
     #Make mask from it (channel 1 - green) since it's single color
     circle_mask = ImageClip(circle((2 * radius, 2 * radius),
                                    (radius, radius), radius, 1, 0),
                             ismask=True)
     #And use it as a mask
     circle_clip = circle_clip.set_mask(circle_mask)
     return circle_clip, radius
Пример #2
0
def _make_round_credits(
    round_credits: RoundCredits,
    round_index: int,
    width: int,
    height: int,
    color: str = 'white',
    stroke_color: str = 'black',
    stroke_width: str = 2,
    font: str = 'Impact-Normal',
    fontsize: int = 60,
    gap: int = 0
) -> Clip:
    texts = []
    texts += [["\n", "\n"]] * 16
    if round_credits.audio != []:
        texts += _make_credit_texts(
            str(round_credits.audio[0]),
            "ROUND {} MUSIC".format(round_index + 1))
        for audio_credit in round_credits.audio[1:]:
            texts += _make_credit_texts(str(audio_credit))
    if round_credits.video != []:
        texts += _make_credit_texts(
            str(round_credits.video[0]),
            "ROUND {} VIDEOS".format(round_index + 1))
        for video_credit in round_credits.video[1:]:
            texts += _make_credit_texts(str(video_credit))
    texts += [["\n", "\n"]] * 2

    # Make two columns for the credits
    left, right = ("".join(t) for t in zip(*texts))
    left, right = [TextClip(txt, color=color, stroke_color=stroke_color,
                            stroke_width=stroke_width, font=font,
                            fontsize=fontsize, align=al)
                   for txt, al in [(left, 'East'), (right, 'West')]]
    # Combine the columns
    cc = CompositeVideoClip([left, right.set_position((left.w + gap, 0))],
                            size=(left.w + right.w + gap, right.h),
                            bg_color=None)

    scaled = resize(cc, width=width)  # Scale to the required size

    # Transform the whole credit clip into an ImageClip
    credits_video = ImageClip(scaled.get_frame(0))
    mask = ImageClip(scaled.mask.get_frame(0), ismask=True)

    lines_per_second = height / CREDIT_DISPLAY_TIME

    def scroll(t): return ("center", -lines_per_second * t)
    credits_video = credits_video.set_position(scroll)
    credits_duration = credits_video.h / lines_per_second
    credits_video = credits_video.set_duration(credits_duration)

    return credits_video.set_mask(mask)
Пример #3
0
def credits1(creditfile,
             width,
             stretch=30,
             color='white',
             stroke_color='black',
             stroke_width=2,
             font='Impact-Normal',
             fontsize=60,
             gap=0):
    """

    Parameters
    -----------
    
    creditfile
      A text file whose content must be as follows: ::
        
        # This is a comment
        # The next line says : leave 4 blank lines
        .blank 4
        
        ..Executive Story Editor
        MARCEL DURAND
        
        ..Associate Producers
        MARTIN MARCEL
        DIDIER MARTIN
        
        ..Music Supervisor
        JEAN DIDIER
    
    width
      Total width of the credits text in pixels
      
    gap
      Horizontal gap in pixels between the jobs and the names
    
    color
      Color of the text. See ``TextClip.list('color')``
      for a list of acceptable names.

    font
      Name of the font to use. See ``TextClip.list('font')`` for
      the list of fonts you can use on your computer.

    fontsize
      Size of font to use

    stroke_color
      Color of the stroke (=contour line) of the text. If ``None``,
      there will be no stroke.

    stroke_width
      Width of the stroke, in pixels. Can be a float, like 1.5.
    
        
    Returns
    ---------
    
    image
      An ImageClip instance that looks like this and can be scrolled
      to make some credits:

          Executive Story Editor    MARCEL DURAND
             Associate Producers    MARTIN MARCEL
                                    DIDIER MARTIN
                Music Supervisor    JEAN DIDIER
              
    """

    # PARSE THE TXT FILE

    with open(creditfile) as f:
        lines = f.readlines()

    lines = filter(lambda x: not x.startswith('\n'), lines)
    texts = []
    oneline = True
    for l in lines:
        if not l.startswith('#'):
            if l.startswith('.blank'):
                for i in range(int(l.split(' ')[1])):
                    texts.append(['\n', '\n'])
            elif l.startswith('..'):
                texts.append([l[2:], ''])
                oneline = True
            else:
                if oneline:
                    texts.append(['', l])
                    oneline = False
                else:
                    texts.append(['\n', l])

    left, right = ["".join(l) for l in zip(*texts)]

    # MAKE TWO COLUMNS FOR THE CREDITS

    left, right = [
        TextClip(txt,
                 color=color,
                 stroke_color=stroke_color,
                 stroke_width=stroke_width,
                 font=font,
                 fontsize=fontsize,
                 align=al) for txt, al in [(left, 'East'), (right, 'West')]
    ]

    cc = CompositeVideoClip([left, right.set_position((left.w + gap, 0))],
                            size=(left.w + right.w + gap, right.h),
                            bg_color=None)

    # SCALE TO THE REQUIRED SIZE

    scaled = resize(cc, 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)
Пример #4
0
def credits1(
    creditfile,
    width,
    stretch=30,
    color="white",
    stroke_color="black",
    stroke_width=2,
    font="Impact-Normal",
    fontsize=60,
    gap=0,
):
    """

    Parameters
    -----------
    
    creditfile
      A string or path like object pointing to a text file
      whose content must be as follows: ::
        
        # This is a comment
        # The next line says : leave 4 blank lines
        .blank 4
        
        ..Executive Story Editor
        MARCEL DURAND
        
        ..Associate Producers
        MARTIN MARCEL
        DIDIER MARTIN
        
        ..Music Supervisor
        JEAN DIDIER
    
    width
      Total width of the credits text in pixels
      
    gap
      Horizontal gap in pixels between the jobs and the names
    
    color
      Color of the text. See ``TextClip.list('color')``
      for a list of acceptable names.

    font
      Name of the font to use. See ``TextClip.list('font')`` for
      the list of fonts you can use on your computer.

    fontsize
      Size of font to use

    stroke_color
      Color of the stroke (=contour line) of the text. If ``None``,
      there will be no stroke.

    stroke_width
      Width of the stroke, in pixels. Can be a float, like 1.5.
    
        
    Returns
    ---------
    
    image
      An ImageClip instance that looks like this and can be scrolled
      to make some credits:

          Executive Story Editor    MARCEL DURAND
             Associate Producers    MARTIN MARCEL
                                    DIDIER MARTIN
                Music Supervisor    JEAN DIDIER
              
    """

    # PARSE THE TXT FILE
    texts = []
    oneline = True

    with open(creditfile) as f:
        for l in f:
            if l.startswith(("\n", "#")):
                # exclude blank lines or comments
                continue
            elif l.startswith(".blank"):
                # ..blank n
                for i in range(int(l.split(" ")[1])):
                    texts.append(["\n", "\n"])
            elif l.startswith(".."):
                texts.append([l[2:], ""])
                oneline = True
            elif oneline:
                texts.append(["", l])
                oneline = False
            else:
                texts.append(["\n", l])

    left, right = ("".join(l) for l in zip(*texts))

    # MAKE TWO COLUMNS FOR THE CREDITS
    left, right = [
        TextClip(
            txt,
            color=color,
            stroke_color=stroke_color,
            stroke_width=stroke_width,
            font=font,
            fontsize=fontsize,
            align=al,
        )
        for txt, al in [(left, "East"), (right, "West")]
    ]

    cc = CompositeVideoClip(
        [left, right.set_position((left.w + gap, 0))],
        size=(left.w + right.w + gap, right.h),
        bg_color=None,
    )

    # SCALE TO THE REQUIRED SIZE

    scaled = resize(cc, 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)
Пример #5
0
def credits1(creditfile,
             width,
             stretch=30,
             color='white',
             stroke_color='black',
             stroke_width=2,
             font='Impact-Normal',
             fontsize=60):
    """
    
    
    Parameters
    -----------
    
    creditfile
      A text file whose content must be as follows: ::
        
        # This is a comment
        # The next line says : leave 4 blank lines
        .blank 4
        
        ..Executive Story Editor
        MARCEL DURAND
        
        ..Associate Producers
        MARTIN MARCEL
        DIDIER MARTIN
        
        ..Music Supervisor
        JEAN DIDIER
    
    width
      Total width of the credits text in pixels
      
    gap
      Gap in pixels between the jobs and the names.
    
    **txt_kw
      Additional argument passed to TextClip (font, colors, etc.)
    
    
    
        
    Returns
    ---------
    
    image
       An ImageClip instance that looks like this and can be scrolled
       to make some credits :
        
        Executive Story Editor    MARCEL DURAND
           Associate Producers    MARTIN MARCEL
                                  DIDIER MARTIN
              Music Supervisor    JEAN DIDIER
              
    """

    # PARSE THE TXT FILE

    with open(creditfile) as f:
        lines = f.readlines()

    lines = filter(lambda x: not x.startswith('\n'), lines)
    texts = []
    oneline = True
    for l in lines:
        if not l.startswith('#'):
            if l.startswith('.blank'):
                for i in range(int(l.split(' ')[1])):
                    texts.append(['\n', '\n'])
            elif l.startswith('..'):
                texts.append([l[2:], ''])
                oneline = True
            else:
                if oneline:
                    texts.append(['', l])
                    oneline = False
                else:
                    texts.append(['\n', l])

    left, right = ["".join(l) for l in zip(*texts)]

    # MAKE TWO COLUMNS FOR THE CREDITS

    left, right = [
        TextClip(txt,
                 color=color,
                 stroke_color=stroke_color,
                 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))],
                            tamano=(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)
Пример #6
0
def credits1(creditfile, width, stretch=30, color='white', stroke_color='black',
             stroke_width=2, font='Impact-Normal', fontsize=60, gap=0):
    """

    Parameters
    -----------
    
    creditfile
      A text file whose content must be as follows: ::
        
        # This is a comment
        # The next line says : leave 4 blank lines
        .blank 4
        
        ..Executive Story Editor
        MARCEL DURAND
        
        ..Associate Producers
        MARTIN MARCEL
        DIDIER MARTIN
        
        ..Music Supervisor
        JEAN DIDIER
    
    width
      Total width of the credits text in pixels
      
    gap
      Horizontal gap in pixels between the jobs and the names
    
    color
      Color of the text. See ``TextClip.list('color')``
      for a list of acceptable names.

    font
      Name of the font to use. See ``TextClip.list('font')`` for
      the list of fonts you can use on your computer.

    fontsize
      Size of font to use

    stroke_color
      Color of the stroke (=contour line) of the text. If ``None``,
      there will be no stroke.

    stroke_width
      Width of the stroke, in pixels. Can be a float, like 1.5.
    
        
    Returns
    ---------
    
    image
      An ImageClip instance that looks like this and can be scrolled
      to make some credits:

          Executive Story Editor    MARCEL DURAND
             Associate Producers    MARTIN MARCEL
                                    DIDIER MARTIN
                Music Supervisor    JEAN DIDIER
              
    """

    # PARSE THE TXT FILE
    
    with open(creditfile) as f:
        lines = f.readlines()
    
    lines = filter(lambda x: not x.startswith('\n'), lines)
    texts = []
    oneline = True
    for l in lines:
        if not l.startswith('#'):
            if l.startswith('.blank'):
                for i in range(int(l.split(' ')[1])):
                    texts.append(['\n', '\n'])
            elif l.startswith('..'):
                texts.append([l[2:], ''])
                oneline = True
            else:
                if oneline:
                    texts.append(['', l])
                    oneline = False
                else:
                    texts.append(['\n', l])
               
    left, right = ["".join(l) for l in zip(*texts)]
    
    # MAKE TWO COLUMNS FOR THE CREDITS
    
    left, right = [TextClip(txt, color=color, stroke_color=stroke_color,
                            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),
                            bg_color=None)
    
    # SCALE TO THE REQUIRED SIZE
    
    scaled = resize(cc, 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)
Пример #7
0
def credits1(creditfile,width,stretch=30,color='white',
                 stroke_color='black', stroke_width=2,
                 font='Impact-Normal',fontsize=60):
    """
    
    
    Parameters
    -----------
    
    creditfile
      A text file whose content must be as follows: ::
        
        # This is a comment
        # The next line says : leave 4 blank lines
        .blank 4
        
        ..Executive Story Editor
        MARCEL DURAND
        
        ..Associate Producers
        MARTIN MARCEL
        DIDIER MARTIN
        
        ..Music Supervisor
        JEAN DIDIER
    
    width
      Total width of the credits text in pixels
      
    gap
      Gap in pixels between the jobs and the names.
    
    **txt_kw
      Additional argument passed to TextClip (font, colors, etc.)
    
    
    
        
    Returns
    ---------
    
    image
       An ImageClip instance that looks like this and can be scrolled
       to make some credits :
        
        Executive Story Editor    MARCEL DURAND
           Associate Producers    MARTIN MARCEL
                                  DIDIER MARTIN
              Music Supervisor    JEAN DIDIER
              
    """
    
    
    # PARSE THE TXT FILE
    
    with open(creditfile) as f:
        lines = f.readlines()
    
    lines = filter(lambda x:not x.startswith('\n'),lines) 
    texts = []
    oneline=True
    for l in  lines:
        if not l.startswith('#'):
            if l.startswith('.blank'):
                for i in range(int(l.split(' ')[1])):
                    texts.append(['\n','\n'])
            elif  l.startswith('..'):
                texts.append([l[2:],''])
                oneline=True
            else:
                if oneline:
                    texts.append(['',l])
                    oneline=False
                else:
                    texts.append(['\n',l])
               
    left,right = [ "".join(l) for l in zip(*texts)]
    
    # MAKE TWO COLUMNS FOR THE CREDITS
    
    left,right =  [TextClip(txt,color=color,stroke_color=stroke_color,
                                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)
Пример #8
0
def credits1(creditfile,width,stretch=30,color='white',
                 stroke_color='black', stroke_width=2,
                 font='Impact-Normal',fontsize=60):
    """
    
    The first credits I imagined. They take as argument a file like: ::
        
        # This is a comment
        # The next line says : leave 4 blank lines
        .blank 4
        
        ..Executive Story Editor
        MARCEL DURAND
        
        ..Associate Producers
        MARTIN MARCEL
        DIDIER MARTIN
        
        ..Music Supervisor
        JEAN DIDIER
        
    And produce an ImageClip that looks like :
    
        Executive Story Editor    MARCEL DURAND
           Associate Producers    MARTIN MARCEL
                                  DIDIER MARTIN
              Music Supervisor    JEAN DIDIER
    
    :param width: total width of the credits text
    :param stretch: stretch in pixels between the jobs and the names.
    
    The other keywords are passed to the ``TextClip``s
    """
    
    
    # PARSE THE TXT FILE
    
    with open(creditfile) as f:
        lines = f.readlines()
    
    lines = filter(lambda x:not x.startswith('\n'),lines) 
    texts = []
    oneline=True
    for l in  lines:
        if not l.startswith('#'):
            if l.startswith('.blank'):
                for i in range(int(l.split(' ')[1])):
                    texts.append(['\n','\n'])
            elif  l.startswith('..'):
                texts.append([l[2:],''])
                oneline=True
            else:
                if oneline:
                    texts.append(['',l])
                    oneline=False
                else:
                    texts.append(['\n',l])
               
    left,right = [ "".join(l) for l in zip(*texts)]
    
    # MAKE TWO COLUMNS FOR THE CREDITS
    
    left,right =  [TextClip(txt,color=color,stroke_color=stroke_color,
                                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+stretch,0))],
                             size = (left.w+right.w+stretch,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)