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

Can't import gifs into moviepy #452

Closed
DanielHHowell opened this issue Feb 28, 2017 · 9 comments
Closed

Can't import gifs into moviepy #452

DanielHHowell opened this issue Feb 28, 2017 · 9 comments

Comments

@DanielHHowell
Copy link

DanielHHowell commented Feb 28, 2017

The below code is working marvelously as-is for other file types such as .webm (when changed in the glob.glob call) but when I try to use it for .gifs nothing happens at all - no errors or exceptions raised. Any ideas? Thanks you in advance for any help!

from moviepy.editor import *
import glob

def movie_maker(location_path):
    raw_clips = [VideoFileClip(path) for path in glob.glob(location_path+'*.gif')]
    sized_clips = [clip.resize((600,600)) for path in raw_clips]
    final_clip = concatenate_videoclips(sized_clips)
    final_clip.write_videofile(path + 'Video.avi', fps=24, codec='png')
@Zulko
Copy link
Owner

Zulko commented Feb 28, 2017

just checking: did you print 'raw_clips' to make sure it's not empty ?

@tburrows13
Copy link
Collaborator

"Nothing happens"? Does final_clip.write_videofile not do anything? Have you tried just running a simple clip = VideoFileClip(file.gif) and clip.write_videofile(path etc)?

@DanielHHowell
Copy link
Author

DanielHHowell commented Feb 28, 2017

Thanks for the very fast responses. Printing raw_clips as is isn't possible, the script is just getting stuck on the first line.

Gloin1313:
I tried that and it worked - so it seems this is an issue of looping through multiple .gifs?

@tburrows13
Copy link
Collaborator

tburrows13 commented Feb 28, 2017

@DanielHHowell You could try expanding your loop, e.g.:

for path in glob.glob(location_path+'*.gif'):
    raw_clips.append(VideoFileClip(path))

And then print certain variables at different points to try and troubleshoot better.

@DanielHHowell
Copy link
Author

DanielHHowell commented Feb 28, 2017

raw_clips = []
for path in glob.glob(location_path + '*.GIF'):
    print(path)
    raw_clips.append(VideoFileClip(path))
print(raw_clips)

So the loop is being iterated through - it prints each instance of 'path' here, however nothing else will happen past that. I'm very confused how the append clip is passed over with seemingly no error raised

@tburrows13
Copy link
Collaborator

tburrows13 commented Feb 28, 2017

What about this?

raw_clips = [0,0,0,0,0,0,0]  # Add a `0` for each gif you have
for i, path in glob.glob(location_path + '*.GIF'):
    print(path)
    raw_clips[i] = VideoFileClip(path)
print(raw_clips)

Or, try this:

raw_clips = []
for path in glob.glob(location_path + '*.GIF'):
    print(path)
    clip = VideoFileClip(path)
    # Do something with `clip` like `clip.write_videofile` or use preview to see whether it exists
    raw_clips.append(clip)
print(raw_clips)

Just a side note; don't name a variable containing a string a clip. I'd recommend just calling it path. Reserve variable names with clip in them for actual instances of a moviepy clip. I've edited your posts in this thread for clarity.

@DanielHHowell
Copy link
Author

Everything is working properly now - even the code I originally introduced. Deleting some .gif path's from the directory revealed that the ffmpeg process was keeping them open, even though no processes were running on the PyCharm IDE. Very strange

@tburrows13
Copy link
Collaborator

tburrows13 commented Mar 1, 2017

Well done!
So nothing wrong on moviepy's side then? If so, we can close this.
Or are you saying that certain GIFs weren't working?

@DanielHHowell
Copy link
Author

My guess is that this was related to ffmpeg - go ahead and close the issue. Thanks for the rapid responses - will keep in mind that debugging process!

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