Moebits/waifu2x

New feature for upscaleGif

Closed this issue · 20 comments

Specy commented

Add callback function to upscaleGif that gets executed whenever a frame finished getting upscaled, which passes as arguments the current frame and the number of frames total

something like:

let callback = (current,total)=>{
    console.log("Done:" current + " out of "+total) 
}
Waifu2x.upscaleGif(path,endPath,options, callback)

Ok, please upgrade to v0.2.3. I also remove the frame folder for you if it already exists so you don't need to do that yourself.

Specy commented

By the way, i've noticed that the encoding takes more time than the upscaling of the images, with a 80 frames gif it takes around 40 seconds to upscale and then 5/6 minutes to encode, is this normal?

Also i was thinking of adding some sort of "stop" variable passed by reference that could be then checked by the upscaleGif function to stop the upscaling of the images, could be part of the options because as for now, once the function is executed, you must wait for it to end.

Sorry, do you mean that upscaling all the images takes 5 minutes, or the actual creation of the gif takes 5 minutes? The progress callback is executed after each frame is upscaled. But the creation of the gif after all the frames are done happens almost instantly.

The way I implemented it was to return true in the callback to stop the upscaling early. But let me know if you would prefer the option.

let progress = (current: number, total: number) => {
        console.log(`Current Frame: ${current} Total Frames: ${total}`)
        if (current === 2) return true
}
Specy commented

I mean the gif encoding (creation of the gif), i've tested that out and it took way more time, i'll make a video later to show you, also, no it doesn't matter that it's inside of the option, i didnt see that the callback also had that functionality, that's way more than enough and i'm gonna use it.

EDIT: Ok i guess it was just that moment as i did it again and it took +-10 seconds to encode

I added that callback functionality recently, so make sure you are on 0.2.4.

Specy commented

Yes I'm on 0.2.3 now, I'll add a "cancel" functionality in next version.

Specy commented

What about adding support for which model to use for the upscale? the cpp waifu2x allows for you to chose which model to use, the library could have a public proprety which has the name of the current available models in the default path something like:

waifu2x.models = [ "/path/to/model/model1.json", "/path/to/model/model2.json"]

and then in the upscaling options you can specify which model path to use (using absolute paths so an user could specify their own)
this way the library is not limited to what is in the default (which should be anime) and has more flexibility on what to use

What about adding support for which model to use for the upscale? the cpp waifu2x allows for you to chose which model to use, the library could have a public proprety which has the name of the current available models in the default path

The C++ version doesn't let you pick individual models, it just accepts a directory. Nevertheless, I included the rest of the cpp options in the new version 0.2.5. See the readme for the updated options.

Specy commented

so wait, this is a whole model right?
If i wanted to use a different model i'd have to , for example, set one of those directory names as the value of modelDir right?

so wait, this is a whole model right?
If i wanted to use a different model i'd have to , for example, set one of those directory names as the value of modelDir right?

Yes.

Specy commented

Ok thanks a lot,I'll see what I can do. Also I'm glad we both managed to make our projects better together

Specy commented

I'm trying to find different models but just for clarification, the waifu2x-cpp lib only supports the vgg models? so in case, i'd have to use those and i can't use those right? do you know of more places where to get models?

If you want more then you'd have to train your own models:
https://github.com/nagadomi/waifu2x#train-your-own-model

You need to be on Linux to use the original waifu2x. If you need help with that, it's better to ask on their repo not mine.

Specy commented

Yea I don't think I would go through the steps to create my own model, was just asking if you knew already existing ones, I've tried some but the only ones working are the RGB and Photo ones

Yea I don't think I would go through the steps to create my own model, was just asking if you knew already existing ones, I've tried some but the only ones working are the RGB and Photo ones

No I don't, sorry.

Specy commented

To allow for lower size, gifs use transparency and then stack the previous frame with the next one and then when displayed they are layered on top of each other, i went to search for a solution and found this (look down the example), it says about something called "coalescing", i went to look at the module you are currently using to extract gif data (gif-frames) and it looks like it has this option as a boolean, "cumulative".
Turning this on will cause an increase in file size but will prevent issues with upscaling images, it should either be on by default or made an option for gif upscale

Example of a gif upscaled without the "cumulative" option:
test

Example of one with the "cumulative" option turned on (used by first decompressing the gif, i haven't tested if gif-frames outputs the same result)
ezgif-4-488cb1d7a8fe

Also, should i make a new issue for every enchancement / issue i find or i can keep writing in this?

Also, should i make a new issue for every enchancement / issue i find or i can keep writing in this?

Make a new issue. But not for this one, I already set cumulative to true in v0.2.7. If you're interested, I was going to add support for videos by using ffmpeg to extract and re-encode the frames. But since upscaling GIFs is bad enough, I'm not sure how feasible that would be.

Specy commented

In what way is it bad? Also, yes I'm interested as I also was thinking of adding video upscale.

Okay, you can upscale videos starting with v0.2.8. See this example usage. You need to have ffmpeg installed.

await waifu2x.upscaleVideo("./videos/video.mp4", "./videos/video2x.mp4", {framerate: 24, quality: 16, speed: 1, 
reverse: false}, progress)

Also setting scale to 1 will skip upscaling entirely this time. I haven't had the time to actually upscale a video, but it "should" work.