Anime4K icon indicating copy to clipboard operation
Anime4K copied to clipboard

Not using the GPU

Open arthurwolf opened this issue 4 years ago • 15 comments

Hello.

Using the 3.0 shaders, it's not using my GPU but using all of the cores on my CPU. Somebody on reddit suggested using a previous version ( 2.1 or earlier ) would solve this issue. Is that correct, and is there any way I can get the latest version to work GPU-powered? Is this an Anime4K issue, or do I need to look into mpv instead?

Thanks a lot!

arthurwolf avatar May 23 '20 17:05 arthurwolf

How does your MPV config look like? Are you using the gpu-hq profile?

ThoughtfulDev avatar May 24 '20 10:05 ThoughtfulDev

Only thing that's not a comment in my config is: autofit-larger=90%x90% So pretty much defaults.

I have tried enabling the gpu-hq profile, and it changed nothing. Should I expect it to?

On Sun, May 24, 2020 at 12:12 PM ThoughtfulDev [email protected] wrote:

How does your MPV config look like? Are you using the gpu-hq profile?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bloc97/Anime4K/issues/89#issuecomment-633208478, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2SFK34ASPKGIGDCYIU3TRTDXJVANCNFSM4NIREQYQ .

--

勇気とユーモア

arthurwolf avatar May 24 '20 10:05 arthurwolf

Assuming you're on Windows-- what do the CPU and GPU tabs of Task Manager look like when playing video with and without the shaders? How's video playback in MPV with and without the shaders? If you play a video in MPV from the command line, does it give you any funny error messages?

I feel like this is more likely to be a case of something else in the background eating a ton of your CPU while playing videos, and possibly when not playing videos too. Or just MPV being too CPU-heavy for whatever you're running it on.

(Sorry if that comes across as presumptuous-- it's just that Anime4K is written in GLSL shader code, which, broadly speaking, can't just run on the CPU. I also just can't reproduce the scenario you're describing.)

dixie-flatliner avatar May 26 '20 18:05 dixie-flatliner

It's on linux. I'm using mpv not to do playback, but to convert a file using the shaders ( I have a whole lot of anime clips I need to render, and some of them have bad quality and running them through Anime4k makes things less bad/ugly ).

I can't just play the file with mpv it's processing at like 0.4 fps ( I'm using 5 shaders, following recommendations for anime upscaling ) so it just skips very hard. It takes hours to convert minutes of anime at this rate.

If I look at CPU usage ( linux ), I've got all 12 cores at full ( used by this, nothing else, I made sure. Wouldn't waste your time if it was this easy. ), and about 2% of GPU in use.

Here's the command I use:

nice -19 mpv /ram/prepared.mp4 --glsl-shader=~/.config/mpv/shaders/Anime4K_3.0_Upscale_CNN_M_x2_Denoise.glsl --glsl-shader=~/.config/mpv/shaders/Anime4K_3.0_Auto_Downscale_Pre_x4.glsl --glsl-shader=~/.config/mpv/shaders/Anime4K_3.0_Deblur_DoG.glsl --glsl-shader=~/.config/mpv/shaders/Anime4K_3.0_DarkLines_HQ.glsl --glsl-shader=~/.config/mpv/shaders/Anime4K_3.0_ThinLines_HQ.glsl --glsl-shader=~/.config/mpv/shaders/Anime4K_3.0_Upscale_CNN_M_x2_Deblur.glsl --vf=gpu="w=3840:h=2160" --o=/ram/upscale-2cq28f.mp4

On Tue, May 26, 2020 at 8:35 PM dixie-flatliner [email protected] wrote:

Assuming you're on Windows-- what do the CPU and GPU tabs of Task Manager look like when playing video with and without the shaders? How's video playback in MPV with and without the shaders? If you play a video in MPV from the command line, does it give you any funny error messages?

