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

Is it even worth updating to the new version? #2265

Open
aaa3334 opened this issue Nov 29, 2024 · 5 comments
Open

Is it even worth updating to the new version? #2265

aaa3334 opened this issue Nov 29, 2024 · 5 comments
Labels
question Questions regarding functionality, usage text Issues dealing with TextClip, SubtitlesClip, or handling of text in general. v2.x Issues based on MoviePy version 2.0 and upwards

Comments

@aaa3334
Copy link
Contributor

aaa3334 commented Nov 29, 2024

I didn't use version control so this update hit me kind of hard.

But I thought I may as well update to the new version - big mistake. I have so far spent maybe 10h trying to update and am still not there. While I have got rid of all the errors now, the actual output is still incorrect and is not the same as it was before (some of the output is weirdly boxed, sizes are all different etc.)

I am wondering what the actual benefits of updating are, or if I should just cut my losses and go back to the old version? I thought it would take 30 min but there are so many breaking changes it has taken many hours over a few days (right now I have just spent 5h in a row so am quite frustrated).

What are peoples opinions on this?

@aaa3334 aaa3334 added the question Questions regarding functionality, usage label Nov 29, 2024
@Implosiv3
Copy link

Implosiv3 commented Nov 29, 2024

I'm obtaining the previous results with less code with the new version. I had to do some tricks in the previous versions to solve issues that now seems to be fixed. Is it happening to you when concatenating, when compositing?

Can you please provide some specific code which is generating those 'weirdly boxed' elements, and maybe some screenshots?

We will try to solve the errors, if existing, to improve the library, so any specific feedback could let us deep into the code to solve them. Thank you very much.

@Manamama
Copy link

Manamama commented Dec 1, 2024

It has hit me hard too. Even memoization and "simple" media chunking (only audio) causes new (!) errors harking back to 2021 ones, see here: #1530

@Manamama
Copy link

Manamama commented Dec 1, 2024

Update, after much head scratching and RTFM (with Perplexity reading some source MoviePy code), I seem to have fixed my problem, q.v. (In short, audio files cannot be memoized).

@aaa3334
Copy link
Contributor Author

aaa3334 commented Dec 1, 2024

I'm obtaining the previous results with less code with the new version. I had to do some tricks in the previous versions to solve issues that now seems to be fixed. Is it happening to you when concatenating, when compositing?

Can you please provide some specific code which is generating those 'weirdly boxed' elements, and maybe some screenshots?

We will try to solve the errors, if existing, to improve the library, so any specific feedback could let us deep into the code to solve them. Thank you very much.

Thanks!

So one part is definitely the bounding boxes - eg I am using this to add a watermark (this is the new edited code - I could just use a few lines before but the bounding box stopped it from showing properly). Before I could just simply rotate the text and it would be fine


def create_watermark(video_data, watermark, video_width, video_height, watermark_config: WatermarkConfig = WatermarkConfig()):
    # Split watermark into lines if more than 2 words
    words = watermark.split()
    if len(words) > 2:
        # Create lines with max 2 words each
        lines = []
        for i in range(0, len(words), 2):
            line = ' '.join(words[i:i+2])
            lines.append(line)
        watermark_text = '\n'.join(lines)
    else:
        watermark_text = watermark
    
    font = get_font_path(watermark_config.font_family)
    
    watermark_clip = TextClip(
        text=watermark_text,
        font_size=int(watermark_config.font_size),
        color=watermark_config.colour,
        font=font,
        method='label',
        text_align='center',
        # Add padding to account for rotation
        size=(None, None),  # Let MoviePy calculate the initial size
        bg_color=None,
        transparent=True
    )
    
       # Get original dimensions
    orig_width, orig_height = watermark_clip.size
    
    
    # Calculate the size needed for rotation (using trigonometry)
    rotation_angle = 20  # degrees
    angle_rad = math.radians(abs(rotation_angle))
    rotated_width = int(abs(orig_width * math.cos(angle_rad)) + abs(orig_height * math.sin(angle_rad)))
    rotated_height = int(abs(orig_width * math.sin(angle_rad)) + abs(orig_height * math.cos(angle_rad)))
    
    # Create a larger clip with padding
    padded_clip = TextClip(
        text=watermark_text,
        font_size=int(watermark_config.font_size),
        color=watermark_config.colour,
        font=font,
        method='label',
        text_align='center',
        size=(rotated_width, rotated_height),
        bg_color=None,
        transparent=True
    ).with_position(('center', 'center'))
    
    # Calculate position based on config percentages
    x_pos = int(video_width * watermark_config.horizontal_position)
    y_pos = int(video_height * watermark_config.vertical_position)
    
    # Set duration, rotate, and set opacity
    watermark_clip = (padded_clip
        .with_position((x_pos, y_pos))
        .with_duration(video_data.duration)
        .rotated(20)
        .with_opacity(watermark_config.transparency))
    
    return [watermark_clip]

(Code changed for the new version but without the padding - results in the text being cut off when rotated)


def create_watermark(video_data, watermark, video_width, video_height, watermark_config: WatermarkConfig = WatermarkConfig()):
    # Split watermark into lines if more than 2 words
    words = watermark.split()
    if len(words) > 2:
        # Create lines with max 2 words each
        lines = []
        for i in range(0, len(words), 2):
            line = ' '.join(words[i:i+2])
            lines.append(line)
        watermark_text = '\n'.join(lines)
    else:
        watermark_text = watermark
    
    font = get_font_path(watermark_config.font_family)
    
    watermark_clip = TextClip(
        text=watermark_text,
        font_size=int(watermark_config.font_size),
        color=watermark_config.colour,
        font=font,
        method='label',
        text_align='center'
    )
    
    # Calculate position based on config percentages
    x_pos = int(video_width * watermark_config.horizontal_position)
    y_pos = int(video_height * watermark_config.vertical_position)
    
    # Set duration to match video length and rotate by 40 degrees
    watermark_clip = (watermark_clip
        .with_position((x_pos, y_pos))
        .with_duration(video_data.duration)  # Set to full video duration
        .rotated(20)
        .with_opacity(watermark_config.transparency))
    
    return [watermark_clip]

)

Another is eg the font - I am using label and I have issues with the text alignment now so letters like g y or p etc. are getting cut off at the bottom and some of the words are jumping up and down (the code for that one is quite long - I am looking at it but I assume it is a change in the default alignment in label and a bounding box issue).

Those are the main ones right now. I am sure I can fix most, but I am guessing the bounding box might also cause issues for other people too

@rockfarmor
Copy link

I'm obtaining the previous results with less code with the new version. I had to do some tricks in the previous versions to solve issues that now seems to be fixed. Is it happening to you when concatenating, when compositing?
Can you please provide some specific code which is generating those 'weirdly boxed' elements, and maybe some screenshots?
We will try to solve the errors, if existing, to improve the library, so any specific feedback could let us deep into the code to solve them. Thank you very much.

Thanks!

So one part is definitely the bounding boxes - eg I am using this to add a watermark (this is the new edited code - I could just use a few lines before but the bounding box stopped it from showing properly). Before I could just simply rotate the text and it would be fine


def create_watermark(video_data, watermark, video_width, video_height, watermark_config: WatermarkConfig = WatermarkConfig()):
    # Split watermark into lines if more than 2 words
    words = watermark.split()
    if len(words) > 2:
        # Create lines with max 2 words each
        lines = []
        for i in range(0, len(words), 2):
            line = ' '.join(words[i:i+2])
            lines.append(line)
        watermark_text = '\n'.join(lines)
    else:
        watermark_text = watermark
    
    font = get_font_path(watermark_config.font_family)
    
    watermark_clip = TextClip(
        text=watermark_text,
        font_size=int(watermark_config.font_size),
        color=watermark_config.colour,
        font=font,
        method='label',
        text_align='center',
        # Add padding to account for rotation
        size=(None, None),  # Let MoviePy calculate the initial size
        bg_color=None,
        transparent=True
    )
    
       # Get original dimensions
    orig_width, orig_height = watermark_clip.size
    
    
    # Calculate the size needed for rotation (using trigonometry)
    rotation_angle = 20  # degrees
    angle_rad = math.radians(abs(rotation_angle))
    rotated_width = int(abs(orig_width * math.cos(angle_rad)) + abs(orig_height * math.sin(angle_rad)))
    rotated_height = int(abs(orig_width * math.sin(angle_rad)) + abs(orig_height * math.cos(angle_rad)))
    
    # Create a larger clip with padding
    padded_clip = TextClip(
        text=watermark_text,
        font_size=int(watermark_config.font_size),
        color=watermark_config.colour,
        font=font,
        method='label',
        text_align='center',
        size=(rotated_width, rotated_height),
        bg_color=None,
        transparent=True
    ).with_position(('center', 'center'))
    
    # Calculate position based on config percentages
    x_pos = int(video_width * watermark_config.horizontal_position)
    y_pos = int(video_height * watermark_config.vertical_position)
    
    # Set duration, rotate, and set opacity
    watermark_clip = (padded_clip
        .with_position((x_pos, y_pos))
        .with_duration(video_data.duration)
        .rotated(20)
        .with_opacity(watermark_config.transparency))
    
    return [watermark_clip]

(Code changed for the new version but without the padding - results in the text being cut off when rotated)


def create_watermark(video_data, watermark, video_width, video_height, watermark_config: WatermarkConfig = WatermarkConfig()):
    # Split watermark into lines if more than 2 words
    words = watermark.split()
    if len(words) > 2:
        # Create lines with max 2 words each
        lines = []
        for i in range(0, len(words), 2):
            line = ' '.join(words[i:i+2])
            lines.append(line)
        watermark_text = '\n'.join(lines)
    else:
        watermark_text = watermark
    
    font = get_font_path(watermark_config.font_family)
    
    watermark_clip = TextClip(
        text=watermark_text,
        font_size=int(watermark_config.font_size),
        color=watermark_config.colour,
        font=font,
        method='label',
        text_align='center'
    )
    
    # Calculate position based on config percentages
    x_pos = int(video_width * watermark_config.horizontal_position)
    y_pos = int(video_height * watermark_config.vertical_position)
    
    # Set duration to match video length and rotate by 40 degrees
    watermark_clip = (watermark_clip
        .with_position((x_pos, y_pos))
        .with_duration(video_data.duration)  # Set to full video duration
        .rotated(20)
        .with_opacity(watermark_config.transparency))
    
    return [watermark_clip]

)

Another is eg the font - I am using label and I have issues with the text alignment now so letters like g y or p etc. are getting cut off at the bottom and some of the words are jumping up and down (the code for that one is quite long - I am looking at it but I assume it is a change in the default alignment in label and a bounding box issue).

Those are the main ones right now. I am sure I can fix most, but I am guessing the bounding box might also cause issues for other people too

I also have issues with TextBoxes. I have created a bug here: #2268

@keikoro keikoro added text Issues dealing with TextClip, SubtitlesClip, or handling of text in general. v2.x Issues based on MoviePy version 2.0 and upwards labels Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions regarding functionality, usage text Issues dealing with TextClip, SubtitlesClip, or handling of text in general. v2.x Issues based on MoviePy version 2.0 and upwards
Projects
None yet
Development

No branches or pull requests

5 participants