nathan-osman / gimp-webp

Gimp plugin for loading and saving WebP images
GNU General Public License v3.0
69 stars 8 forks source link

Animation support #4

Open Xylemon opened 8 years ago

Xylemon commented 8 years ago

Could there be support for animated webp's?

nathan-osman commented 8 years ago

That's a great idea. I'll see how simple this would be to implement. It would probably work the same way as the GIF plugin, using a separate layer for each frame.

ghost commented 8 years ago

I second that this is an awesome idea! Currently, the only way to export high bit depth animation in GIMP is to start off exporting first to video and then to transcode this video to webp using ffmpeg like

ffmpeg -i u5.mp4 -c:v libwebp -loop 0 u5.webp

...which is somewhat less than desireable. So, I can't say how enthused I am if this could be made possible! Google+ allows animated webp uploads and I publish some of my work there this way: https://plus.google.com/+VisualEyes-us ... so a BIG :+1:^:100:

ghost commented 8 years ago

If it helps for testing purposes, here are some animated webp images I generated using ffmpeg:

https://storage.googleapis.com/bucketami/00245%3D07576%3D07576%3D07576.webp https://storage.googleapis.com/bucketami/00247%3D06534%3D06534%3D06534.webp https://storage.googleapis.com/bucketami/femto.webp https://storage.googleapis.com/bucketami/VFP3.webp

Compiled and installed the plugin, so you also have a dedicated tester here.

nathan-osman commented 8 years ago

Thanks. I'll see what I can do.

nathan-osman commented 8 years ago

I've added code for detecting libwebp 0.5+ (required for animation support). The only thing left is the actual load / save code. I'll try to tackle that over the weekend.

ghost commented 8 years ago

Are you sure libwebp 0.5 is required for animation? ffmpeg only requires 0.4+ to compile with animated webp capability. The reason I ask is that I looked around and couldn't find any debian packages or ppas with anything higher than 0.4.4 available. http://packages.ubuntu.com/search?suite=xenial&searchon=names&keywords=libwebp This also may make it more difficult for others to compile your plugin ;)

nathan-osman commented 8 years ago

Yeah, that's a good point. I looked at the 0.5 release notes and saw:

* New WebPAnimEncoder API for creating animations
* New WebPAnimDecoder API for decoding animations

It may be possible to read and write animated WebP images without these functions but this will require some further digging into the source code since none of the functions are documented (as far as I can tell). I would like to keep the version requirements as low as possible.

As far as Ubuntu goes, I could easily add packages for 0.5 to the PPA I'm currently using to distribute the plugin if that becomes necessary. When I publish builds for Windows, I prefer to statically link WebP, so the problem doesn't really exist on that platform.

nathan-osman commented 8 years ago

Looking through the version history shows:

0.3.0

* color profile, metadata (XMP/EXIF) and animation support finalized in the
container.

This appears to be the first release to support animation. Once I get something together that works, I can try compiling it with progressively older versions until it breaks.

ghost commented 8 years ago

I'm not opposed to using 0.5, I'm sure I could figure out how to install it from source if I was forced to. In fact, having to do so might improve my ffmpeg transcodes. But, I just wanted to make sure you were aware that 0.4 could get the job done as well. Also, AFAIK, I wasn't able to successfully make animated webp's from ffmpeg using libwebp 0.3. Your idea of stepping back version by version sounds great!

nathan-osman commented 8 years ago

Unfortunately, I wasn't able to complete this over the weekend :cry:

There is both good news and bad news. The good news is that it appears I can indeed read and write WebP files with multiple frames (animations) within libwebp 0.4. The bad news is that this requires switching to the WebPMux* functions, which requires rewriting a significant amount of code.

I'm still hoping to get this done soon, but I wanted to provide a brief update.

Xylemon commented 8 years ago

Glad to hear you're still working on adding animation support and wanted to say I appreciate the effort to get this working.

nathan-osman commented 8 years ago

I've added the code that should be sufficient for loading animated WebP images. However, it fails to load the examples that @triune provided. What's more, they don't even work in WebP's own CLI tool:

$ file ~/Downloads/00245=07576=07576=07576.webp
~/Downloads/00245=07576=07576=07576.webp: RIFF (little-endian) data, Web/P image
$ webpmux -info 00245=07576=07576=07576.webp
Failed to create mux object from file 00245=07576=07576=07576.webp

However, the animations play without issue in Chrome. So I wondered if this had anything to do with my using libwebp 0.4.4, but upgrading to 0.5.0 didn't make any difference.

On an unrelated note, I think I'm going to rewrite the plugin in C++. My original reason for using C was the goal of eventually submitting the code to the Gimp project. However, Gimp 2.9 has added basic support for WebP images and the only reason for keeping this plugin around is to support 2.8.x releases.

ghost commented 8 years ago

@nathan-osman I can reproduce the error in getting mux information as well. Not sure why my ffmpeg generated imagery could be bad. I have asked on the webp dev mailing list about this errata here: https://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/00wJrPn5CJM

Glad to see you're still interested in continued dev on this with a rewrite in C++ :+1:

ghost commented 8 years ago

Got some more information from the mailing list... it appears the bug discovered here is in ffmpeg's muxer as it will always set the alpha bit to 1 regardless of transparency information being present or not in the image. https://bugs.chromium.org/p/webp/issues/detail?id=266

I've created a ticket on the ffmpeg tracker about this bug: https://trac.ffmpeg.org/ticket/5431

nathan-osman commented 8 years ago

Great, thanks for the update. I'll try to generate some WebP animations using the webpmux tool so that I have some test images I can use.

draekko commented 8 years ago

@nathan-osman

Just a heads up that i added animation support and loading/save the ICC profile with each image. I forked it over here https://github.com/draekko/gimp-webp and changed all the deprecated code to use gegl calls insteads of what was there. Hoping to add exif, and xmp support sooner or later. Only tested it against gimp 2.9.4 with libwebp 0.5.1, not sure it would work with 2.8.x. Unfortunately the code is too different in places to do pull request. Have a good one.

nathan-osman commented 8 years ago

@draekko cool! Thanks for letting me know. This is the reason that I released the project under an open source license - so that people could improve and build on what I wrote.

If I wrapped the GEGL code in #ifdef / #endif blocks, it would probably be possible to get it working on both Gimp 2.8.x and Gimp 2.9.x. I would be willing to merge a pull request if you sent one and then I could fix it up to work with both releases.

Thanks again!

ghost commented 8 years ago

+1 for 2.8.x support !!

draekko commented 8 years ago

@nathan-osman Sure, i'll do that, i don't use 2.8 anymore and i needed to make a lot of changes soooo... lol. If you want to merge be my guest, in theory it should work fine if you add the missing chunks back in. The one caveat is that muxer does its own thing and doesn't let you specify layer blending on export. I spent a day on that and didn't find any way that worked, probably would have to rewrite huge portions of libwebp for that. If you merge, let me know i'll repost about it on the gimp devel mailing list with a link to my repo as i didn't if/when you'd answer. So if you merge it i'll amend the info with a new email to it. I tried to get exif and xmp working but gimp uses gexiv2 to load metadata and doesn't seem compatible just yet with how webp stores its data. I have to do more reading on that unless you want to tackle that, look at the icc code, the xmp and exif is just another chunk added to the file. Similar process to add or remove both, but getting that into gimp is problematic. Anyways i'll send you a pull request with what i currently have.

draekko commented 8 years ago

Oh before i forget one caveat best to up the requirement to libwepm 0.5.1 (i used it from git) for testing.

nathan-osman commented 8 years ago

@draekko thanks! I've merged it into a branch here: https://github.com/nathan-osman/gimp-webp/tree/draekko-master I'll work at getting it into master. Shouldn't be too much work - just some conditional blocks here and there. Thanks!

draekko commented 8 years ago

Cool, let me know if you need any other info.

nathan-osman commented 8 years ago

Alright, I finally finished getting everything merged together. It's still a bit of a mess, but it compiles and I can still open and save files with Gimp 2.8.x. I will try to get my hands on a copy of Gimp 2.9.x so that I can try it out there. I am almost certain that I broke something due to the sheer size of the merge.

