0

WHAT I'M TRYING TO DO:

Concatenate a few dozen videos from a directory to form one large video. The videos don't have the same size or aspect ratio, so I'd like for the videos to fit (without stretching) in a 1080x1920 frame and just have the background be black.

MY CODE:

I'm getting the following error:

Exception has occurred: ValueError
could not broadcast input array from shape (1080,1920,3) into shape (1080,1920)

when I run the following code (error comes at the commented line):

from moviepy.editor import *
from os import walk, path

INTRO_VIDEO_PATH = r'C:\Users\jack_L\Downloads\INTRO_VIDEO\INTRO.mp4'
VIDEOS_PATH = r'C:\Users\jack_l\Downloads\DOWNLOADS\folder'

myVideos = next(walk(VIDEOS_PATH), (None, None, []))[2]
finalVideo = []
finalVideo.append(VideoFileClip(INTRO_VIDEO_PATH))

for counter in range(len(myVideos)):
    myExtension = path.splitext(myVideos[counter])[1]
    if myExtension != '.mp4':
        continue
    myVideo = VideoFileClip(VIDEOS_PATH+'\\'+myVideos[counter])
    finalVideo.append(myVideo)

theFinalVideo = concatenate_videoclips(finalVideo, method='compose', bg_color='black')

theFinalVideo.write_videofile(r'C:\Users\jack_l\Downloads\final.mp4') #error at this line

WHAT I KNOW/HAVE BEEN TOLD:

  • "Each frame is a RGB frame, which has 3 channels, but you are trying to fit it into a Greayscale single channel frame." - Sembei Norimaki. Unfortunately, I'm unsure of how I could fix this.

FULL TRACEBACK:

Traceback (most recent call last):
  File "c:\Users\jack_l\Documents\MEME_MAKER\swagGamingMemes.py", line 20, in <module>
    theFinalVideo.write_videofile(r'C:\Users\jack_l\Downloads\final.mp4')
  File "<decorator-gen-55>", line 2, in write_videofile
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-54>", line 2, in write_videofile
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-53>", line 2, in write_videofile
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\video\VideoClip.py", line 300, in write_videofile
    ffmpeg_write_video(self, filename, fps, codec,
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\video\io\ffmpeg_writer.py", line 220, in ffmpeg_write_video
    for t,frame in clip.iter_frames(logger=logger, with_times=True,
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\Clip.py", line 472, in iter_frames
    frame = self.get_frame(t)
  File "<decorator-gen-11>", line 2, in get_frame
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\video\compositing\CompositeVideoClip.py", line 111, in make_frame
    f = c.blit_on(f, t)
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\video\VideoClip.py", line 564, in blit_on
    return blit(img, picture, pos, mask=mask, ismask=self.ismask)
  File "C:\Users\jack_l\AppData\Roaming\Python\Python39\site-packages\moviepy\video\tools\drawing.py", line 41, in blit
    new_im2[yp1:yp2, xp1:xp2] = blitted
ValueError: could not broadcast input array from shape (1080,1920,3) into shape (1080,1920)
  • Just to inform, an array of (1080,1920,3) is not equal to (1080,1920). The first one consists data of 1080*1920*3 while the latter is only 1080*1920 –  Jun 15 '22 at 14:43
  • @KevinChoonLiangYew Yes but im unsure of where the the 3 is coming from. Why is it doing 1080x1920x3? – THEMOUNTAINSANDTHESKIES Jun 15 '22 at 15:31

1 Answers1

0

SOLUTION:

Removed the bg_color='black' attribute from the theFinalVideo = concatenate_videoclips(finalVideo, method='compose', bg_color='black') line and it worked.