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)
A time stamp will appear at (100,200).
The timestamp does not move.
I have tried many overloads of this function "center","right", 0.2,0.5 etc. and nothing worked
The function above.
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.
Most helpful comment
Update:
Changing the line:
To the following:
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