Ask Your Question

cv2.imread fail to open gif image

asked 2020-02-20 12:55:41 -0500

updated 2020-09-17 03:24:08 -0500

Can anybody tell why imread function will fail for this photo?


Actual file is here:

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-02-20 13:10:31 -0500

berak gravatar image

updated 2020-02-20 13:12:33 -0500

easy one, imread() won't read any .gif there is no codec for this (license problem)

as a workaround (and if you have ffmpeg support builtin), try:

cap = cv2.VideoCapture("f.gif")
ret, image =

if ret:
    # safe to work with image !
edit flag offensive delete link more


i don't think so. This photo is saved from browser. While most of images working only a few getting this problem. Why only specific photos will have this problem?

raggupta2 gravatar imageraggupta2 ( 2020-02-20 13:20:20 -0500 )edit

gif is animation not image. You will have to used @berak's snippet code.

supra56 gravatar imagesupra56 ( 2020-02-21 04:30:03 -0500 )edit

Of course GIF is a still image format, and was very common for pictures before PNG was invented. Today, though, it is mostly used for small silent animations.

mvuori gravatar imagemvuori ( 2020-02-21 05:49:01 -0500 )edit

@mvuori. Thank. I can recalled back in 1984. that I used to build 8086.

supra56 gravatar imagesupra56 ( 2020-02-21 09:01:51 -0500 )edit

I just opened this photo in MS-Paint and saved as JPG. Now it works

raggupta2 gravatar imageraggupta2 ( 2020-02-21 09:29:23 -0500 )edit

Question Tools

1 follower


Asked: 2020-02-20 12:55:41 -0500

Seen: 2,071 times

Last updated: Feb 21 '20