bloc97 / Anime4K

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

Encoder #77

Open aaronth07 opened 4 years ago

aaronth07 commented 4 years ago

I have no interest in real time encoding, yet a encoder to re-encode anime in an upscaled would be extremely useful. Is there a way to do this with Anime4k?

TianZerL commented 4 years ago

Try this. https://github.com/TianZerL/Anime4KCPP Witch have a GUI and support GPU acceleration

ThoughtfulDev commented 4 years ago

Hey, i had the same problem. Here is what i did.

  1. Compile the newest mpv version
  2. encode the file using mpv with the shaders (sadly only x264 but you can convert to x265 after the fact) keep in mind that the next step will loose audio or subs so you have to mux the manually using for example mknixtools.
  3. mpv --vf=format=yuv420p input.mkv --vf=gpu="w=3840:h=2160" --glsl-shaders=~/Anime4K_Hybrid_v2.1a_L.glsl --ovc=libx264 --ovcopts="preset=slow:tune=animation:crf=18" --o=shader.mkv this outputs a 4k file (you can change the width and height) of the input. Please change your shader paths and such.
bloc97 commented 4 years ago

@ThoughtfulDev May I ask which options did you use for the compilation and what OS you are on? The default official build for windows does not support -vf=gpu...

ThoughtfulDev commented 4 years ago

@bloc97 yes i noticed that windows does not work. I am using POP OS (Ubuntu basically) and added the mpv ppa (http://ppa.launchpad.net/mc3man/mpv-tests/ubuntu) I didn't compile from source (sorry :D). But i am sure its in the official build from 0.31 onward on Linux at least. The -vf=gpu option is only available on Linux afaik.

This is the mpv version output (0.32 has no bugs for me): mpv 0.32.0 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects built on Sat Apr 4 05:54:47 UTC 2020 ffmpeg library versions: libavutil 56.31.100 libavcodec 58.54.100 libavformat 58.29.100 libswscale 5.5.100 libavfilter 7.57.100 libswresample 3.5.100 ffmpeg version: 4.2.2

The new filters Ver 3 (the single filters) all work also flawlessly and also when chained.

I havent been able to encode to x265 directly with MPV thought since i get a error about not support 4:4:4. I am not that good with encoding so i just left it at x264 and encode with ffmpeg after upscaling. If you are interested i am currently writing a python script with uses the currently up to date V3 of your shaders. It extracts the audio, subs of a file, scales it, then adds the audio and subs back and then converts it back to x265 if desired. But it still needs some work.

Edit: here is the commit which adds the gpu filter: https://github.com/mpv-player/mpv/commit/90df6c79c9400d3f1c711ef5696324908a5126ce

bloc97 commented 4 years ago

@ThoughtfulDev I see... I'm currently deciding if I am going to do a full Tensorflow+ffmpeg+Python port of Anime4K for easier use in non-real time applications, and I'm not entirely confident that mpv will introduce gpu encoding for all platforms. I guess I will simply start working on the port first and see from there...

ThoughtfulDev commented 4 years ago

@bloc97 seems like a good Idea. With the keras implementation in tensorflow integrated this shoulnt be that complicated instead of pure tensorflow (god i hate that).

Good luck. Looking forward to that.

NightMachinery commented 4 years ago

@ThoughtfulDev Do share your script! BTW, what does vf=gpu.. do? If I am on a CPU-only laptop, is that even needed?

ThoughtfulDev commented 4 years ago

@NightMachinary i am not ready yet. I have to do some tests still. You need to use the vf=gpu option since the shaders need to be rendered on the GPU. Thats why you need mpv >= 0.32 since if you want to transcode the shader run on the gpu and then encode on cpu (x264 yuv444 - needs reencoding after that to x265 with ffmpeg to yuv420) or encoding on gpu nvenc(x265 already yuv420).

ThoughtfulDev commented 4 years ago

@bloc97 and @NightMachinary i just published my repository with the scripts: https://github.com/ThoughtfulDev/Anime4K

ducomeon commented 3 years ago

@ThoughtfulDev I see... I'm currently deciding if I am going to do a full Tensorflow+ffmpeg+Python port of Anime4K for easier use in non-real time applications, and I'm not entirely confident that mpv will introduce gpu encoding for all platforms. I guess I will simply start working on the port first and see from there...

Hope to get out early, my computer configuration is very low, can not use Anime4K smooth real-time, and transcoding can be better shared

ThoughtfulDev commented 3 years ago

You can have a look at my repository Anime4K which does offline encoding using the Anime4K shaders. https://github.com/ThoughtfulDev/Anime4K

ducomeon commented 3 years ago

You can have a look at my repository Anime4K which does offline encoding using the Anime4K shaders. https://github.com/ThoughtfulDev/Anime4K

Thank you very much! But I tested that this doesn't work on my Windows pc, and I'd appreciate your answer anyway.

dark-swordsman commented 3 years ago

Just to note about X264 encoding. Apparently you can do "i-frame only" encoding. So it saves a picture for each frame. It is incredibly expensive in terms of video size, but it's quality is technically infinite and you can use that to encode into other formats.

I will certainly try out your MPV solution with that and see if it works.

78Alpha commented 3 years ago

https://github.com/AaronFeng753/Waifu2x-Extension-GUI

Let's you encode with anime 4 land a number of other things, could be a good example for making a standalone one.

SwayStar123 commented 2 years ago

@ThoughtfulDev I see... I'm currently deciding if I am going to do a full Tensorflow+ffmpeg+Python port of Anime4K for easier use in non-real time applications, and I'm not entirely confident that mpv will introduce gpu encoding for all platforms. I guess I will simply start working on the port first and see from there...

Hello is this possible yet?