Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError in write_videofile after concatenate_videoclips #2247

Closed
FedeSpu opened this issue Nov 21, 2024 · 2 comments
Closed

ValueError in write_videofile after concatenate_videoclips #2247

FedeSpu opened this issue Nov 21, 2024 · 2 comments
Labels
bug Issues that report (apparent) bugs. v2.x Issues based on MoviePy version 2.0 and upwards video Related to VideoClip and related classes, or handling of video in general.

Comments

@FedeSpu
Copy link

FedeSpu commented Nov 21, 2024

Expected Behavior

Export the video correctly after using concatenate_videoclips and write_videofile

Actual Behavior

ValueError, and the video is not produced

Steps to Reproduce the Problem

from moviepy import *
title_clip = TextClip(text=title_frame_txt, font="Arial", font_size=34, color='white', bg_color='black', size=(width, height), duration=1.5, text_align='center')
video = CompositeVideoClip(clip_list, use_bgclip=True)

final_video = concatenate_videoclips([title_clip, video], method='chain')
final_video.write_videofile(output_file, fps=out_fps, codec='libx264')

Solution

The error is in "ffmpeg_writer.py" file in line frame = np.dstack([frame, mask]). The problem is that the mask has shape [1,1]. This is due to concatenate_videoclips, that in line mask = clip.mask or ColorClip([1, 1], color=1, is_mask=True) produces mask of shape [1,1].
The solution that I've found is to replace this line with mask = clip.mask or ColorClip(clip.size, color=1, is_mask=True)

Specifications

  • Python Version: 3.12.2
  • MoviePy Version: 2.0.0
  • Platform Name: Ubuntu
  • Platform Version: 22.04
@FedeSpu FedeSpu added the bug Issues that report (apparent) bugs. label Nov 21, 2024
@Implosiv3
Copy link
Contributor

Implosiv3 commented Nov 23, 2024

I faced the same error and this solves it. Apparently, there is no reason to be [1, 1] shape in that situacion as it is fulfilling masks for clips without them when compositing. As FedeSpu says 👇

File: moviepy\video\compositing\CompositeVideoClip.py
Line 292, replace with this: mask = clip.mask or ColorClip(clip.size, color=1, is_mask=True)

Implosiv3 added a commit to Implosiv3/moviepy that referenced this issue Nov 27, 2024
Fixes the issue when concatenating videoclips as mask is being considered as [1, 1] so the mask shape is different from the other videos and fails.

I think [1, 1] could be a default mask to avoid divisions by zero or something similar, but here it does not make sense.

Issue here: Zulko#2247
@keikoro keikoro added video Related to VideoClip and related classes, or handling of video in general. v2.x Issues based on MoviePy version 2.0 and upwards labels Dec 8, 2024
@OsaAjani
Copy link
Collaborator

Fixed with #2307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs. v2.x Issues based on MoviePy version 2.0 and upwards video Related to VideoClip and related classes, or handling of video in general.
Projects
None yet
Development

No branches or pull requests

4 participants