Moebits / waifu2x

waifu2x image upscaling in Node.js
MIT License
70 stars 11 forks source link

Using parallel frames makes gifs buggy #11

Closed Specy closed 3 years ago

Specy commented 3 years ago

EDIT: I'm using v0.4.3, i'll update and check if the issue is still there

When using parallelFrames to 1, the gif gets upscaled correctly and without issues, but if you set up a different value, say for example 5, some frames are "swapped"

Original:

someGif

example: (5 parallel frames)

someGif

example 2 (1 parallel frame)

someGif

Moebits commented 3 years ago

I think it should be fixed as of 0.6.1.

If you're interested, you can also find my GUI for Waifu2x here: https://github.com/Tenpi/Waifu2x-GUI

I actually don't know how you were able to correctly package it in electron, I had to manually set the waifu2xPath. Although there were a lot of versions since 0.4.3 I think the only breaking change is that I set cumulative to false for GIFs, because it breaks most of the GIFs I tried, but you can change it by setting the cumulative option. For upscaleImage it takes a new callback action, where if you return "stop" then it will kill the waifu2x-cpp child process.

Moebits commented 3 years ago

Oh, and you can remove ffprobe, because I just used regex for parseFramerate, parseDuration, and parseResolution. If you need that information, those functions are also public.

Specy commented 3 years ago

Mmmm i dont know why but v0.6.1 doesnt work for anything, upscaleImage doesnt upscale, upscaleGif errors out in some frames, video also errors out at encoding.

Also, did you change the parallelFrames from doing them in "chunks" to using semaphores? because i don't seem to see the "chunking" (aka frames get upscaled parallel and then it waits for all the other frames to finish before doing the next "chunk", semophore instead add a new frame being upscaled once one finishes with a max of N frames at a time, this is also much more efficient)

I can't really debug much as im not receiving any errors, it just doesnt save the file, only thing is that file paths are strange, from the output of upscaleImage() i get : C:\Users\dione\Desktop\up\8-2\/14fsfd.jpg while supplied is: C:\Users\dione\Desktop\up\8-2\14fsfd.jpg , to note that i dont use the output to read the file destination, i reuse the one i provide in the upscaleImage() function.

upscaleVideo() errors out as:

Error: ffmpeg exited with code 1: C:\Users\dione\Desktop\up\8-2\/videoFrames/upscaled/frame%d.png: No such file or directory
[1]
[1]     at ChildProcess.<anonymous> (C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\fluent-ffmpeg\lib\processor.js:182:22)
[1]     at ChildProcess.emit (events.js:315:20)

upscaleGif() errors out as:

[1] Error Error: ENOENT: no such file or directory, open 'C:\Users\dione\Desktop\up\8-2\someGifFrames\upscaled\frame0.jpg'
[1]     at Object.openSync (fs.js:466:3)
[1]     at Object.func [as openSync] (electron/js2c/asar_bundle.js:5:1812)
[1]     at syncFileToBuffer (C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\image-size\dist\index.js:71:27)
[1]     at Function.imageSize (C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\image-size\dist\index.js:101:24)
[1]     at C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\waifu2x\dist\waifu2x.js:284:51[1]     at new Promise (<anonymous>)
[1]     at C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\waifu2x\dist\waifu2x.js:283:35[1]     at step (C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\waifu2x\dist\waifu2x.js:33:23)
[1]     at Object.next (C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\waifu2x\dist\waifu2x.js:14:53)
[1]     at C:\Users\dione\Desktop\Progetti\electron\scapix\node_modules\waifu2x\dist\waifu2x.js:8:71 {[1]   errno: -4058,
[1]   syscall: 'open',
[1]   code: 'ENOENT',
[1]   path: 'C:\\Users\\dione\\Desktop\\up\\8-2\\someGifFrames\\upscaled\\frame0.jpg'
[1] }
[1] Error: ENOENT: no such file or directory, open 'C:\Users\dione\Desktop\up\8-2\someGifFrames\upscaled\frame0.jpg'
Moebits commented 3 years ago

upscaleImage doesnt upscale, upscaleGif errors out in some frames, video also errors out at encoding.

If you can provide the settings you are using it would be great, I changed some of the code in upscaleImage which every function depends on so the problem might be there.

Also, did you change the parallelFrames from doing them in "chunks" to using semaphores? because i don't seem to see the "chunking" (aka frames get upscaled parallel and then it waits for all the other frames to finish before doing the next "chunk", semophore instead add a new frame being upscaled once one finishes with a max of N frames at a time, this is also much more efficient)

I don't think there will be much of a difference, because when you start the conversions in parallel, they will also end at around the same time. If you really want to then open a pull request, because I have no idea how to use semaphore and there isn't a lot of documentation for it.

Specy commented 3 years ago

Nono dont worry, i was just wondering if u changed something because it felt "different".

upscaleImage options:

{ noise: 0, scale: 2 }

upscaleGif options:

{ noise: 0, scale: 2, speed: 1, parallelFrames: 5, cumulative: true }

upscaleVideo options:

 {
                quality: 0,
                noise: noiseLevel, //from UI, it's a int
                scale: scaleLevel, //from UI, it's a double
                ffmpegPath: "path/to/ffmpeg.exe",
                parallelFrames: 2
  }

all input and output paths are valid paths to files (all i did was update to v0.6.1 by the way, i havent changed any other code)

Moebits commented 3 years ago

Upgrade to the latest version, if you are still experiencing problems then open another issue, I don't really know what could be causing that bug. To me it sounds like the frame folder is being deleted before the function finishes executing, so make sure you aren't doing anything that leads to a confliction like upscaling the same two files to the same destination at the same time.