k4yt3x / video2x

A lossless video/GIF/image upscaler achieved with waifu2x, Anime4K, SRMD and RealSR. Started in Hack the Valley II, 2018.
https://video2x.org
GNU Affero General Public License v3.0
10.07k stars 974 forks source link

Add support for Real-ESRGAN, plus various fixes (hangs, async video, etc.) #1133

Open arximboldi opened 3 months ago

arximboldi commented 3 months ago

This picks up the work in #1102 by @aa-ko to introduce Real-ESRGAN support, adding support for all models exposed by realesrgan-ncnn-py and testing it outside of a Docker container.

Additionally, I have fixed a few issues that I've found. I wasn't sure whether you prefer to have multiple smaller PR, or to just review all at once. The work is separated into multiple commits so I can still split into multiple PR's if you prefer.

These are the highlights from this PR:

There are also some smaller changes that I'm not sure you agree with, but that I think are quite convenient:


Thank you @aa-ko for starting the work on integrating Real-ESRGAN. It's model realesr-animevideov3 is giving me incredible results, with image quality comparable or better for anime than realcugan, yet much faster!

Thank you @k4yt3x for this incredible tool. Looking into the code has shown me how much love there is into it and it is working super well for me now!

twardoch commented 1 month ago

@arximboldi

class KillableListener(Listener, KillableThreadMixin):
    """
    A killable version of pyinput.keyboard.Listener, as joining()
    seems to hang on some systems even after properly calling close().
    """
    pass

in https://github.com/arximboldi/video2x/blob/realesrgan/video2x/video2x.py#L131C1-L136C9 causes a fail where pynput is not available. Because Python tries to subclass from Listener. You should define that class in a scoped way.

twardoch commented 1 month ago

@arximboldi Also when I try running with realesrgan on Google Colab, I get

Unrecognized option 'fps_mode'. Error splitting the argument list: Option not found

(which seems to be referenced in https://github.com/arximboldi/video2x/blob/realesrgan/video2x/decoder.py )

twardoch commented 4 weeks ago

Turns out that 'fps_mode' is a relatively new option in ffmpeg, and the standard Google Colab environment installs an older ffmpeg. But I was able to work around it with:

# Install system dependencies
!apt-get update
!apt-get install -y --no-install-recommends \
    python3-pip libvulkan-dev glslang-dev glslang-tools \
    build-essential swig ninja-build nvidia-driver-535 \
    mpv xserver-xorg-video-dummy xvfb libomp5
!sudo curl -L https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz -o /usr/local/bin/ffmpeg.tar.xz

%cd /usr/local/bin/
!7z e /usr/local/bin/ffmpeg.tar.xz -aoa
!7z e /usr/local/bin/ffmpeg.tar -aoa
!sudo chmod a+rx /usr/local/bin/ffmpeg
twardoch commented 4 weeks ago

Similarly, to work around the poor integration of Listener, I was able to work around it in Google Colab by providing:

%env DISPLAY=:0
class Listener:
    pass

from video2x import Video2X
video2x = Video2X()

But that’s not how it should work :)