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

How to conditionally chain effects? #138

Closed
Netherdrake opened this issue Mar 5, 2015 · 10 comments
Closed

How to conditionally chain effects? #138

Netherdrake opened this issue Mar 5, 2015 · 10 comments

Comments

@Netherdrake
Copy link

This is some horrible python code that will make you cringe (sorry, I barely know any python), but what I'm trying to do is conditionally chain the effects:

def render_clip(video, output):
    clip1 = editor.VideoFileClip(video["filePath"])

    if video["fade"]["in"]:
        clip1.fadein(2)

    if video["fade"]["out"]:
        clip1.fadeout(2)

    if video["effects"]["mirror"]:
        clip1.fx( editor.vfx.mirror_x )

    if video["effects"]["blackWhite"]:
        clip1.fx( editor.vfx.blackwhite )

    if video["effects"]["cartoon"]:
        clip1.fx( editor.vfx.painting )

    clip1.write_videofile(output)

Unfortunately, this naive implementation doesn't work. The state from calling a function on clip1 insn't preserved.

Is there any built in utility that could handle this problem? Any language feature I am unaware of?

@Zulko
Copy link
Owner

Zulko commented Mar 5, 2015

All transformations are outplace so write clip1 = clip1.fadein(2) instead of just clip1.fadein(2)

@Netherdrake
Copy link
Author

when I tried that it never finished.

It would just run ffmpeg at full speed in and out for the whole night on a clip that should take no more than 10 minutes to render.

@Zulko
Copy link
Owner

Zulko commented Mar 5, 2015

Yes but did it work ? Have you tried this on a subclip ? My guess would be that the painting effect is slowing everything down.

@Netherdrake
Copy link
Author

No, I killed the process in the morning.

Its really slow:

|----------| 34/2550   1% [elapsed: 00:28 left: 34:37,  1.21 iters/sec]

Editing 30s file shouldn't take this long to render.

When I just concatenate them like

clip1.speedx(foo).fx( some_effect)...write_videofile(output)

it takes only about a minute to render.

@Zulko
Copy link
Owner

Zulko commented Mar 5, 2015

That's not logical, there must be a difference between your scripts . You'll have to give me two complete examples with the resulting speeds (iters/sec) of each

@Netherdrake
Copy link
Author

Yes, here is the code:

def render_clip(video, output):
    # clip1 = editor.VideoFileClip(video["filePath"])
    #
    # if video["speed"]["up"]:
    #     clip1 = clip1.speedx(1.00 + (float(video["speed"]["value"])/100))
    #
    # if video["speed"]["down"]:
    #     clip1 = clip1.speedx(1.00 - (float(video["speed"]["value"])/100))
    #
    # if video["zoom"]["in"]:
    #     clip1 = clip1.resize(video["zoom"]["value"])
    #
    # if video["fade"]["in"]:
    #     clip1 = clip1.fadein(2)
    #
    # if video["fade"]["out"]:
    #     clip1 = clip1.fadeout(2)
    #
    # if video["effects"]["mirror"]:
    #     clip1 = clip1.fx( editor.vfx.mirror_x )
    #
    # if video["effects"]["blackWhite"]:
    #     clip1 = clip1.fx( editor.vfx.blackwhite )
    #
    # if video["effects"]["cartoon"]:
    #     clip1 = clip1.fx( editor.vfx.painting )
    #
    # clip1.write_videofile(output)

    clip2 = editor.VideoFileClip(video["filePath"]). \
        fx( editor.vfx.mirror_x ). \
        resize(1.07). \
        speedx(0.93). \
        fadeout(2). \
        fadein(2). \
        fx( editor.vfx.blackwhite ). \
        write_videofile(output)

I ran both under exact same settings, just the second ones are hardcoded (but matching 100%).

clip1 is slow:

|----------| 34/2550   1% [elapsed: 00:28 left: 34:37,  1.21 iters/sec]

clip2 is 30x+ faster:

|----------| 212/2550   8% [elapsed: 00:05 left: 01:02, 37.38 iters/sec]

@Zulko
Copy link
Owner

Zulko commented Mar 5, 2015

I have no idea what effects clip1 has because of the conditionality, but I guess you are using the "cartoon" effect, and that's why it is very slow.

@Netherdrake
Copy link
Author

I am not using cartoon effect in either.

Furthermore, its very slow if I use no effects at all (25min eta on just speed-up, resize & fadein).

I think when its done conditionally, something gets messed up internally.

@Zulko
Copy link
Owner

Zulko commented Mar 5, 2015

I can't see what could get "messed up internally". Either it applies the effect, or it doesn't, but when it does, it's really equivalent to what you do with clip2. Can you provide the parameters used for clip1 ? I can't help you if you don't provide the complete script.

@Netherdrake
Copy link
Author

Sorry, nevermind. I am a complete retard.

I had a bug in one of parameters (zoom), it would zoom in 7 instead of 1.07. This caused the slow-down.

I am sorry for wasting your time with my stupidity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants