-
Notifications
You must be signed in to change notification settings - Fork 192
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
Animated GIF corruption + size increase #1024
Comments
I just looked at a recent PNG I uploaded: Original size: 1.2MB Very cool. |
Likely a PIL bug and not ours, I think: https://github.com/webcompat/webcompat.com/blob/master/webcompat/api/uploads.py#L89-L92 |
The corrupted GIF issues. yes this is known. We discussed about it already. And you can see my discussion with Pillow owners |
We also discussed it here |
Note that I can try to solve it on Pillow side, but that will take a bit of time, because I think it's quite a complex issue with color encoding compression, etc. I wonder if for animated gif, we could convert them to compressed mp4 movies. as we are able to detect them. |
@miketaylr Oh! http://zulko.github.io/moviepy/ Let's test something with that.
Then onto the interesting stuff. >>> import moviepy.editor as mp
Imageio: 'ffmpeg.osx' was not found on your computer; downloading it now.
Error while fetching file: ('The read operation timed out',).
Error while fetching file: ('The read operation timed out',).
Error while fetching file: ('The read operation timed out',).
Error while fetching file: ('The read operation timed out',).
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/moviepy/editor.py", line 22, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/moviepy/video/io/VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 20, in <module>
from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_writer.py", line 15, in <module>
from moviepy.config import get_setting
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/moviepy/config.py", line 38, in <module>
FFMPEG_BINARY = get_exe()
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/imageio/plugins/ffmpeg.py", line 52, in get_exe
exe = get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat])
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/imageio/core/fetching.py", line 98, in get_remote_file
_fetch_file(url, filename)
File "/Users/karl/.virtualenvs/testing/lib/python2.7/site-packages/imageio/core/fetching.py", line 154, in _fetch_file
os.path.basename(file_name))
IOError: Unable to download 'ffmpeg.osx'. Perhaps there is a no internet connection? If there is, please report this problem. Rha let's pull the thread.
Let's go back to python. >>> import moviepy.editor as mp
Imageio: 'ffmpeg.osx' was not found on your computer; downloading it now.
Error while fetching file: ('The read operation timed out',).
Error while fetching file: ('The read operation timed out',).
Error while fetching file: ('The read operation timed out',).
Try 4. Download from https://github.com/imageio/imageio-binaries/raw/master/ffmpeg/ffmpeg.osx (28.8 MB)
Downloading: 30241064/30241064 bytes (100.0%)
Done
File saved as /Users/karl/Library/Application Support/imageio/ffmpeg/ffmpeg.osx.
>>> movie_gif = mp.VideoFileClip("/Users/karl/Desktop/animated.gif")
>>> movie_gif.write_videofile("/Users/karl/Desktop/animated.webm")
[MoviePy] >>>> Building video /Users/karl/Desktop/animated.webm
[MoviePy] Writing video /Users/karl/Desktop/animated.webm
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 104.60it/s]
[MoviePy] Done.
[MoviePy] >>>> Video ready: /Users/karl/Desktop/animated.webm OK the conversion worked! Without issues. ls -lh ~/Desktop/animated* | awk '{print $5, $9}'
# original
309K /Users/karl/Desktop/animated.gif
# Movie by moviepy
105K /Users/karl/Desktop/animated.webm
# Saved by pillow
707K /Users/karl/Desktop/animated_save_all.gif |
Just to be more explicit. Just the 3 lines of code. import moviepy.editor as mp
movie_gif = mp.VideoFileClip("/Users/karl/Desktop/animated.gif")
movie_gif.write_videofile("/Users/karl/Desktop/animated.webm") |
Yeah, I remember that. I thought the idea was that we weren't going to touch animated GIFs with Pillow, to prevent the corruption. But I misunderstood, because just saving the image (via (I guess my bad for not catching this at review.) Another option might be detect if it's animated via Pillow, then save the original file manually via @karlcow for the mp4 approach, do you have a sense of how long it takes to convert? I see you used webm, but Safari can't play those (or Edge currently), so probably not ideal. If it's fast, this seems cool. If it's slow maybe we skip Pillow for animated GIFs like mentioned above. |
Yeah good points. Probably slow. >>> timeit.timeit('import moviepy.editor as mp; movie_gif = mp.VideoFileClip("/Users/karl/Desktop/animated.gif"); movie_gif.write_videofile("/Users/karl/Desktop/animated.mp4", verbose=False)', number=10)
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 1001.18it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 1093.55it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 1105.09it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 966.25it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 1054.83it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 1025.64it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 961.58it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 972.44it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 1020.62it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<00:00, 1054.83it/s]
1.6520440578460693 Around 1.6s to 1.7s |
Let's not fix this. 💣 |
If you upload an animated GIF, it's being corrupted at some level.
Compare the source:
And the uploaded file:
Also the original file-size was 2.7MB, the corrupted version is 5.6MB 😮
@karlcow something you want to tackle?
The text was updated successfully, but these errors were encountered: