lottie-node icon indicating copy to clipboard operation
lottie-node copied to clipboard

Not working with some bodymovin json data

Open sudesh1456 opened this issue 5 years ago • 15 comments

I'm using this file that rendering blank video

sudesh1456 avatar Mar 14 '19 19:03 sudesh1456

Hi! Thanks for reporting this.

I'm also getting blank output with that data file, although it does work in Lottie-web. Unfortunately I don't know how to fix it. lottie-node is basically an API wrapping Lottie, node-canvas and jsdom. The problem is not likely in lottie-node itself but one of those libraries (my guess is node-canvas). That's a lot of code to debug, and I don't have the time I'm afraid.

If you want to avoid the problem, try removing layers in After Effects and/or tweaking export settings in Bodymovin (and let me know if you find out what caused it since it may help someone else). I would make sure all assets are either included or remove the layers.

Also, do you mind if I attach the file to this issue via github's attach feature? This will ensure that the file is accessible as long as the issue is.

friday avatar Mar 14 '19 20:03 friday

Yes, Please attach via github. I also tried some basic effects like [https://lottiefiles.com/1708-success](this one) It is also not rendered on video properly.

sudesh1456 avatar Mar 15 '19 20:03 sudesh1456

Sorry to hear that!

Here are both of them attached: hbd.json.zip lottiefiles-1708-success.json.zip

If you or someone want to do more digging, you're very welcome to. Try to find what these have in common and comment if you find more examples (especially small and simple animations).

If someone is able to isolate a minimal test case for node-canvas this would be even better. This means a canvas that renders in browsers, but not node-canvas, and the test-case shouldn't include Lottie.

friday avatar Mar 15 '19 21:03 friday

when use a json file with image,i found that animation.isLoaded was false, false

but when use a json file without image,i found that animation.isLoaded was true, true

setImmediate(() => {
  console.log('animation',animation)
  //console.log(canvas.toDataURL())
  fs.writeFile(`${__dirname}/output.png`, canvas.toBuffer(), err => {
    if (err) {
      throw err;
    }
  });
});

so i guess the problem is lottie do not loaded image when lottie-node render-png

WangShuXian6 avatar Apr 24 '19 06:04 WangShuXian6

so i guess the problem is lottie do not loaded image when lottie-node render-png

I'm sure that's not it. The issue happened without images (see above), and I developed this specifically for rendering lottie animations with interchangable images. They all worked, but I don't own the right to them.

Though maybe isLoaded is worth looking into. Thanks!

friday avatar Apr 24 '19 10:04 friday

so i guess the problem is lottie do not loaded image when lottie-node render-png

I'm sure that's not it. The issue happened without images (see above), and I developed this specifically for rendering lottie animations with interchangable images. They all worked, but I don't own the right to them.

Though maybe isLoaded is worth looking into. Thanks!

I encountered the same question. When I look deep into the source code of lottie.js, I find the problem:

function loaded() { return this.totalImages === this.loadedAssets; }

the loadedAssets+1 when the picture triggered the onload function. However the code below is not working in canvas.: img.addEventListener('load', this._imageLoaded.bind(this), false);

I think this may be the problem but I don't know how to fix it

issderek avatar May 05 '19 17:05 issderek

Thanks for trying! lottie-node patches the lottie-web code by overriding the image load handler so that it works with node + node-canvas. Could be something related to this. I'm not convinced this is the right place to look, or if it's even the same issue, but since I haven't got time to investigate this myself I'm glad for all of your efforts :+1:

friday avatar May 05 '19 17:05 friday

puppeteer-lottie, an alternative to lottie-node was just created by @transitive-bullshit. I haven't tried it, but since it doesn't deal with Node-canvas at all it's not very likely to have this issue.

friday avatar May 10 '19 14:05 friday

Did anyone find a solution to the inclusion of images making the isLoaded: false ? Node-lottie is otherwise working well for me, I cannot use puppeteer-lottie because it is too slow for my use case. I have tried using the inline images option, local images, remote images. I have played around with the code, it seems to me the CVImageElement.prototype.createContent which has been patched is not even getting fired, as I put a console log in it, both patched and unpatched.

galipmedia avatar Aug 15 '20 13:08 galipmedia

Feel free to play around with it and submit PRs if there are improvements that can be made.

friday avatar Aug 15 '20 15:08 friday

Fixed in https://github.com/friday/lottie-node/pull/14

razvanmitre avatar Mar 17 '21 14:03 razvanmitre

@razvanmitre thank you I cannot wait to try this!

galipmedia avatar Mar 18 '21 06:03 galipmedia

I have tested it and can confirm it is working! What a legend!

galipmedia avatar Mar 18 '21 06:03 galipmedia

Looking forward to this being merged, thanks

GDownes avatar Mar 30 '21 14:03 GDownes

I copied only the parts needed from @razvanmitre's PR to fix compatibility with recent Lottie-web (image loading was completely broken). Note that this issue originally had nothing to do with that. It may have fixed all or only some of the cases mentioned above.

friday avatar Apr 07 '21 12:04 friday