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

Moviepy blocks in the loop of VideoFileClip.iter_frames() for some gifs #1231

Closed
jianjieluo opened this issue Jun 15, 2020 · 2 comments
Closed
Labels
bug Issues that report (apparent) bugs.

Comments

@jianjieluo
Copy link

jianjieluo commented Jun 15, 2020

Hi, I found that moviepy>=1.0.3 will block in VideoFileClip.iter_frames() loop at the second frame forever when it processes some specific gifs, and the code won't throw an exception.

from moviepy.video.io.VideoFileClip import VideoFileClip
import numpy as np
from PIL import Image, ImageSequence
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

video = VideoFileClip(path)
frame_iterator = video.iter_frames()

frames = []
for frame in frame_iterator:  # block here in the second iteration
    if isinstance(frame, np.ndarray):
        frame = Image.fromarray(np.uint8(frame))
    frames.append(frame.convert('RGB'))

Expected Behavior

Extract the frames correctly

Actual Behavior

block in VideoFileClip.iter_frames() loop at the second iteration forever

Steps to Reproduce the Problem

Use the code above to process the example Gifs below:

484631

404933

486514

More details in the stackoverflow question: https://stackoverflow.com/questions/62389087/python-detect-a-rare-strange-gif-when-extracting-its-frames

Specifications

  • Python Version: 3.6, 3.5
  • Moviepy Version: >= 1.0.2
  • Platform Name: Windows10, Ubuntu 16.04
@jianjieluo jianjieluo added the bug Issues that report (apparent) bugs. label Jun 15, 2020
@tburrows13
Copy link
Collaborator

Hello, thanks for reporting this issue. I cannot replicate the hang on my (macOS) computer though. It outputs similar to PIL, which from looking at the comments on Stack Overflow seems like a valid interpretation of the broken gif. I am only getting 2 frames output (and 1 on the current v2.0 branch), but this is an issue with duration detection (which is being actively worked on to be more reliable in #1222).

MoviePy uses FFmpeg to access the file data, so you could experiment with that to find out where it is hanging. Also try doing a keyboard interrupt (Ctrl-C) whilst it is hanging to work out where it is getting stuck.

@jianjieluo
Copy link
Author

jianjieluo commented Jun 15, 2020

Thanks for your quick response. I directly use the lateset static builds of FFmpeg to extract frames and get 2 frames output as you say. Therefore it may account mainly for the broken gifs rather than moviepy package. I will try to detect such broken gifs before using moviepy to handle them.

Thanks for your help again.

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

2 participants