Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used to encode to allow for later playback? #55

Open
arces opened this issue Nov 9, 2019 · 15 comments
Open

Can this be used to encode to allow for later playback? #55

arces opened this issue Nov 9, 2019 · 15 comments

Comments

@arces
Copy link

arces commented Nov 9, 2019

Is your feature request related to a problem? Please describe.
A way to encode the video to be later viewed on something like Plex.

Describe the solution you'd like
A way to encode the video into a 4k resolution video file to be viewed later or on other players.

Describe alternatives you've considered
A have used it and it works great but only works in players that I don't normally or can't use sometimes.

Additional context
A script or even some workaround like using a video player, that currently works with the plugin, to encode and save the video file. I know you can do some encoding with VLC.

@arces arces changed the title Can this be used to encode Can this be used to encode to allow for later playback? Nov 9, 2019
@arbrog
Copy link

arbrog commented Mar 24, 2020

Bump. I tried using mpv's record-file option but it looks like it just outputs the original input file resolution not the upscaled post shader player resolution. Does anyone know any tools for rendering videos with shaders? One i found that might work is https://github.com/polyfloyd/shady (is there a meta tag for issues?)

@bloc97
Copy link
Owner

bloc97 commented Mar 24, 2020

There will be a python/tensorflow version coming soon. You will be able to use ffmpeg-python to encode video if you wish. (Even if it goes against the nature of Anime4K)

@arbrog
Copy link

arbrog commented Mar 24, 2020

Awesome! Yeah I know it's against the whole point but if I want to watch on my Ipad, etc (using plex) I don't know of any way to apply the shader live on those platforms.

@arces
Copy link
Author

arces commented Mar 24, 2020

Thank you @bloc97 appreciate it :)

@cladoxylopsidus
Copy link

Are there any updates on this yet?

@bloc97
Copy link
Owner

bloc97 commented Apr 24, 2020

I can't promise a deadline due to the current circumstances, but I think I should at least be able to start working on a Tensorflow/Python port now that v3.0 is released.

Edit: On a different note, you should be able to achieve similar if not even better results using the already available AVISynth filters and the numerous waifu2x encoders out there. But of course, they are pretty slow and not suitable for real-time use.

@ccicnce113424
Copy link

ccicnce113424 commented Apr 25, 2020

(The following content was translated from Chinese to English using DeepL)
The HLSL version of this filter can be loaded in AviSynth using the AviSynthShader. Unfortunately, the HLSL version is not the latest version and has stopped updating.
Example

@arces
Copy link
Author

arces commented Jul 7, 2021

Any update @bloc97 . I am sure you are busy and don't want to bug you but thought it would be good to check in a year later and see if there is any update. Thank you!

@bloc97
Copy link
Owner

bloc97 commented Jul 8, 2021

If I remember correctly it is already possible to encode video using mpv on linux after applying shaders.
Futhermore, I can release the uncleaned tensorflow code/model, but the line thinning and other non-ML shaders are not implemented in python.

I had planned to release the tensorflow model much earlier but I had no time and my training machine broke. I only recently obtained a personal machine for training and am in the process of updating the code to Tensorflow 2.5 (the old code was for tf 1.15).

@arces
Copy link
Author

arces commented Jul 13, 2021

I have a 3090, 64gb ram, and an i7-9770k happy to train the model if you need.

@bloc97
Copy link
Owner

bloc97 commented Jul 13, 2021

@arces I really appreciate your offer! My machine is working, albeit not as powerful as yours... However, even the biggest Anime4K network is very lightweight (under 20k parameters) and trains pretty much on anything. Training time is also very short by using sota training methods such as adaptive momentum, cyclical learning rates and super-convergence. It takes less than 2 hours for successful training for the UL version, and less than 10 minutes for the M version to converge.
The real issue right now is the code is extremely messy and not worthy of being published... The script for TF model -> GLSL conversion is also hardcoded and won't work if the network architecture is modified.

Edit: I'm working on cleaning up the code and allowing it to be run within a standard tf-gpu docker container.

@barneymaydance
Copy link

Hi @bloc97 , thanks for your excellent work. I tried it and it is really fast. I want to train the same model by my dataset. Can you please release the model structure of M version? Model structure is enough. Thanks!

@bloc97
Copy link
Owner

bloc97 commented Aug 6, 2021

@barneymaydance The M version is tiny. It's simply five 3x3 Conv2D layers (4 features wide) with CReLU activation followed by a Depth to Space upsampling layer. The network predicts residuals instead of the full image, just like in VDSR (CVPR16).
Note that in v3.1 the M variant uses a concatenate-and-reduce dense layer at the end, similar to what is used in DenseNet (CVPR17), but further experiments showed that it is not beneficial for x2 upscaling with a very shallow network and can be removed. The dense layer do help for x2, x3 and x4 upscaling when using a deeper network (6+ layers). I've kept it just for consistency across versions (easier to debug and to train in batch)...

@bloc97
Copy link
Owner

bloc97 commented Aug 6, 2021

@barneymaydance Here's the snippet of code that I used

import tensorflow as tf

def SR2Model(input_channels=1, features=4, block_depth=4):

    input_shape = [None, None, input_channels]
    input_lr = tf.keras.layers.Input(shape=input_shape)
    upsampled_lr = tf.keras.layers.UpSampling2D(size=(2, 2), interpolation='bilinear')(input_lr)
    
    x = input_lr
    for i in range(block_depth):
        x = tf.keras.layers.Conv2D(features, (3, 3), padding='same', kernel_initializer='he_normal')(x)
        x = tf.nn.crelu(x)
    
    x = tf.keras.layers.Conv2D(input_channels*4, (3, 3), padding='same', kernel_initializer=tf.keras.initializers.RandomNormal(mean=0.0, stddev=0.001))(x)
    x = tf.nn.depth_to_space(x, 2)
    x = tf.keras.layers.Add()([x, upsampled_lr])

    model = tf.keras.models.Model(input_lr, x)
    model.summary(line_length=150)

    return model

@feanor3
Copy link

feanor3 commented Oct 24, 2021

the python version for encoding will be aviable for windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants