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 15th December 2017, 21:57   #1  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
Problems with Histogram/Tweak and Other Teething Problems

I'm having trouble with Histogram. At first, I tried to load the plugin, but that generated an error message telling me that the plugin was already loaded, at which point I realized that it is now built in. So I removed the call to LoadPlugin(), but I now receive an error message saying that there is no function called hist.

I took the code from the usage section of Histogram.

Code:
core.std.hist.Color2(video)
Apologies for the newb question! I installed VapourSynth only yesterday and am trying to teach myself VapourSynth and basic Python at the same time. (I'm much more used to AviSynth's way of doing things.)

Last edited by Richard1485; 16th December 2017 at 17:58.
Richard1485 is offline   Reply With Quote
Old 15th December 2017, 22:34   #2  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 279
It's core.hist.Color2(video)
Are_ is offline   Reply With Quote
Old 15th December 2017, 22:36   #3  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,867
Try core.hist.Color(...) without the 'std',... (Are_ was faster )
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 15th December 2017, 23:19   #4  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
Thank you both! That works. I'm still uncertain about when to use std or core and when not to. Moreover, the documentation says that it's possible to chain filters with a dot (like AviSynth), but I'm receiving error messages when I do so.
Richard1485 is offline   Reply With Quote
Old 16th December 2017, 07:42   #5  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,867
Sorry, never tried that. I usually don't chain filters in Avisynth either.
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 16th December 2017, 12:17   #6  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 279
Every plugin should start with the core, but once it is there you can't call it again in the same call.

Then the namespace of the plugin follows it, it is like the container of all functions the plugin has. That's what you usually see like std, resize, hist...

And after that, you call the function you want from that plugin, Color2 for example.

Code:
clip = core.resize.Bicubic(clip, 640, 480)
clip = core.hist.Color2(clip)
becomes

Code:
clip = core.resize.Bicubic(clip, 640, 480).hist.Color2(clip)
The downside about this is it can get ugly pretty fast and if you get errors it makes them harder to track down.

Ofc to create the core there are many methods, you can use
Code:
from vapoursynth import core
which is ugly and prone to produce shit code or the good old
Code:
import vapoursynth as vs
core = vs.get_core()
That being said the ugly way is quite good for short scripts.
Are_ is offline   Reply With Quote
Old 16th December 2017, 13:20   #7  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
Quote:
Originally Posted by Selur View Post
Sorry, never tried that. I usually don't chain filters in Avisynth either.
Oh, I see. Is there a technical reason for that or is it just preference?

Quote:
Originally Posted by Are_ View Post
Every plugin should start with the core, but once it is there you can't call it again in the same call.

Then the namespace of the plugin follows it, it is like the container of all functions the plugin has. That's what you usually see like std, resize, hist...

And after that, you call the function you want from that plugin, Color2 for example.

Code:
clip = core.resize.Bicubic(clip, 640, 480)
clip = core.hist.Color2(clip)
becomes

Code:
clip = core.resize.Bicubic(clip, 640, 480).hist.Color2(clip)
The downside about this is it can get ugly pretty fast and if you get errors it makes them harder to track down.
Thanks for the explanation! Yeah, the latter example that you posted looks like what I'm used to doing in AviSynth.

Quote:
Originally Posted by Are_ View Post
Ofc to create the core there are many methods, you can use
Code:
from vapoursynth import core
which is ugly and prone to produce shit code or the good old
Code:
import vapoursynth as vs
core = vs.get_core()
That being said the ugly way is quite good for short scripts.

I'm really glad that you posted this. I've been seeing the two ways of doing it all over place and wondered which was right or whether they were linked to different versions of Python or whatever. I started by following the documentation, which uses the new way, but after what you've said, I think that I might use the old way. In fact, my current script has a mix of the two because some functions refer to vs, which in the new way remains undefined.
Richard1485 is offline   Reply With Quote
Old 16th December 2017, 14:08   #8  |  Link
hBIkOa7m
Registered User
 
Join Date: Feb 2016
Posts: 6
Quote:
Originally Posted by Are_ View Post
Code:
clip = core.resize.Bicubic(clip, 640, 480).hist.Color2(clip)
The downside about this is it can get ugly pretty fast and if you get errors it makes them harder to track down.
It seems to be quite common that people writing filter code make absolutely no effort to format their code in a way that makes it maintainable or readable. Even if you're only running the script as a one-off job, I've never understood why people make it harder for themselves.

You can chain methods AND use new lines - if you make each line only do one job errors are much easier to track down. By wrapping the block in parenthesis you can newline as much as you like. This is the preferred way in Python. Some MWE:

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

clip = (core.std.BlankClip()
            .resize.Bicubic(1280, 720)
            .text.ClipInfo()
            .std.Turn180()
       )

clip.set_output()
You can also just escape the newlines with a backslash. I think this is more ugly than parenthesis.

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

clip = core.std.BlankClip() \
           .resize.Bicubic(1280, 720) \
           .text.ClipInfo() \
           .std.Turn180()

clip.set_output()
You should line up your indentation on the dots.
hBIkOa7m is offline   Reply With Quote
Old 16th December 2017, 14:43   #9  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
^ The second option looks like the way I do things in AviSynth, although I tab the backspaces to make them line up and look a little neater. I'll try the first in VapourSynth. It does look more elegant.

EDIT: I now have a problem with Tweak().

Code:
import adjust

video2 = core.adjust.Tweak(video,hue=XX)
The result is an error.

Code:
ModuleNotFoundError: No module named "adjust"
The documentation says:

