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. |
|
|
#1 | Link |
|
Anime addict
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
}
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 |
|
|
|
|
|
#2 | Link |
|
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() ps : you forgot the import "vapoursynth as vs" before "core = vs.get_core()" Last edited by YamashitaRen; 27th September 2015 at 14:48. |
|
|
|
|
|
#3 | Link |
|
Registered User
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 322
|
I don't have the time to check it now but:
- You forgot to load vapoursynth in this module: Code:
import vapoursynth as vs - 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. |
|
|
|
|
|
#4 | Link | ||
|
Anime addict
Join Date: Feb 2009
Location: Spain
Posts: 673
|
Thanks, a both.
Quote:
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() Quote:
__________________
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 |
||
|
|
|
|
|
#5 | Link |
|
Useful n00b
Join Date: Jul 2014
Posts: 1,666
|
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() |
|
|
|
|
|
#6 | Link |
|
Registered User
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 322
|
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
I also get ride of lsb because it makes no sense when all your entire pipeline can be at any bit depth. |
|
|
|
|
|
#7 | Link | |
|
Anime addict
Join Date: Feb 2009
Location: Spain
Posts: 673
|
Quote:
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 |
|
|
|
|
|
|
#8 | Link | |
|
Anime addict
Join Date: Feb 2009
Location: Spain
Posts: 673
|
Quote:
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. |
|
|
|
|
|
|
#9 | Link |
|
Anime addict
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 |
|
|
|
|
|
#10 | Link | |
|
Registered User
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 322
|
Quote:
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 |
|
|
|
|
|
|
#11 | Link | |
|
Anime addict
Join Date: Feb 2009
Location: Spain
Posts: 673
|
Quote:
__________________
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 |
|
|
|
|
|
|
#12 | Link |
|
Anime addict
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. |
|
|
|
|
|
#13 | Link |
|
Professional Code Monkey
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,647
|
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 |
|
|
|
|
|
#14 | Link |
|
Registered User
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 322
|
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. |
|
|
|
|
|
#15 | Link | |
|
Anime addict
Join Date: Feb 2009
Location: Spain
Posts: 673
|
Quote:
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 |
|
|
|
|
|
|
#16 | Link |
|
Professional Code Monkey
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,647
|
Yes, at least write reasonable code to do horrible things.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet |
|
|
|
|
|
#17 | Link | ||||
|
Anime addict
Join Date: Feb 2009
Location: Spain
Posts: 673
|
Quote:
Quote:
Quote:
Quote:
__________________
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. |
||||
|
|
|
|
|
#19 | Link |
|
Anime addict
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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|