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 > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 27th September 2015, 13:41   #1  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
[Solved] Check if porting is proper

Hi, folks. I am porting some functions for beginning to use vapoursynth.

I need convert this function:

Code:
function BrightDfttestMod(clip input, float "sbright", float "smedium", float "sdark", 
 \        int "th_low", int "th_med", int "th_high", int "tbsize", bool "lsb", int "mode")
{


sbright       = default( sbright,  0 ) 
smedium       = default( smedium,  0 )
sdark         = default( sdark,    0 ) 

th_low        = default( th_low,   20 ) 
th_med        = default( th_med,   40 ) 
th_high       = default( th_high, 100 ) 

lsb	      = default( lsb, false )
mode	      = default( mode, 0    )


bright = (sbright > 0 && lsb==false) ? input.dfttest(sigma = sbright,tbsize=tbsize,sbsize=18,sosize=9,lsb=lsb):\
 	 (sbright > 0 && lsb==true)  ? input.dfttest(sigma = sbright,tbsize=tbsize,sbsize=18,sosize=9,lsb=lsb).ditherpost(mode=mode) : input
medium = (smedium > 0 && lsb==false) ? input.dfttest(sigma = smedium,tbsize=tbsize,sbsize=18,sosize=9,lsb=lsb):\
	 (smedium > 0 && lsb==true)  ? input.dfttest(sigma = smedium,tbsize=tbsize,sbsize=18,sosize=9,lsb=lsb).ditherpost(mode=mode) : input
dark   = (sdark   > 0 && lsb==false) ? input.dfttest(sigma = sdark,tbsize=tbsize,sbsize=18,sosize=9,lsb=lsb)  :\
	 (sdark   > 0 && lsb==true)  ? input.dfttest(sigma = sdark,tbsize=tbsize,sbsize=18,sosize=9,lsb=lsb).ditherpost(mode=mode) : input

mmask = medium.levels(th_med, 1.0, th_high, 255, 0, false)		   
dmask = medium.levels(th_low, 1.0, th_med,  255, 0, false)

output = bright.mt_merge(medium, mmask, U=3, V=3, luma=true) 
         \  .mt_merge(dark, dmask, U=3, V=3, luma=true)

return output
}
Other question is how could test this function, where put this file.py??

Thanks
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite

Last edited by Overdrive80; 1st October 2015 at 20:16. Reason: Edit code
Overdrive80 is offline   Reply With Quote
Old 27th September 2015, 14:39   #2  |  Link
YamashitaRen
Registered User
 
Join Date: Apr 2014
Location: France
Posts: 33
You have to put your function in the python path (I don't know where it is on your system).

For testing it, let's assume you named the file "myfunction.py" :
Code:
import vapoursynth as vs
import myfunction as mf
core=vs.get_core()

clip=mysourceclip
clip=BrightDfttestMod(clip)
clip.set_output()
Or, instead of using the "import myfunction as mf", you can copy/paste your function in the script. Which is good for testing with vsedit in my opinion.

ps : you forgot the import "vapoursynth as vs" before "core = vs.get_core()"

Last edited by YamashitaRen; 27th September 2015 at 14:48.
YamashitaRen is offline   Reply With Quote
Old 27th September 2015, 14:42   #3  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 321
I don't have the time to check it now but:

- You forgot to load vapoursynth in this module:
Code:
import vapoursynth as vs
And in the very first line, outside of any function.

- Don't manually load any plug-in, anywhere, never (well, just for debugging). It is needed in avisynth because it's broken there, but auto-loading is quite sane in vapoursynth.

- Vapoursynth is case sensitive, so, you will be happier if you don't use caps in function names/parameters, just write all lowercase or use underscores.

- Your indentation is not consistent, it will error out.

- """ are used for documentation, use # for general comments.

And to test functions is best to put it in a working script with some source file loaded, and put them in a separate file in "/your/python/installation/site-packages", if you don't you will need to restart the testing program to reload the module, quite annoying.

Last edited by Are_; 27th September 2015 at 14:48.
Are_ is offline   Reply With Quote
Old 27th September 2015, 14:54   #4  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Thanks, a both.

Quote:
Your indentation is not consistent, it will error out.
Exactly. Edit: Fixed.

I put module py in "C:\Users\Isra\AppData\Local\Programs\Python\Python35-32\Lib\site-packages". From Vapoursynth editor I use:

Code:
import vapoursynth as vs
import brightdfttestmod 
core = vs.get_core()

clip = core.lsmas.LWLibavSource(r'D:/Utorrent/xxx.mp4')

clip=brightdfttestmod(clip)
clip.set_output()
With updated above code this is error message:

Quote:
File "src\cython\vapoursynth.pyx", line 1484, in vapoursynth.vpy_evaluateScript (src\cython\vapoursynth.c:26808)
File "C:/Users/Isra/Desktop/Untitled.vpy", line 7, in <module>
clip=brightdfttestmod(clip)
TypeError: 'module' object is not callable
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite

Last edited by Overdrive80; 27th September 2015 at 15:01. Reason: Edit for error
Overdrive80 is offline   Reply With Quote
Old 27th September 2015, 15:48   #5  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Just a noob here but maybe something like this:

import vapoursynth as vs
import brightdfttestmod as br
core = vs.get_core()

clip = core.lsmas.LWLibavSource(r'D:/Utorrent/xxx.mp4')

clip=br.brightdfttestmod(clip)
clip.set_output()
videoh is offline   Reply With Quote
Old 27th September 2015, 20:44   #6  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 321
After reading your function and realizing you didn't even boder to read the documentation for any plugin (Levels had transposed arguments and many functions had nonexistent arguments/function_names) I lost part of my motivation to help you.

Anyway here is like it may be done:
Code:
import vapoursynth as vs

def scale(old_value, new_bd=16):
    return int((old_value * ((1 << new_bd) - 1)) / 255)


def brightdfttestmod(clip, sbright=0, smedium=0, sdark=0, th_low=20, th_med=40, th_high=100, tbsize=5):
    
    core = vs.get_core()
    
    if not isinstance(clip, vs.VideoNode):
        raise ValueError('This is not a clip')
    
    # This scales the values for Levels in case we are not working with 8-bit clips
    if clip.format.bits_per_sample != 8:
        th_low = scale(th_low, clip.format.bits_per_sample)
        th_med = scale(th_med, clip.format.bits_per_sample)
        th_high = scale(th_high, clip.format.bits_per_sample)
    
    # Bright
    if sbright > 0:
        bright = core.dfttest.DFTTest(clip, sigma=sbright, tbsize=tbsize, sbsize=18, sosize=9)
    else: 
        bright = clip
        
    # Medium
    if smedium > 0:
        medium = core.dfttest.DFTTest(clip, sigma=smedium, tbsize=tbsize, sbsize=18, sosize=9)
    else: 
        medium = clip
        
    # Dark
    if sdark > 0:
        dark = core.dfttest.DFTTest(clip, sigma=sdark, tbsize=tbsize, sbsize=18, sosize=9)
    else: 
        dark = clip

    mmask = core.std.Levels(medium, th_med, th_high, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)
    dmask = core.std.Levels(medium, th_low, th_med, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)

    output = core.std.MaskedMerge(bright, medium, mmask, first_plane=1)
    output = core.std.MaskedMerge(output, dark, dmask, first_plane=1)

    return output
Carefully read it and try to notice what you were doing wrong.
I also get ride of lsb because it makes no sense when all your entire pipeline can be at any bit depth.
Are_ is offline   Reply With Quote
Old 27th September 2015, 20:51   #7  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Quote:
Originally Posted by videoh View Post
Just a noob here but maybe something like this:

import vapoursynth as vs
import brightdfttestmod as br
core = vs.get_core()

clip = core.lsmas.LWLibavSource(r'D:/Utorrent/xxx.mp4')

clip=br.brightdfttestmod(clip)
clip.set_output()
Some answer is appreciatted. Thanks, was useful.

Edit: Finally, I get that works. Now, I have compare result of avisynth and vapoursynth
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Old 27th September 2015, 21:09   #8  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Quote:
Originally Posted by Are_ View Post
After reading your function and realizing you didn't even boder to read the documentation for any plugin (Levels had transposed arguments and many functions had nonexistent arguments/function_names) I lost part of my motivation to help you.
Is my first attempt with vapoursynth, I read documentation but I can not convert on advanced user at one day. Sorry that you think it and you lost motivation, but if you see modification of code, you can check that I do changes about it.

ATW, thanks for answering.
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite

Last edited by Overdrive80; 27th September 2015 at 21:17.
Overdrive80 is offline   Reply With Quote
Old 28th September 2015, 09:29   #9  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Hi holywu, use: ( U=3, V=3, luma=true) isnt the same than planes=[1, 2], first_plane=True , is it??

With respect to lsb and mode, until he said it I did not realize that vapoursynth processed over 8 bitdepth unlike avisynth, hence my misconception.

Thanks to his code, I call to function after using: clip=core.fmtc.bitdepth(clip, bits=16, mode=6)

Thanks for helping to learn.
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Old 28th September 2015, 12:02   #10  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 321
Quote:
Originally Posted by Overdrive80 View Post
Hi holywu, use: ( U=3, V=3, luma=true) isnt the same than planes=[1, 2], first_plane=True , is it??
No.
U=3, V=3, luma=true means: process both chroma planes (in adition to luma plane), use luma plane from mask to do it.
planes=[1, 2], first_plane=True means: proces only chroma planes, use luma plane from mask to do it.

As I posted in my script, you should just put first_plane=True, because planes=[0, 1, 2] is the default, or if you want to put everything there, planes=[0, 1, 2], first_plane=True
Are_ is offline   Reply With Quote
Old 28th September 2015, 14:08   #11  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Quote:
Originally Posted by Are_ View Post
No.
U=3, V=3, luma=true means: process both chroma planes (in adition to luma plane), use luma plane from mask to do it.
planes=[1, 2], first_plane=True means: proces only chroma planes, use luma plane from mask to do it.

As I posted in my script, you should just put first_plane=True, because planes=[0, 1, 2] is the default, or if you want to put everything there, planes=[0, 1, 2], first_plane=True
Ok, all clear. Thanks you so much.
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Old 1st October 2015, 19:31   #12  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
For how want, I have completed the function (thanks to _Are):

Code:
import vapoursynth as vs

def scale(old_value, new_bd=16):
    return int((old_value * ((1 << new_bd) - 1)) / 255)


def brightdfttestmod(clip, sbright=0, smedium=0, sdark=0, th_low=20, th_med=40, th_high=100, tbsize=5,
					sbsize=18, sosize=9, planes=[0,1,2], luma=True):
    
    core = vs.get_core()
    
    if not isinstance(clip, vs.VideoNode):
        raise ValueError('This is not a clip')
	
    # This scales the values for Levels in case we are not working with 8-bit clips
    if clip.format.bits_per_sample != 8:
        th_low = scale(th_low, clip.format.bits_per_sample)
        th_med = scale(th_med, clip.format.bits_per_sample)
        th_high = scale(th_high, clip.format.bits_per_sample)
    
    # Bright
    if sbright > 0:
        bright = core.dfttest.DFTTest(clip, sigma=sbright, tbsize=tbsize, sbsize=sbsize, sosize=sosize, planes=planes)
    else: 
        bright = clip
        
    # Medium
    if smedium > 0:
        medium = core.dfttest.DFTTest(clip, sigma=smedium, tbsize=tbsize, sbsize=sbsize, sosize=sosize, planes=planes)
    else: 
        medium = clip
        
    # Dark
    if sdark > 0:
        dark = core.dfttest.DFTTest(clip, sigma=sdark, tbsize=tbsize, sbsize=sbsize, sosize=sosize, planes=planes)
    else: 
        dark = clip
		
    if luma==True:
        luma_layer= core.std.ShufflePlanes(medium, planes=[0], colorfamily=vs.GRAY)
        mmask = core.std.Levels(luma_layer, th_med, th_high, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)
        dmask = core.std.Levels(luma_layer, th_low, th_med, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)
    else:
        mmask = core.std.Levels(medium, th_med, th_high, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)
        dmask = core.std.Levels(medium, th_low, th_med, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)

    output = core.std.MaskedMerge(bright, medium, mmask, planes=planes, first_plane=luma)
    output = core.std.MaskedMerge(output, dark, dmask, planes=planes, first_plane=luma)

    return output
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite

Last edited by Overdrive80; 4th October 2015 at 02:08.
Overdrive80 is offline   Reply With Quote
Old 1st October 2015, 20:34   #13  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,548
Why oh WHY are you putting so many lines into making your functions not work the same way as basically every other vapoursynth function ever?

And a small hint if you still want to make things more difficult:
planes = []
if y:
planes.insert(0)
...
if planes.count() == 0:
error terror!
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 1st October 2015, 20:43   #14  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 321
No really, just forget about all that avisynth nonsense, instead of y=True, u=True, v=True just do planes=[0, 1, 2], that will make your function look like any vapoursynth function out there . And pass that to dfttest too, if you are not going to use it don't spend time filtering it.
And before you create the mask you can just core.std.ShufflePlanes(medium, planes=[0], colorfamily=vs.GRAY), so you can get ride of first_plane=luma too.

Last edited by Are_; 1st October 2015 at 20:48.
Are_ is offline   Reply With Quote
Old 1st October 2015, 22:21   #15  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Quote:
Originally Posted by Myrsloik View Post
Why oh WHY are you putting so many lines into making your functions not work the same way as basically every other vapoursynth function ever?

And a small hint if you still want to make things more difficult:
planes = []
if y:
planes.insert(0)
...
if planes.count() == 0:
error terror!
Hi, are you referring to some like this, arent you?:

Code:
    planes=[]	
    # Select planes
    if y:
        planes.append(0)
    if u:
        planes.append(1)
    if v:
        planes.append(2)
    if len(planes)==0:
        raise ValueError("Really? There are not any plane selected.")
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Old 1st October 2015, 22:43   #16  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,548
Yes, at least write reasonable code to do horrible things.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 1st October 2015, 23:18   #17  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Quote:
Originally Posted by Are_ View Post
No really, just forget about all that avisynth nonsense, instead of y=True, u=True, v=True just do planes=[0, 1, 2], that will make your function look like any vapoursynth function out there .
Fixed, like Myrsloik suggestion, too.

Quote:
And pass that to dfttest too, if you are not going to use it don't spend time filtering it.
Fixed.

Quote:
And before you create the mask you can just core.std.ShufflePlanes(medium, planes=[0], colorfamily=vs.GRAY), so you can get ride of first_plane=luma too.
If I dont wrong, do you say this?:

Quote:
luma_layer= core.std.ShufflePlanes(medium, planes=[0], colorfamily=vs.GRAY)
mmask = core.std.Levels(luma_layer, th_med, th_high, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)
dmask = core.std.Levels(luma_layer, th_low, th_med, 1.0, (1 << clip.format.bits_per_sample) - 1, 0)
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite

Last edited by Overdrive80; 1st October 2015 at 23:29.
Overdrive80 is offline   Reply With Quote
Old 1st October 2015, 23:53   #18  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 321
Yes, like that.
Are_ is offline   Reply With Quote
Old 2nd October 2015, 22:30   #19  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Updated function.
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 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 00:16.


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