video2x icon indicating copy to clipboard operation
video2x copied to clipboard

Feature: pause work

Open AlvaroBeiro opened this issue 5 years ago • 18 comments

I'm trying to convert a 20 minute video from 576p to 1080p. I'm using cuda and it says it will take 14 hours. I don't like to have my computer working at 100% for such a long time, that's why I would like to have some kind of pause/resume. It could work just by pausing the script or by comparing two folders and seeing where it stopped upscaling, and restarting from there.

AlvaroBeiro avatar Mar 28 '19 14:03 AlvaroBeiro

waifu2x controls the upscaling process, so video2x can't really interviene with the upscaling process. Something major has to be changed in order for this to be possible.

k4yt3x avatar Mar 28 '19 15:03 k4yt3x

completed_command = subprocess.run(execute, check=True) completed_command = subprocess.Popen(execute, check=True) With p=psutil.Process(completed_command) it may be possible to halt the thread's execution with p.suspend() and followed up with p.resume().
Otherwise waifu2x's may allow for popen.communicate() and may have functions ready to handle a pause.

Windows CMD/Powershell has built pause and resume. Pause = pause/break key and resume = space bar Linux I believe its CRTL+Z to pause and I believe resume is typing in fg.
So you can manually pause it, but you will get no indication from cmd, powershell, or a terminal. Just don't close it.
When paused the usage will drop to 0% and the ram will dump the program state into storage and wait until it gets resumed and then reallocate ram and other resources.

Potential implementation is to throw an exception from keyboard interrupts and have them be caught and perform the pause/resume functionality.

What Alvaro Beiro is describing to me sounds like quitting the program and resuming from a save state.

dtgraham9 avatar Mar 30 '19 04:03 dtgraham9

What Alvaro Beiro is describing to me sounds like quitting the program and resuming from a save state.

That's what I was thinking as well, but it sounds pretty hard to implement. If it's simply pause and resume without exiting, then I think it's more viable.

k4yt3x avatar Mar 30 '19 18:03 k4yt3x

You should be able to create something simple as a txt file with "1172/123212 frames progressed" If you load the txt file then it will just continue with 1173?

rasm685p avatar Mar 31 '19 21:03 rasm685p

You should be able to create something simple as a txt file with "1172/123212 frames progressed" If you load the txt file then it will just continue with 1173?

Video2X does not control the progress,waifu2x does. Yes, video2x can count how many frames have been upscaled, but now I need to find out how to make waifu2x stop its job gracefully and such.

k4yt3x avatar Mar 31 '19 21:03 k4yt3x

k4yt3x from my understanding of your code you pass the entire temp frame directory to waifu2x, right? If that's the case rasm685p, there is so code aside to send individual files/ smaller broken up temp directories.

If the code was reworked to send individual frames to be upscaled by wiafu2x instead of an entire directory, yes it could be possible to create a txt file with start frame number, but no system is in place for that. I would like to work on that, but my hands are tied up with work. As summer approaches I should be able to contribute to this repo.

The other option is see if waifu2x is open to receive stdin signals, and how it handles them. Unfortunately, I don't have the time to see if waifu2x has this functionality built into it.

If anything I said was wrong about your code k4yt3x please feel free to reply and correct me. I went through most of your code in a few hours and got a rough overview of the systems.

dtgraham9 avatar Apr 01 '19 02:04 dtgraham9

@dtgraham9 as mentioned in #11, processing individual frames greatly reduce the efficiency of upscaling. I'm curious to see if I can stop waifu2x gracefully, but unfortunately that has to happen after my exam weeks.

k4yt3x avatar Apr 01 '19 03:04 k4yt3x

@k4yt3x I'll put some time into looking into it as well when I get time too, good luck on exams. Mine aren't for a while. My C++ skills are quite rusty.

waifu2x-converter-cpp atleast has a discord server so questions are easier to ask.

dtgraham9 avatar Apr 01 '19 03:04 dtgraham9

@dtgraham9 you have my appreciation. Thanks for helping out. waifu2x-converter-cpp developers are quite engaging in issues opened, and are actively making changes and improvements. If we do need something specific, I think they might be happy to help.

Wish the exams are over quicker so I can work on my own stuff.

k4yt3x avatar Apr 01 '19 04:04 k4yt3x

On this topic, I was able to simply pause and resume the waifu2x process from resmon. That's some progress I guess.

image

k4yt3x avatar Apr 28 '19 23:04 k4yt3x

@k4yt3x You may want to take a look at the CMD Tools from Systeminternals, the PS Tools Collection may has something you could implement simply by doing a cmd call. This for Example should do the Job > https://docs.microsoft.com/en-us/sysinternals/downloads/pssuspend Otherwise you could also set the Priority of the Process to "Idle" which would end in a similar Result.

DJPlaya avatar Jun 30 '19 18:06 DJPlaya

@DJPlaya thanks for the suggestions. I would like to be able to use python to do a native API call, or use a C library to call the Windows API, instead of executing a shell command. If all of that don't work out, maybe I can then consider cmd calls.

k4yt3x avatar Jul 04 '19 03:07 k4yt3x

I tried pausing and resuming (both the waifu2x and python processes since python continued to use significant CPU usage with waifu2x being paused) and when I tried to resume it ended up crashing and deleting all of the images/folders in the temp folder. I assumed if anything would happen I could just restart the waifu2x-caffe process using the same input/output paths.

Unfortunate because I was 48 hours into a week long conversion.

hart0 avatar Jul 23 '19 19:07 hart0

Didn't read the thread, but the app and/or dependent processes should be able to be suspended by Process Explorer. Maybe just mark all of them together and via RBM press suspend.

deton24 avatar Nov 16 '19 18:11 deton24

I see Video2x can divide the task over more than 1 process. Why not implement a way to send chunks of image at a time? Like a queue with chunks of 500 or 1000 images (user defined). If the user decide to pause, than queue pauses at the end of the current chunk.

I also find 12 to 20 hours to upscale a lot of time. And it's common to just need to use the PC at some point. If I can create chunks that last 15 minutes, this should be perfect as it'll put the work on hold.

tamodolo avatar Jun 10 '20 20:06 tamodolo

@tamodolo Dandere2x is using the approach you described, but I'm trying to consider a different approach that doesn't require chunking. I want the upscaling to stop when I click stop.

I'm already working on that, but it's more complicated than that. I want a zip bundle to be created when the upscaling stops.

k4yt3x avatar Jun 11 '20 03:06 k4yt3x

I didn't know dandere2x has that as it don't work here for some reason.

It's just a sugestion but the method I sugested seems easy enough to implement as I see some of the behaviors necessary already there and it's good enough to solve the problem for now. Your method could be implemented without hury then as it's complicated.

tamodolo avatar Jun 11 '20 12:06 tamodolo

it would be nice if we had 2 pause buttons. 1 for pause the actuall process (that what you are at looking atm how to do it) 2 to pause the quarry (what you could already implement? because you dont have to pause the actual upsampling)

Xyz00777 avatar Jun 11 '20 22:06 Xyz00777