Some code inadvertently got removed in an attempt to get it working (saving color profiles and lots of the debug statements). I'll slowly put those lines back in once I can get more of this tested.

ghost commented 8 years ago

I did a git pull, build, deleted both ~/.gimp-2.8/plug-ins/file-webp and /usr/lib/gimp/2.0/plug-ins/file-webp and then installed via sudo make install which worked... and I cannot open any webp files.... I also do not see the animation control in the export dialog. screenshot 2016-07-29 at 6 15 41 am screenshot 2016-07-29 at 6 17 56 am

ghost commented 8 years ago

Is this perhaps b/c I am still using libwebp 0.4.4 ? I don't know how to upgrade these packages.... doesn't seem to be a 0.5.x ppa anywhere out there. I also tried compiling the library from source https://developers.google.com/speed/webp/docs/compiling#building and then to rebuild gimp-webp but the 0.4.4 library still seems to take precedence.

screenshot 2016-07-29 at 6 44 07 am

nathan-osman commented 8 years ago

Yes, all of the animation code is prevented from being included unless libwebp>0.5 is installed. In theory it should be possible to tell CMake where to look for pkg-config files when searching for libwebp, but I'm not exactly sure how. This answer suggests that adding a line right after find_package() in CMakeLists.txt might work:

set(ENV{PKG_CONFIG_PATH} "/path/to/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}" )

As far as the plugin itself not working, are you using Gimp 2.8.x or Gimp 2.9.x?

ghost commented 8 years ago

Gimp 2.8.x

libwebp 0.5.1 compiled with cmake and installed here >>

z@G:/usr/local/lib$ ls -la libwebp* -rw-r--r-- 1 root root 4608436 Jul 29 11:33 libwebp.a -rwxr-xr-x 1 root root 954 Jul 29 11:33 libwebp.la lrwxrwxrwx 1 root root 16 Jul 29 11:33 libwebp.so -> libwebp.so.6.0.1 lrwxrwxrwx 1 root root 16 Jul 29 11:33 libwebp.so.6 -> libwebp.so.6.0.1 -rwxr-xr-x 1 root root 2735256 Jul 29 11:33 libwebp.so.6.0.1

Tried adding that line like: find_package(PkgConfig REQUIRED) set(ENV{PKG_CONFIG_PATH} "/usr/local/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}" )

But I get this >>

z@G:~/gimp-webp/build$ nano ../CMakeLists.txt z@G:~/gimp-webp/build$ cmake .. -- Gimp 2.8.18 found Checking for modules 'libwebp>=0.4;libwebpmux>=0.4'

CMake Error at /usr/share/cmake-3.5/Modules/FindPkgConfig.cmake:367 (message): A required package was not found Call Stack (most recent call first): /usr/share/cmake-3.5/Modules/FindPkgConfig.cmake:532 (_pkg_check_modules_internal) CMakeLists.txt:61 (pkg_check_modules)

-- Configuring incomplete, errors occurred! See also "/home/z/gimp-webp/build/CMakeFiles/CMakeOutput.log".

^^ attaching that file if it helps...

CMakeOutput.log.txt

Would using the precompiled package: libwebp-0.5.1-linux-x86-64 help at all if I could point to it in gimp-webp cmake somehow?

draekko commented 8 years ago

@nathan-osman i've got some partial code for the plugin and exiv2 to add reading the exif and xmp data. Going to start working on the saving part. Hoping to get that working in the next week or so. I'll do another pull request when its done and working for 2.9 (i don't think that part will work with 2.8).

draekko commented 8 years ago

For Ubuntu users here's a ppa for 2.9.5+ https://launchpad.net/~otto-kesselgulasch/+archive/ubuntu/gimp-edge to test with.

draekko commented 8 years ago

@nathan-osman you should mention needing 0.5+ for the webp library to get animation working.

ghost commented 8 years ago

There's kind of a gaping hole out there in the need for a ppa with libwebp 0.5.1 ... isn't there? I can't believe even the upcoming 16.10 Yakkety only has 0.4.4 !!

http://packages.ubuntu.com/search?keywords=libwebp&searchon=names&suite=yakkety&section=all

Who's the best person to get in contact with to request 0.5.x in a PPA ? If someone could tell me how to setup an autobuilding PPA, I'd even do it myself in one of my GCE instances.

nathan-osman commented 8 years ago

Debian has a build in experimental. I'm going to try backporting it shortly.

draekko commented 8 years ago

I've added an extras directory to my fork https://github.com/draekko/gimp-webp/tree/master/extras with ubuntu built deb's for 0.5.1 as well as the source code & debian folder to create the debs and a precompiled binary of the plug-in for GIMP 2.9.5 also built on Ubuntu.

draekko commented 8 years ago

@nathan-osman i haven;t tested the your back port yet, hoping to do that soonish.

ghost commented 8 years ago

@draekko thank you for the libwebp 0.5.1 packages! Since I got those, I attempted to build using @nathan-osman 's branch, but I got a ton of errors. So, I think he might want to see what happened for me...

z@G:~/gimp-webp/build$ cmake .. -- The C compiler identification is GNU 5.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") -- Checking for modules 'gimp-2.0>=2.8;gimpui-2.0>=2.8' -- Found gimp-2.0, version 2.8.18 -- Found gimpui-2.0, version 2.8.18 -- Gimp 2.8.18 found -- Checking for modules 'libwebp>=0.4;libwebpmux>=0.4' -- Found libwebp, version 0.5.1 -- Found libwebpmux, version 0.5.1 -- WebP 0.5.1 found -- Configuring done -- Generating done -- Build files have been written to: /home/z/gimp-webp/build z@G:~/gimp-webp/build$ make Scanning dependencies of target file-webp [ 20%] Building C object src/CMakeFiles/file-webp.dir/webp-dialog.c.o In file included from /usr/include/gtk-2.0/gtk/gtkwidget.h:36:0, from /usr/include/gtk-2.0/gtk/gtkcontainer.h:35, from /usr/include/gtk-2.0/gtk/gtkbin.h:35, from /usr/include/gtk-2.0/gtk/gtkwindow.h:36, from /usr/include/gtk-2.0/gtk/gtkdialog.h:35, from /usr/include/gtk-2.0/gtk/gtkaboutdialog.h:32, from /usr/include/gtk-2.0/gtk/gtk.h:33, from /usr/include/gimp-2.0/libgimp/gimpui.h:22, from /home/z/gimp-webp/src/webp-dialog.c:20: /home/z/gimp-webp/src/webp-dialog.c: In function ‘save_dialog_toggle_checkbox’: /usr/include/gtk-2.0/gtk/gtkobject.h:48:38: warning: passing argument 1 of ‘gtk_widget_set_sensitive’ from incompatible pointer type [-Wincompatible-pointer-types]

define GTK_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_OBJECT, GtkObject))

                                  ^

