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

5MB image take time almost 20 sec in AWS Lambda function #17

Open
bhandurejitu opened this issue Sep 1, 2021 · 3 comments
Open

5MB image take time almost 20 sec in AWS Lambda function #17

bhandurejitu opened this issue Sep 1, 2021 · 3 comments
Labels
question Further information is requested

Comments

@bhandurejitu
Copy link

I am trying to convert heic image into jpeg.

1 => take image from s3 bucket.
2 => convert image ( quality => 0.35)
3 => save converted image on s3 bucket.

it takes almost 20+ sec for the whole process.

is there any way to reduce this time?

@catdad catdad added the question Further information is requested label Sep 1, 2021
@catdad
Copy link
Member

catdad commented Sep 1, 2021

So let's break this down a little bit and hopefully this info will help:

First, it seems you are talking about timing an operation where only part of it is affected by this library. You are not really telling me whether this library is the problem, whether some other part of your function is the problem, or whether something about Lamba itself is a problem. I will really only attempt to help with issues using this library, as this is not the right forum for general software advice. Can you please make sure you are timing only using this library and provide that information?

Second, the size of the image alone is not super helpful. The size of the HEIC file itself and the size of the compressed content that is stored inside the HEIC can vary significantly based on many variables. The data that you are decoding is what is important. Would you be able to provide an example file that you are debugging this problem with?

Finally, this library is very likely solving a different problem than what you are solving. There are many ways to convert a HEIC image to another format. This library tries to solve the problem by converting the image in JavaScript, for users who are limited to using JavaScript. It does not try to solve the problem of converting it as fast as possible for users who do not have technology limitations. Since you are running in Lambda, you can use pretty much any tool. It might be best to find the tool that tries to solve the problem the fastest rather than a tool that is most convenient due to solving the problem with only JavaScript.

@jalik
Copy link

jalik commented Oct 23, 2021

Indeed, using a native tool to convert instead of JS is a good idea.

For example this command converts from HEIC to JPG:
heif-convert sample1.heic sample1.jpg

In JS, you could do something like:

import { spawn } from 'child_process';

function convertHEIF(input, output) {
  return new Promise((resolve, reject) => {
    const cmd = spawn(
      'heif-convert',
      [input, output],
      { cwd: process.cwd() },
    );
    let hasFailed = false;
    cmd.stderr.on('data', (buffer) => {
      hasFailed = true;
      reject(new Error(buffer.toString()));
    });
    cmd.on('error', (error) => {
      hasFailed = true;
      reject(error);
    });
    cmd.on('close', (errCode) => {
      if (!hasFailed) {
        resolve(errCode);
      }
    });
  });
}

convertHEIF('sample1.heic', 'sample1.sample1.jpg')
  .then(() => {
    // conversion done
  })
  .catch((err) => {
    console.error(err.message);
  });

Of course you need to install the program (ex on Ubuntu):
apt install libheif-examples

@youngvo
Copy link

youngvo commented Dec 1, 2023

@bhandurejitu I'm working on a Lambda function to convert heic images to jpeg. I got some troubles with the convention. Could you please post here your implementation code? I did try several ways, but it doesn't work at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants