I am trying to composite a '.mp4' video and 'text' using VideoFileClip and TextClip respectively by appending them to a variable 'clip_list'.
If I try to print 'clip_list' on console it logs:
[<moviepy.video.io.VideoFileClip.VideoFileClip object at 0x7f3d1da98208>,
<moviepy.video.VideoClip.TextClip object at 0x7f3d20699a20>]
Now using CompositeVideoClip on clip_list gives me following error.
Traceback (most recent call last): File "test.py", line 155, in <module> scene_composition = CompositeVideoClip(clip_list).set_duration(scenes[i].get('duration')).on_color(size=screensize, color=(0, 0, 0)) File "/usr/local/lib/python3.7/site-packages/moviepy/video/VideoClip.py", line 616, in on_color colorclip = ColorClip(size, color=color) File "/usr/local/lib/python3.7/site-packages/moviepy/video/VideoClip.py", line 1014, in __init__ ImageClip.__init__(self, np.tile(color, w * h).reshape(shape), File "<__array_function__ internals>", line 6, in tile File "/usr/local/lib/python3.7/site-packages/numpy/lib/shape_base.py", line 1258, in tile return c.reshape(shape_out) TypeError: 'float' object cannot be interpreted as an integer
Any help here? I am using:
Python 3.7.3
moviepy==1.0.2
numpy==1.18.3
Would you mind posting your code that causes this? Preferably the shortest/simplest version that still demonstrates this bug.
However, going off of your traceback, the error is not in the call to CompositeVideoClip, it is in .on_color(). I think that your screensize variable contains floats, not ints.
And as a suggestion, use the size and bg_color parameters to CompositeVideoClip instead of .on_color(). It should result in the same thing, but I think that that would make cleaner code.
from moviepy.editor import VideoFileClip, clips_array, concatenate_videoclips, AudioFileClip, ImageClip, CompositeVideoClip, TextClip
from pprint import pprint
scene_bg_color = '#ffffff'
screensize = (480, 318)
total_duration = 15
# Converts percentage into float value
def p2f(x):
return float(x.strip('%'))/100
# Text Clip
print('Video Size = '+str(screensize))
clip_list = []
layer_path = './uploads'
font_size = int('103px'.strip('px'))
font_family = "Arial"
color = "#F50057"
print('Creating video from a Text ... 1 of size '+ str(font_size) + ' px from fontFamily = ' + font_family + ' and color = ' + color)
clip_temp = TextClip('1', font=font_family, color=color, fontsize=int(font_size))
duration_t = 11.2
print('Show text for '+str(duration_t)+' secs ... at position ')
clip_temp = clip_temp.set_duration(duration_t)
clip_temp = clip_temp.set_position((p2f("16.975624818903114%"), p2f("16.975624818903114%")))
clip_list.append(clip_temp)
# Video Clip
duration = 9
print('Create Movie Clip in seconds: ')
print(duration)
target_resolution = (480, 318)
print('vid resolution = ' + str(target_resolution))
resize_algorithm = "bilinear" # default: bicubic // Todo: benchmark bilinear fast
clip_temp = VideoFileClip(layer_path+'/test.mp4', target_resolution=target_resolution, resize_algorithm=resize_algorithm, fps_source="fps")
clip_temp = clip_temp.set_position((p2f('0%'), p2f(('0%'))))
clip_temp = clip_temp.set_duration(duration)
clip_list.append(clip_temp)
# Composite Clip
print('total clip list size '+ str(len(clip_list)))
print('total scene duration '+ str(total_duration))
pprint(clip_list)
scene_composition = CompositeVideoClip(clip_list, size=screensize, bg_color=scene_bg_color)
scene_composition = scene_composition.set_duration(total_duration)
scene_composition.write_videofile('uploads/output.mp4', fps=24)
I upgraded my Moviepy to 2.0.0
I am running it on OS: Alpine
It's not working on Mac OS also
Please help I spent lot of time in trying to figure it out. I think I am making stupid mistake somewhere.
Because when I use TextClip, VideoFileClip, CompositeVideoClip without much options it's working just fine.
Thanks for that. I'm going through your file now. I'm able to get through all of it until the last line, where it crashes whilst writing to a file. Is that where yours crashes? Are you still getting the same error as the one you reported in your first post?
I've fixed the bug that I was getting: you need to set scene_bg_color to (255, 255, 255), not "#ffffff". MoviePy only accepts colours in the format I just described.
If that doesn't solve your problem, then send the full traceback for the crash that you're getting.
Very well. That just fixed my problem 馃槂
Thanks 馃憤