Code:
Drop adjust.py someplace where Python can find it, then use import adjust in your scripts.
I don't know where Python can find adjust.py. I tried putting it in the same directory as the script, but obviously that's the wrong thing to do.

The documentation has a Plugin Autoloading section, but it doesn't seem to refer to .py files, and I'd prefer to load things manually anyway, at least for the time being.

Last edited by Richard1485; 16th December 2017 at 15:37.
Richard1485 is offline   Reply With Quote
Old 16th December 2017, 16:04   #10  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,929
Quote:
Originally Posted by Richard1485 View Post

I don't know where Python can find adjust.py. I tried putting it in the same directory as the script, but obviously that's the wrong thing to do.


I place .py in the python => lib => site-packages directory . Then you can import it with "import adjust"

Another useful .py is HAvsFunc.py by HolyWu - it has many familiar avisynth functions
https://forum.doom9.org/showthread.php?t=166582

(PS. when I come across "std", I take penicillin )

Last edited by poisondeathray; 16th December 2017 at 16:09.
poisondeathray is offline   Reply With Quote
Old 16th December 2017, 16:44   #11  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
Thanks! Unfortunately, that generates a syntax error that points to line 7 of adjust.py itself, possibly because it was written with an older version of Python in mind. I'm using 3.64 with the latest 64-bit version of VapourSynth.

Quote:
Originally Posted by poisondeathray View Post
(PS. when I come across "std", I take penicillin )
That's probably wise.

Last edited by Richard1485; 16th December 2017 at 16:49.
Richard1485 is offline   Reply With Quote
Old 16th December 2017, 16:52   #12  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,929
Quote:
Originally Posted by Richard1485 View Post
Thanks! Unfortunately, that generates a syntax error that points to line 7 of adjust.py itself, possibly because it was written with an older version of Python in mind. I'm using 3.64 with the latest 64-bit version of VapourSynth.
I don't even have a line 7. It's blank.

I think I'm using this one
https://forum.doom9.org/showthread.php?t=172808
poisondeathray is offline   Reply With Quote
Old 16th December 2017, 17:13   #13  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
^ With that version, renamed to adjust.py, I receive a different error.

Code:
AttributeError: No attribute with the name adjust exists. Did you mistype a plugin namespace?
Richard1485 is offline   Reply With Quote
Old 16th December 2017, 17:20   #14  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,929
Weird, it works here

I'm using it like this

Code:
import vapoursynth as vs
import adjust
core = vs.get_core()
#clip = whateversourcefilter()
clip = adjust.Tweak(clip, sat=0.5)
clip.set_output()
poisondeathray is offline   Reply With Quote
Old 16th December 2017, 17:43   #15  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
Got it! I removed core before adjust.Tweak() and moved import adjust so it came before core = vs.get_core(), and it's working. I think the VapourSynth port of Tweak() works like SmoothTweak() in AviSynth in that when one adjusts hue it shifts the chroma in a linear fashion along an axis. With the original Tweak(), I could rotate/turn the chroma like turning a key in a lock.
Richard1485 is offline   Reply With Quote
Old 16th December 2017, 17:45   #16  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,929
Yes, the one in that post separated U, V hue like smoothtweak .
Quote:
I only added separate settings for hue v and u (idea taken from SmoothTweak plugin).
The original one by dubhater is more like classic tweak
poisondeathray is offline   Reply With Quote
Old 16th December 2017, 17:56   #17  |  Link
Richard1485
Registered User
 
Join Date: Feb 2010
Posts: 233
In that case, I wish I could get the original one to work, but it doesn't. Maybe it's meant for 32-bit VapourSynth; I'm using the 64-bit version.

EDIT: It's a shame that one cannot have both approaches to hue. The ability to rotate the chroma is useful, in my opinion.
Richard1485 is offline   Reply With Quote
Old 16th December 2017, 18:18   #18  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,929
Quote:
Originally Posted by Richard1485 View Post
In that case, I wish I could get the original one to work, but it doesn't. Maybe it's meant for 32-bit VapourSynth; I'm using the 64-bit version.

EDIT: It's a shame that one cannot have both approaches to hue. The ability to rotate the chroma is useful, in my opinion.
It works the same way, you can just drop it in and replace

If you want to use both at the same time, just rename one (e.g adjust2.py) and use a different namespace e.g import adjust2 as adjust2

Code:
import vapoursynth as vs
import adjust
import adjust2 as adjust2
core = vs.get_core()
#clip = whateversourcefilter()
clip = adjust.Tweak(clip, hue=20)
clip = adjust2.Tweak(clip, huev=10)
clip.set_output()

Last edited by poisondeathray; 16th December 2017 at 18:22.
poisondeathray is offline   Reply With Quote
Old 16th December 2017, 19:02   #19  |  Link
DJATOM
Registered User
 
DJATOM's Avatar
 
Join Date: Sep 2010
Location: Ukraine, Bohuslav
Posts: 185
> import adjust2 as adjust2
that is redundant
import adjust2 will be the same
__________________
Me on GitHub | My Telegram
PC Specs: Ryzen 3900X (no OC with 250W Air cooling), Asus ROG Crosshair Hero VII (WiFi) @ chipset x470, 32 GB RAM @ 3333MHz OC, Gigabyte RTX 2070, Kingston A1000 @ 240 GB
DJATOM is offline   Reply With Quote
Old 17th December 2017, 09:43   #20  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,867
Quote:
Oh, I see. Is there a technical reason for that or is it just preference?
Mainly: readability and easier debugging.
__________________
Hybrid here in the forum, homepage
Selur 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 07:54.


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