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

loop for concatenate_videoclips #1027

Closed
arianaa30 opened this issue Oct 3, 2019 · 2 comments
Closed

loop for concatenate_videoclips #1027

arianaa30 opened this issue Oct 3, 2019 · 2 comments

Comments

@arianaa30
Copy link

How can I do the following command in a for loop? Right now it is hardcoded for only 4 subs. I need to extend it to n subs.

final = concatenate_videoclips([sub[0], sub[1].crossfadein(.5), sub[2].crossfadein(.5), sub[3].crossfadein(.5)], padding=-1, method="compose")

Any subs after [0] need to have a crossfadein effect.

@arianaa30 arianaa30 changed the title loop loop for concatenate_videoclips Oct 3, 2019
@tburrows13
Copy link
Collaborator

I think this does what you're looking for:

crossfadedsub = []
for clip in sub[1:]:  # Iterate over the list except for the first item
    crossfadedsub.append(clip.crossfadein(0.5))
final = concatenate_videoclips([sub[0]] + crossfadedsub, padding=-1, method="compose")

@Zulko
Copy link
Owner

Zulko commented Oct 3, 2019

Rah Tom beat me to it but here is an alternative with list comprehensions:

faded_clips = [sub[0]] + [clip.crossfadein(0.5) for clip in sub[1:]]
final = concatenate_videoclips(faded_clips, padding=-1, method="compose")

Note that, as this is more a Python question than a Moviepy question, you'd get faster answers by posting a question on Stackoverflow or Reddit/Python.

@Zulko Zulko closed this as completed Oct 9, 2019
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

3 participants