bloc97 / Anime4K

A High-Quality Real Time Upscaler for Anime Video
https://bloc97.github.io/Anime4K/
MIT License
17.98k stars 1.34k forks source link

How do I use this outside of realtime video playback? #228

Closed Sawtaytoes closed 4 months ago

Sawtaytoes commented 5 months ago

Is your feature request related to a problem? Please describe. I'm looking at the docs and only see them for realtime video playback with MPV and Plex.

I'd like to run this on some old DVDs and upscale with Anime4K-GAN. I find that while Real-ESRGAN looks better, it alters the colors and comes up with its own art style that doesn't match the original. Anime4K-GAN seems to upscale accurate to the source.

Since my source is a DVD, I'll need the 4.1 version as well.

Describe the solution you'd like I'd like to see docs detailing how I can do this upscale where I don't have to integrate with a player. My Plex server sits in a Linux Docker container, and I don't wanna overload my server CPU (no GPU nor IGP).

Describe alternatives you've considered

  1. Use another upscaler.
  2. Just watch the DVD as-is with whatever scaling my SHIELD or TV uses (yuck).

Additional context I bought Blu-rays of the original 3 Slayers episodes only to find that they used a horrible upscale.

While they're encoded with high-bitrate AVC, the DVDs have superior quality in a lot of ways. The Blu-rays are so blurry, I can't tell what's going on. I'd like to upscale the DVDs because it's also a distractingly low-res image, and subtitles are very blurry when blown up to 100" from a 480p source. I can move the lossless Blu-ray audio into the resulting MKV file after making an upscale. I'm hoping Anime4K-GAN can fix this for me.

Tama47 commented 5 months ago

There's Anime4K-GUI if you want a GUI, or you can use FFmpeg to manually apply the Anime4K shader. Replace 'custom_shader_path' with the shaders you want to use.

For CPU encoding:

ffmpeg -y -vsync 0 -i "input.mp4" -init_hw_device vulkan -vf format=yuv420p10,hwupload,libplacebo=w=3840:h=2160:upscaler=ewa_lanczos:custom_shader_path=shaders/Anime4K_ModeA.glsl,hwdownload,format=yuv420p10 "output.mp4"

For NVENC encoding:

ffmpeg -y -vsync 0 -i "input.mp4" -init_hw_device vulkan -vf format=yuv420p10,hwupload,libplacebo=w=3840:h=2160:upscaler=ewa_lanczos:custom_shader_path=shaders/Anime4K_ModeA.glsl,hwdownload,format=yuv420p10 -c:v hevc_nvenc -cq 24 -bf 5 -refs 5 -preset p7 "output.mp4"

My Plex server sits in a Linux Docker container, and I don't wanna overload my server CPU (no GPU nor IGP).

Are you going to use it with Plex? Just FYI, the Plex client app supports Anime4K, I've found this to be much more convenient and efficient than upscaling each episode individually.

Sawtaytoes commented 4 months ago

Plex Plugin

I'd rather upscale the episodes than use it with Plex. I'm not really sure how the Plex plugin works, but my server runs an Epyc 7313p, and it has no GPU nor native CPU encoder, so I like to avoid any encoding where possible.

And I'm sure I can't just install this plugin on my NVIDIA Shield right? So I'd rather just do it offline and always have the files at maximum quality.

GUI vs CLI

I think the CLI is the right way to go. You gave great commands there, and all I have to do is figure out which shader I wanna use.

The GUI is great though. Nice UI and lots of stuff built-in, but I'm not sure if the shaders include the 4.1 experimental low-res changes nor if they're the ones optimized for my NVIDIA RTX 3090. Not sure if the GPU-optimized shaders even matter when doing offline renders though.

Tama47 commented 4 months ago

I'd rather upscale the episodes than use it with Plex. I'm not really sure how the Plex plugin works, but my server runs an Epyc 7313p, and it has no GPU nor native CPU encoder, so I like to avoid any encoding where possible.

I run my Plex server on a DS923+, which doesn't have a GPU either. The upscaling is done on the client side (Plex app), just like the mpv app.

And I'm sure I can't just install this plugin on my NVIDIA Shield right? So I'd rather just do it offline and always have the files at maximum quality.

I'm pretty sure you could install mpv on NVIDIA Shield since it runs Android. But I'm not sure if it will be able to handle anything higher then the fast shaders. Also, doesn't the NVIDIA Shield also have its own upscaling built-in?

I think the CLI is the right way to go. You gave great commands there, and all I have to do is figure out which shader I wanna use.

Yes, I think it will fit your use case the most. If your goal is to use it outside of real-time video playback.

The GUI is great though. Nice UI and lots of stuff built-in, but I'm not sure if the shaders include the 4.1 experimental low-res changes nor if they're the ones optimized for my NVIDIA RTX 3090. Not sure if the GPU-optimized shaders even matter when doing offline renders though.

They're using the exact same preset as the mpv config, just consolidated. The shaders are not "optimized for" any specific GPU. The Mode A (Fast) preset, for example, mainly uses the Restore (M) shader with other shaders chained together, while Mode A (HQ) uses the VL shader instead of the M shader. This is to make sure that your GPU can keep up with real-time upscaling. So it doesn't matter for post-processing, you can even use higher quality shaders if you want.