I feel like this is more likely to be a case of something else in the background eating a ton of your CPU while playing videos, and possibly when not playing videos too. Or just MPV being too CPU-heavy for whatever you're running it on.

(Sorry if that comes across as presumptuous-- it's just that Anime4K is written in GLSL shader code, which, broadly speaking, can't just run on the CPU. I also just can't reproduce the scenario you're describing.)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bloc97/Anime4K/issues/89#issuecomment-634202483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2SFJ2O2CTFP7EVANBFMTRTQDYJANCNFSM4NIREQYQ .

--

勇気とユーモア

arthurwolf avatar May 26 '20 18:05 arthurwolf

@arthurwolf What GPU do you have? Anything less than an GTX 1060 or RX 570 would have trouble running all 5 shaders together. It might work if you omit the last upscale (use the extremely fast Upscale_DoG or Upscale_Original) and use faster versions of DarkLines/ThinLines.

bloc97 avatar May 26 '20 18:05 bloc97

GeForce GTX 960

The issue is the nvidia-settings app tells me while the command is running, my GPU utilization is 2%... So it doesn't sound like it's over-using the GPU...

On Tue, May 26, 2020 at 8:51 PM bloc97 [email protected] wrote:

@arthurwolf https://github.com/arthurwolf What GPU do you have? Anything less than an GTX 1060 or RX 570 would have trouble running all 5 shaders together. It might work if you omit the last upscale (use the extremely fast Upscale_DoG or Upscale_Original) and use faster versions of DarkLines/ThinLines.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bloc97/Anime4K/issues/89#issuecomment-634210522, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2SFK7BTYDXVLQGOILJH3RTQFSXANCNFSM4NIREQYQ .

--

勇気とユーモア

arthurwolf avatar May 26 '20 19:05 arthurwolf

--vf=gpu="w=3840:h=2160" --o=/ram/upscale-2cq28f.mp4

Ooooh, you're outputting the filtered video-- that makes a huge difference! When you output a filtered video from MPV, MPV has to re-encode the video after rendering it. Unfortunately there's no real way around this-- the encoding process happens after shaders like Anime4K are applied anyway, and if you're getting 0.4FPS with the shaders you'll probably still get 0.4FPS without them.