/home/z/gimp-webp/src/webp-dialog.c:87:30: note: in expansion of macro ‘GTK_OBJECT’ gtk_widget_set_sensitive(GTK_OBJECT(data), ^ In file included from /usr/include/gtk-2.0/gtk/gtkcontainer.h:35:0, from /usr/include/gtk-2.0/gtk/gtkbin.h:35, from /usr/include/gtk-2.0/gtk/gtkwindow.h:36, from /usr/include/gtk-2.0/gtk/gtkdialog.h:35, from /usr/include/gtk-2.0/gtk/gtkaboutdialog.h:32, from /usr/include/gtk-2.0/gtk/gtk.h:33, from /usr/include/gimp-2.0/libgimp/gimpui.h:22, from /home/z/gimp-webp/src/webp-dialog.c:20: /usr/include/gtk-2.0/gtk/gtkwidget.h:964:23: note: expected ‘GtkWidget * {aka struct GtkWidget }’ but argument is of type ‘GtkObject * {aka struct _GtkObject }’ void gtk_widget_set_sensitive (GtkWidget widget, ^ [ 40%] Building C object src/CMakeFiles/file-webp.dir/webp-load.c.o /home/z/gimp-webp/src/webp-load.c: In function ‘load_image’: /home/z/gimp-webp/src/webp-load.c:210:9: error: label at end of compound statement success: ^ /home/z/gimp-webp/src/webp-load.c:233:13: error: ‘flag’ undeclared (first use in this function) if (flag & ICCP_FLAG) { ^ /home/z/gimp-webp/src/webp-load.c:233:13: note: each undeclared identifier is reported only once for each function it appears in /home/z/gimp-webp/src/webp-load.c:235:13: error: unknown type name ‘GimpColorProfile’ GimpColorProfile profile; ^ /home/z/gimp-webp/src/webp-load.c:238:34: warning: passing argument 2 of ‘WebPMuxGetChunk’ makes pointer from integer without a cast [-Wint-conversion] WebPMuxGetChunk(mux, WEBP_CHUNK_ICCP, &icc_profile); ^ In file included from /home/z/gimp-webp/src/webp-load.c:24:0: /usr/include/webp/mux.h:179:27: note: expected ‘const char ’ but argument is of type ‘int’ WEBP_EXTERN(WebPMuxError) WebPMuxGetChunk( ^ /home/z/gimp-webp/src/webp-load.c:241:23: warning: implicit declaration of function ‘gimp_color_profile_new_from_icc_profile’ [-Wimplicit-function-declaration] profile = gimp_color_profile_new_from_icc_profile( ^ /home/z/gimp-webp/src/webp-load.c:241:21: warning: assignment makes pointer from integer without a cast [-Wint-conversion] profile = gimp_color_profile_new_from_icc_profile( ^ /home/z/gimp-webp/src/webp-load.c:244:17: warning: implicit declaration of function ‘gimp_image_set_color_profile’ [-Wimplicit-function-declaration] gimp_image_set_color_profile(imageID, profile); ^ src/CMakeFiles/file-webp.dir/build.make:86: recipe for target 'src/CMakeFiles/file-webp.dir/webp-load.c.o' failed make[2]: ** [src/CMakeFiles/file-webp.dir/webp-load.c.o] Error 1 CMakeFiles/Makefile2:85: recipe for target 'src/CMakeFiles/file-webp.dir/all' failed make[1]: * [src/CMakeFiles/file-webp.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: * [all] Error 2

draekko commented 8 years ago

@nathan-osman Oh before i forget i submitted a patch to the folks at the exiv2 project to support exif/xmp waiting to hear back on that.

ghost commented 8 years ago

@draekko am I missing some more PPA's or something?

z@G:~$ sudo apt-get build-dep gimp [sudo] password for z: Reading package lists... Done E: You must put some 'source' URIs in your sources.list

draekko commented 8 years ago

@triune You probably already have all the dependencies already, as for the errors it looks like some code errors in the plugin that nathan would need to fix.

draekko commented 8 years ago

There is one error that looks like its not finding the header files for gimp. Either using aptitude or synaptic make sure that the gimp-dev package is installed (not sure the actual name just do search for gimp).

ghost commented 8 years ago

@draekko I think I had that package already...

z@G:~$ sudo apt-cache search gimp | grep dev libglib2.0-dev - Development files for the GLib library libgutenprint-dev - development files for the Gutenprint printer driver library libgutenprintui2-dev - development files for the Gutenprint printer driver user interface library libijs-dev - IJS raster image transport protocol: development files libgegl-dev - Generic Graphics Library (development files) libgimp2.0-dev - Headers and other files for compiling plugins for GIMP libgimp2.0-doc - Developers' Documentation for the GIMP library libvips-dev - image processing system good for very large images (dev) z@G:~$ sudo apt install libgimp2.0-dev Reading package lists... Done Building dependency tree Reading state information... Done libgimp2.0-dev is already the newest version (2.8.18-0x2~ppa). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

I have these PPA's if it makes any difference... otto-kesselgulasch-gimp-trusty otto-kesselgulasch-ubuntu-gimp-xenial

draekko commented 8 years ago

You'll have to ask nathan i don't use 2.8 :)

nathan-osman commented 8 years ago

@triune I have fixed those compilation errors. Sorry about that.