Example Mode A (Fast): Optimized for lower-end GPU
glsl-shaders="~~/shaders/Anime4K_Clamp_Highlights.glsl;~~/shaders/Anime4K_Restore_CNN_M.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_M.glsl;~~/shaders/Anime4K_AutoDownscalePre_x2.glsl;~~/shaders/Anime4K_AutoDownscalePre_x4.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_S.glsl"
Mode A (HQ): Optimized for higher-end GPU
glsl-shaders="~~/shaders/Anime4K_Clamp_Highlights.glsl;~~/shaders/Anime4K_Restore_CNN_VL.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_VL.glsl;~~/shaders/Anime4K_AutoDownscalePre_x2.glsl;~~/shaders/Anime4K_AutoDownscalePre_x4.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_M.glsl"
Sawtaytoes commented 4 months ago

Thanks!

Where'd you get that Anime4K_ModeA.glsl file in the ffmpeg script?

I was hoping to download 4.1 (better for low-res?) and run that on this show since it's 480p, but I can't find any downloads for 4.1 with the Mode A shader.


I'd prefer to use Plex since all my anime is hosted on my NAS and viewed through Plex.

My NVIDIA Shield does have an AI upscaler built-in, and it sucks really bad. Too much posterization and artificial sharpening. It's never looked good to me. There's also an "Enhanced", but in my testing, I find that it looks best on "Basic".

In your FFMPEG script, any reason for using yuv420p10 format with 10-bit colors rather than 8-bit colors?


This list is for MPV right? So that won't work for FFMPEG? Or does it work for FFMPEG, and I just used it wrong?

glsl-shaders="~~/shaders/Anime4K_Clamp_Highlights.glsl;~~/shaders/Anime4K_Restore_CNN_VL.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_VL.glsl;~~/shaders/Anime4K_AutoDownscalePre_x2.glsl;~~/shaders/Anime4K_AutoDownscalePre_x4.glsl;~~/shaders/Anime4K_Upscale_CNN_x2_M.glsl"
Tama47 commented 4 months ago

Where'd you get that Anime4K_ModeA.glsl file in the ffmpeg script?

This list is for MPV right? So that won't work for FFMPEG? Or does it work for FFMPEG, and I just used it wrong?

Yes, the chain is for mpv only. I got the shaders from Anime4K-GUI, as it's essentially the same preset as mpv. Just easier to use with FFmpeg because it's a single GLSL file.

I was hoping to download 4.1 (better for low-res?) and run that on this show since it's 480p, but I can't find any downloads for 4.1 with the Mode A shader.

I'm not sure what you mean by "4.1", do you mean v4.0.1 release? That's just the latest release. If you want shaders for 480p, then use Mode C. Since sharpening might be too strong for Mode A or B. Check out the Advanced Guide.

In your FFMPEG script, any reason for using yuv420p10 format with 10-bit colors rather than 8-bit colors?

https://yukisubs.files.wordpress.com/2016/10/why_does_10bit_save_bandwidth_-_ateme.pdf

I'd prefer to use Plex since all my anime is hosted on my NAS and viewed through Plex.

Then my suggestion is to install mpv and try running Anime4K on the NVIDIA Shield. If not, the next best solution is to hook up a computer to the TV and run Plex HTPC with Anime4K. The Plex app runs exactly like the TV app, and you can even pair a remote to control it like a normal TV.

Screenshot 2024-02-02 at 01 13 50

Sawtaytoes commented 4 months ago

Thanks for your help!

Justieku commented 4 months ago

There's Anime4K-GUI if you want a GUI, or you can use FFmpeg to manually apply the Anime4K shader. Replace 'custom_shader_path' with the shaders you want to use.

For CPU encoding:

ffmpeg -y -vsync 0 -i "input.mp4" -init_hw_device vulkan -vf format=yuv420p10,hwupload,libplacebo=w=3840:h=2160:upscaler=ewa_lanczos:custom_shader_path=shaders/Anime4K_ModeA.glsl,hwdownload,format=yuv420p10 "output.mp4"

For NVENC encoding:

ffmpeg -y -vsync 0 -i "input.mp4" -init_hw_device vulkan -vf format=yuv420p10,hwupload,libplacebo=w=3840:h=2160:upscaler=ewa_lanczos:custom_shader_path=shaders/Anime4K_ModeA.glsl,hwdownload,format=yuv420p10 -c:v hevc_nvenc -cq 24 -bf 5 -refs 5 -preset p7 "output.mp4"

My Plex server sits in a Linux Docker container, and I don't wanna overload my server CPU (no GPU nor IGP).

Are you going to use it with Plex? Just FYI, the Plex client app supports Anime4K, I've found this to be much more convenient and efficient than upscaling each episode individually.

I get the error bellow with i5-8500 CPU (by CPU encoding you mean only cpu encoding or its GPU on board graphics as well?). Seems like GPU is needed and in my case it is UHD 630 graphics (vulkaninfo works and ffmpeg -init_hw_device list shows vulkan in list). Another pc where there are CPU i7-9700 (without UHD graphics) and GPU 3070 ti it works great with the same .mkv video and shaders... Both OS are Windows.

=> ffmpeg -y -vsync 0 -i "m06.mkv" -init_hw_device vulkan -vf format=yuv420p,hwupload,libplacebo=w=3840:h=2160:upscaler=ewa_lanczos:custom_shader_path=Anime4K_ModeA+A.glsl,hwdownload,format=yuv420p "m06_out.mkv"

[hwupload @ 0000023bff6c7640] A hardware device reference is required to upload frames to. [Parsed_hwupload_1 @ 0000023bfc56fac0] Query format failed for 'Parsed_hwupload_1': Invalid argument Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 [libvorbis @ 0000023bfc5a3080] 39 frames left in the queue on closing Conversion failed!