MPV does seem to have some options for customizing the encoding process (https://mpv.io/manual/master/#encoding), but that's far beyond the scope of Anime4K. (Or my knowledge as a random user, sorry. :( )

dixie-flatliner avatar May 26 '20 20:05 dixie-flatliner

@arthurwolf If your GPU doesn't have enough shader cores for a single pass of the shader or does not have enough memory, the GPU might be starved and be under-utilized. Have you tried each shader individually? If they run very fast (sub 10ms), it might be resource starvation.

Or it might be what dixie-flatliner pointed out: slow encoding.

bloc97 avatar May 26 '20 20:05 bloc97

Ah. Thanks for explaining. Any way I can use the shaders outside of mpv ( like, say ffmpeg ), or any way I can improve this situation in any way you can think of?

On Tue, May 26, 2020 at 10:17 PM dixie-flatliner [email protected] wrote:

--vf=gpu="w=3840:h=2160" --o=/ram/upscale-2cq28f.mp4

Ooooh, you're outputting the filtered video-- that makes a huge difference! When you output a filtered video from MPV, MPV has to re-encode the video after rendering it. Unfortunately there's no real way around this-- the encoding process happens after shaders like Anime4K are applied anyway, and is just a glacially slow process regardless.

MPV does seem to have some options for customizing the encoding process ( https://mpv.io/manual/master/#encoding), but that's far beyond the scope of Anime4K. (Or my knowledge as a random user, sorry. :( )

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bloc97/Anime4K/issues/89#issuecomment-634255821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2SFJTLHPB5TKNPJ3NEQDRTQPVBANCNFSM4NIREQYQ .

--

勇気とユーモア

arthurwolf avatar May 26 '20 20:05 arthurwolf

well, your problem here is just that x264 is CPU-only, so it'd be slow regardless of where you use it from. Since you're on Linux, mpv is probably just calling your system's copy of ffmpeg for this anyway, which is in turn probably just calling your system's copy of x264-- so I doubt you'd get any better performance from calling ffmpeg or x264 directly even if you could use the shaders with them.

You could try using a faster x264 encoding preset (will need to look into this on your own), or possibly try getting MPV/ffmpeg/whatever's actually running to use your GTX960's NVENC encoder. Unfortunately those are the limits of my knowledge on the subject.

dixie-flatliner avatar May 26 '20 20:05 dixie-flatliner

I tried 5 different --ovc outputs, including lossless ones ( exporting to a ramdisk so disk write isn't a choke point ), and they all output at the same speed, so encoding isn't the issue I think this shows.

Also, I have 5 shaders enabled. If I start disabling them one by ones, things get faster and faster ( 0.6fps with 5 enabled, 3.3fps with just the first one enabled ). But still, very low GPU usage, and full usage of all 12 CPU cores.

On Tue, May 26, 2020 at 10:27 PM dixie-flatliner [email protected] wrote:

well, your problem here is just that x264 is slow, so it'd be slow regardless of where you use it from. Since you're on Linux, mpv is probably just calling your system's copy of ffmpeg for this anyway, so I doubt calling it directly will change anything.

You could try using a faster x264 encoding preset (will need to look into this on your own), or possibly try getting MPV/ffmpeg/whatever's actually running to use your GTX960's NVENC encoder. Unfortunately those are the limits of my knowledge on the subject.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bloc97/Anime4K/issues/89#issuecomment-634260564, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2SFJFQB2VC2AB4IUSVYLRTQQ3BANCNFSM4NIREQYQ .

--

勇気とユーモア

arthurwolf avatar May 26 '20 20:05 arthurwolf

Hey @arthurwolf i made a tool which encodes the video with mpv: https://github.com/ThoughtfulDev/Anime4K It also has a selection to encode with nvenv directly on the GPU (which is way faster). Otherwise encoding always envolves the CPU (you can only do x264 4:4:4) - reencode to x265 4:2:0 if necessary.

ThoughtfulDev avatar May 27 '20 17:05 ThoughtfulDev

Thanks, it's the first thing I tried, before even trying mpv --o, and after 3 hours of hell trying to get it to compile I just gave up, it was issue after issue after issue unfortunately.

On Wed, May 27, 2020 at 7:23 PM ThoughtfulDev [email protected] wrote:

Hey @arthurwolf https://github.com/arthurwolf i made a tool which encodes the video with mpv: https://github.com/ThoughtfulDev/Anime4K It also has a selection to encode with nvenv directly on the GPU (which is way faster). Otherwise encoding always envolves the CPU (you can only do x264 4:4:4) - reencode to x265 4:2:0 if necessary.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bloc97/Anime4K/issues/89#issuecomment-634816962, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2SFPZI2BBZMXTHU7HIKLRTVEALANCNFSM4NIREQYQ .

--

勇気とユーモア

arthurwolf avatar May 27 '20 17:05 arthurwolf

What do you need to compile? There is a ppa for ubuntu called mpv-test that has the latest mpv version.

ThoughtfulDev avatar May 29 '20 17:05 ThoughtfulDev

I'm not running Ubuntu, I'm running Debian, and the ppa didn't work

On Fri, May 29, 2020 at 7:13 PM ThoughtfulDev [email protected] wrote:

What do you need to compile? There is a ppa for ubuntu called mpv-test that has the latest mpv version.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bloc97/Anime4K/issues/89#issuecomment-636085935, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2SFLYG47WH72PG2JC7YLRT7UKNANCNFSM4NIREQYQ .

--

勇気とユーモア

arthurwolf avatar Jun 16 '20 10:06 arthurwolf