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

subclip not behaving properly due to decorator #2232

Open
jcoelho-aurascape opened this issue Oct 25, 2024 · 0 comments
Open

subclip not behaving properly due to decorator #2232

jcoelho-aurascape opened this issue Oct 25, 2024 · 0 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@jcoelho-aurascape
Copy link

Due to the convert_to_seconds decorator in subclip, it is ignoring the t_end argument. I am using python 3.11.9

Expected Behavior

Subclip should be 60 seconds long

Actual Behavior

Subclip is full video

Steps to Reproduce the Problem

Try to subclip a video clip and check the duration

from moviepy.editor import VideoFileClip
video_file = "video.mp4"
clip = VideoFileClip(video_file)
print(clip.duration)
1014.52

subclip = clip.subclip(0, 60)
print(subclip.duration)
1014.52

Clip.py

    @convert_to_seconds(['t_start', 't_end'])
    @apply_to_mask
    @apply_to_audio
    def subclip(self, t_start=0, t_end=None):
        ...
        # Add prints
        print("t_start:", t_start)
        print("t_end:", t_end)

decorators.py

def preprocess_args(fun,varnames):
    """ Applies fun to variables in varnames before launching the function """
    
    def wrapper(f, *a, **kw):
        if hasattr(f, "func_code"):
            func_code = f.func_code # Python 2
        else:
            func_code = f.__code__ # Python 3
            
        names = func_code.co_varnames
        new_a = [fun(arg) if (name in varnames) else arg
                 for (arg, name) in zip(a, names)]
        new_kw = {k: fun(v) if k in varnames else v
                 for (k,v) in kw.items()}
        # Add prints
        print("a, names:", {name: arg for (arg, name) in zip(a, names)})
        print("a:", a)
        print("new_a:", new_a)
        print("kw:", kw)
        print("new_kw:", new_kw)
        return f(*new_a, **new_kw)
    return decorator.decorator(wrapper)


def convert_to_seconds(varnames):
    "Converts the specified variables to seconds"
    return preprocess_args(cvsecs, varnames)

Outputs

a, names: {'args': <moviepy.video.io.VideoFileClip.VideoFileClip object at 0x1429a3710>, 'kw': 0}
a: (<moviepy.video.io.VideoFileClip.VideoFileClip object at 0x1429a3710>, 0,60)
new_a: [<moviepy.video.io.VideoFileClip.VideoFileClip object at 0x1429a3710>, 0]
kw: {}
new_kw: {}
t_start:  0
t_end:  None

Specifications

  • Python Version: 3.11.9
  • MoviePy Version: moviepy==1.0.3
  • Platform Name: OSX
  • Platform Version: 15.0
@jcoelho-aurascape jcoelho-aurascape added the bug Issues that report (apparent) bugs. label Oct 25, 2024
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.
Projects
None yet
Development

No branches or pull requests

1 participant