Moviepy: TextClip positioning does not work

Created on 15 Dec 2018  路  3Comments  路  Source: Zulko/moviepy

I have written the following function to add a timestamp to a video:

def stamp_clip(clip, start_t=0):
    clips = []
    for x in range(int(clip.duration)):
        txtclip = TextClip(str(timedelta(seconds=x + start_t)),
                           font='Arial-Black', fontsize=50, stroke_color='black', stroke_width=2, color='white')

        txtclip.duration = 1
        txtclip.set_position((100, 200))
        sub = clip.subclip(x, x+1)
        # clip.add_mask()
        comp = CompositeVideoClip([sub, txtclip])
        comp.duration = 1
        clips.append(comp)

    return concatenate_videoclips(clips)

Expected Behavior

A time stamp will appear at (100,200).

Actual Behavior

The timestamp does not move.

I have tried many overloads of this function "center","right", 0.2,0.5 etc. and nothing worked

Steps to Reproduce the Problem

The function above.

Specifications

  • Python Version: 2.7.15
  • Moviepy Version: 0.2.3.5
  • Platform Name: Windows
  • Platform Version: 10
text

Most helpful comment

Update:

Changing the line:

  txtclip = TextClip(str(timedelta(seconds=x + start_t)),
                           font='Arial-Black', fontsize=50, stroke_color='black', stroke_width=2, color='white')

To the following:

  txtclip = TextClip(str(timedelta(seconds=x + start_t)),
                           font=font, fontsize=font_size, color='white', stroke_color='black', stroke_width=1) \
                           .set_duration(1) \
                           .set_pos(('left', 'bottom'))

and, of course, removing redundant rows, solves the issue.

I really have no idea what caused the issue, but the solution might give some hints for where the bug is.

Cheers

All 3 comments

Update:

Changing the line:

  txtclip = TextClip(str(timedelta(seconds=x + start_t)),
                           font='Arial-Black', fontsize=50, stroke_color='black', stroke_width=2, color='white')

To the following:

  txtclip = TextClip(str(timedelta(seconds=x + start_t)),
                           font=font, fontsize=font_size, color='white', stroke_color='black', stroke_width=1) \
                           .set_duration(1) \
                           .set_pos(('left', 'bottom'))

and, of course, removing redundant rows, solves the issue.

I really have no idea what caused the issue, but the solution might give some hints for where the bug is.

Cheers

All functions that have an @outplace decorator return a new modified clip, so you need to store their return value. See: https://zulko.github.io/moviepy/getting_started/effects.html for some documentation on this behavior. You're now storing a reference to the final modified clip in txtclip, which is also fine.

Sorry for the confusion, I understand that "with_duration", "with_position" would have been better names than "set_duration", "set_pos", to indicate that the transformations are not in-place, but hey I was young at the time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keikoro picture keikoro  路  4Comments

Deng-deng-deng-deng picture Deng-deng-deng-deng  路  3Comments

bobozar picture bobozar  路  4Comments

LaoYuanPython picture LaoYuanPython  路  3Comments

cquintini picture cquintini  路  4Comments