Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th June 2020, 21:59   #601  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
Sorry, I think I'm complicating things. What I would like to know is if, as it seems, the use of the Width and Height parameters with any Output is enough to make sure that the size of each texture is that intended.
Alexkral is offline   Reply With Quote
Old 27th June 2020, 03:32   #602  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
if I remember, the shader takes parameters to know the input size, and the parameters added to the command are the output size. I could be wrong, but I think it's that.
MysteryX is offline   Reply With Quote
Old 27th June 2020, 08:50   #603  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
Okay, it seems to work fine so thanks.
Alexkral is offline   Reply With Quote
Old 27th June 2020, 23:20   #604  |  Link
amayra
Quality Checker
 
amayra's Avatar
 
Join Date: Aug 2013
Posts: 284
any plan for VapourSynth support ?
__________________
I love Doom9
amayra is offline   Reply With Quote
Old 28th June 2020, 10:32   #605  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
@Amayra, just out of curiosity, what would you use this for in VapourSynth? I mean, something that is not possible with AviSynth?
Alexkral is offline   Reply With Quote
Old 2nd July 2020, 22:51   #606  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
I would like to add VapourSynth support. I think AviSynth/VapourSynth cross-platoform compatibility should be the standard in 2020 (although this particular project can't work outside Windows because of DirectX9)

Yet I still haven't looked into learning VapourSynth at all.

It would be useful if someone would write documentation with standard guidelines to write plugins for both VapourSynth and Avisynth, and also for making them cross-platform. Otherwise each dev needs to figure it out on their own.
MysteryX is offline   Reply With Quote
Old 3rd July 2020, 12:13   #607  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,548
Quote:
Originally Posted by MysteryX View Post
I would like to add VapourSynth support. I think AviSynth/VapourSynth cross-platoform compatibility should be the standard in 2020 (although this particular project can't work outside Windows because of DirectX9)

Yet I still haven't looked into learning VapourSynth at all.

It would be useful if someone would write documentation with standard guidelines to write plugins for both VapourSynth and Avisynth, and also for making them cross-platform. Otherwise each dev needs to figure it out on their own.
Cross-platform development is so far outside the scope of everything ending in synth it's not even funny. You need a fairly thick programming book to cover that subject in general.

Here's the uncomfortable truth:
1. Did you write GPU code? Probably not portable
2. Did you write code with unaligned memory access? Probably not portable
3. Did you access the filesystem? Probably not portable
4. Did you partially access a wider numerical type in memory? Definitely not portable!
5. Are you super great at build systems? No? No portability for you!

If you write sane code that only performs some CPU calculations and nothing else it'll probably be portable without much effort but that's about it.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 3rd July 2020, 19:04   #608  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
These would be good guidelines for those starting to write new plugins. Things to know before writing the first line of code.

What's easier to do is port to VapourSynth and support both. If the actual work is done by a well-encapsulated class, then it should only require 2 separate code files to interop with each *synth?
MysteryX is offline   Reply With Quote
Old 3rd July 2020, 20:16   #609  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,548
Quote:
Originally Posted by MysteryX View Post
These would be good guidelines for those starting to write new plugins. Things to know before writing the first line of code.

What's easier to do is port to VapourSynth and support both. If the actual work is done by a well-encapsulated class, then it should only require 2 separate code files to interop with each *synth?
Yes, supporting both is very easy if you know what a function looks like.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 20th July 2020, 15:26   #610  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
Quote:
Originally Posted by poisondeathray View Post
I can reproduce this; easier to see with colorbars or similar patterns

fulls=true seems to "fix" it (or match the others)

Code:
ConvertBits(16, fulls=true)
SuperResXBR(MatrixIn="Rec601")
ConvertBits(8, fulls=true, dither=-1)
Quote:
Originally Posted by markiemarcus View Post
Many thanks for this! It does indeed work. I guess the big question is why? I haven't observed this behaviour in KNLMeansCL for example. Just a bug?

I also wonder why it produces very slightly different results (detail-wise) to the LSB method. I was under the impression that despite the different approach to high bit depth processing, the results should be 100% identical.
it's was bug and fixed in https://forum.doom9.org/showthread.p...15#post1916615
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 21st July 2020, 20:08   #611  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
Hi MysteryX, I've been working with AviSynth Shader for some time trying to use it to run some Super-resolution CNNs implemented as pixel shaders. You can see the result here. First thing I have to say is that it works very good and fast, so I wanted to thank you for your work, it's great to be able to use a tool like this. However I have found some problems and limitations that I wanted to inform you about, so that you can see what would be necessary to solve them if this is possible:

- This works by using each plane as the input/output for a filter, so with a maximum of 9 clips, the maximum number of filters is 36. To implement a network of 64 filters (most), 16 clips would therefore be necessary. For simple models like FSRCNN, this can be solved by spliting the layers between two or more shaders, but for more complex models this would mean a large increase in the number of shaders, and apart from what this would mean for performance, there is already a limit about the maximum number of shaders that can be used in the same pass (see below).
- I'm not sure what the problem is with Y16 as this seems to have been changing. Using it as input produces the error "CombinePlanes: source has no such plane U". Using it as output returns a YUVA444P16 clip. Maybe this could help to increase performance.
- Trying to return a Y8 clip now with Precision = 0 produces the error "CombinePlanes: source bit depth is different from 16".
- Shader Model 3.0 has a limit of 224 Constant registers. This means that, for example, the maximum number of clips that can be used in a shader for a Conv3x3 layer is equal to 6. Unfortunately this can only be solved by using Shader Model 4.0 or spliting the layers as above.
- There is a limit on the maximum number of shaders that can be used in a single pass, after which an access violation error occurs. I have noticed that this limit varies slightly depending on Precision and PlanarOut. This is what I've found in case it could help you:

With Precision = 1 and PlanarOut = false, the limit is 79.
With Precision = 1 and PlanarOut = true, the limit is 76.
With Precision = 2 and PlanarOut = false, the limit is 80.
With Precision = 2 and PlanarOut = true, the limit is 77.

And I think that would be it. For the kind of models I am using, troubleshooting the Y8 and Y16 issues could help to increase performance. I don't think that solving the other issues related to increasing the number of filters or layers could be especially beneficial, because the models would be much slower and the improvement in results would be only marginal. To have the possibility of implementing other more complex networks, a solution would be necessary though.

Last edited by Alexkral; 30th October 2020 at 18:01.
Alexkral is offline   Reply With Quote
Old 24th July 2020, 17:49   #612  |  Link
amayra
Quality Checker
 
amayra's Avatar
 
Join Date: Aug 2013
Posts: 284
Quote:
Originally Posted by Alexkral View Post
@Amayra, just out of curiosity, what would you use this for in VapourSynth? I mean, something that is not possible with AviSynth?
will like my script to be cross-platform and all work in one VS script to run it in mpv

I find VapourSynth faster/stable then AviSynth when it comes to frame interpolation
__________________
I love Doom9
amayra is offline   Reply With Quote
Old 16th September 2020, 03:17   #613  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
Don't know if anyone here still uses this, but do I have to use a combination of SuperRes and another upscaler to upscale say a 720p source to 4k? If not, how do I make it so that it doesn't scale 2x.
The results are pretty good tbh :P
ENunn is offline   Reply With Quote
Old 26th September 2020, 03:13   #614  |  Link
SaurusX
Registered User
 
Join Date: Feb 2017
Posts: 134
You can just chain the upscalers together. Call one after the other with whatever sharpening you want between them. Then downscale afterwards to a final 4K res.
SaurusX is offline   Reply With Quote
Old 10th November 2020, 18:43   #615  |  Link
tyee
Registered User
 
Join Date: Oct 2001
Posts: 416
Please check syntax

Trying to get this to work in AVS but having problems. I've tried to fix the syntax as best I can but after loading the avs file into Vdub I get this error -



I see the suggested script -

ConvertToShader(1)
Input
Shader("Diff1.cso", Output=2)
Shader("Diff2.cso", Output=3)
Shader("Merge.cso", Clip1=2, Clip2=3, Output=1)
ShaderExecute(last, Input, Clip1Precision=1, Precision=3, OutputPrecision=1)
ConvertFromShader(1)

I'm not sure what "Input" means and whether "1" means precision=1?

Here is my script - I tried to copy another script in this thread.

mov = FFVideoSource("J:\video.mp4")
ConvertToShader(mov)
Shader("G:\Adaptive-sharpen - Pass one.hlsl", Output=2)
Shader("G:\Adaptive-sharpen - Pass two.hlsl", Output=1)
ExecuteShader(last, mov, Clip1Precision=1, Precision=3, OutputPrecision=1)
ConvertFromShader()

Can you see what's wrong?

Last edited by tyee; 10th November 2020 at 18:47.
tyee is offline   Reply With Quote
Old 10th November 2020, 20:52   #616  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
Try this:

Code:
mov = FFVideoSource("J:\video.mp4")
Input = ConvertToShader(mov, 1)
Shader(Input, "G:\Adaptive-sharpen - Pass one.hlsl", Output = 2)
Shader("G:\Adaptive-sharpen - Pass two.hlsl", Clip1 = 2)
ExecuteShader(last, Input, Clip1Precision = 1, Precision = 3, OutputPrecision = 1)
ConvertFromShader()
Default precision in ConvertToShader is 2, so you have to specify it. Default Output on the last shader line is always 1.
__________________
AviSynth AiUpscale
Alexkral is offline   Reply With Quote
Old 11th November 2020, 06:17   #617  |  Link
tyee
Registered User
 
Join Date: Oct 2001
Posts: 416
OK, thanks. Tried it and got an error about opening the shader. I removed the "G:\" and copied the .hlsl files to the plugin folder and now it loads fine but the image in Vdub is not the correct aspect ratio (width is 1/2 what it should be) and it's all covered in blue. I think there was something in the instructions about floating point?

Last edited by tyee; 11th November 2020 at 06:45.
tyee is offline   Reply With Quote
Old 11th November 2020, 08:49   #618  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
Yeah, I guess the shaders are these. You have to set also precision in ConvertFromShader(1)
__________________
AviSynth AiUpscale

Last edited by Alexkral; 11th November 2020 at 08:59.
Alexkral is offline   Reply With Quote
Old 12th November 2020, 01:55   #619  |  Link
tyee
Registered User
 
Join Date: Oct 2001
Posts: 416
Thanks, I did have the latest but I forgot that (1) on the last line. Works fine now!
tyee is offline   Reply With Quote
Old 2nd January 2021, 13:59   #620  |  Link
butterw2
Registered User
 
Join Date: Jun 2020
Posts: 303
I've tried out Avisynth shader on a simple mp-hc video player shader. Any further advice welcome.

Mpc-hc shaders only run in rgb so it is necessary to convert to RGB32 at the input and the output.
It also seems necessary to modify the shader so that it takes bgra as input and output to get correct colors.

sampler s0: register(s0);

float4 main(float2 tex: TEXCOORD0): COLOR {
float4 c0 = tex2D(s0, tex).bgra;
...
c0+= float4(1, 0, 0, 0); //saturate red channel
...
return c0.bgra;
}


Perf overhead: tested on old intel integrated graphics i3-4150,
realtime preview at 720p60 and 1080p25 seem near achievable.
adding Prefetch(2) at the end of the script improves perf slightly but does increase cpu usage.

# AviSynth Shader v1.6.6 with Avisynth+ v3.6.1 x64 on Win10
https://github.com/mysteryx93/AviSynthShader/releases

Quote:
Originally Posted by Alexkral View Post
- The default precision for ConvertToShader and ConvertFromShader is not 1, so you have to specify it.
- The input has to be RGB because otherwise the shader receives YUV channels.
- The first shader receives the channels as BGRA. The last shader has to return them as BGRA for RGB32 by changing the order again, or as GBRA for YV12 or YV24.
- The Alpha channel can be used to pass data between the shaders, but obviously it is lost at the end.

There is no need to compile the shaders.

Code:
input = FFMS2("video.mkv", colorspace = "RGB32")

c = ConvertToShader(input, Precision = 1)
Shader(c, "Anime4K_ComputeLum.hlsl", output=2)
Shader(last, "Anime4K_Push.hlsl", Clip1 = 2, output = 3)
Shader(last, "Anime4K_ComputeGradient.hlsl", Clip1 = 3, output = 4)
Shader(last, "Anime4K_PushGrad.hlsl", Clip1 = 4, output = 1)
ExecuteShader(last, c, Precision = 3, OutputPrecision = 1)
ConvertFromShader(last, Precision = 1, Format = "RGB32")

EDIT: My understanding of how avisynth shader works is as follows:
- The input video file (ex: yuv420) is loaded into avisynth (cpu).
- avisynth shader can transfer this to a pixel shader chain (dx9 .hlsl, gpu).
- mpc-hc video player shaders run in rgba. Thus the input has to be converted to RGB first (!!! avisynth shader input/output is in .bgra format meaning the shader code will have to be modified if it performs specific operations on color component).
- it would be possible to write hlsl shaders that run in yuv and you can pass parameters to the shaders via registers.
- the output gets transfered back to avisynth (cpu). The transfers between cpu/gpu have significant overhead, especially at higher resolution.
Further processing can be done in avisynth at input or output.

Last edited by butterw2; 3rd January 2021 at 15:25.
butterw2 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.