It is currently November 15th, 2019, 11:26 am

Rainmeter for changing parameters in .avs file (AVISYNTH)?

Help with creating, editing & fixing problems with skins
User avatar
protator
Posts: 26
Joined: October 14th, 2014, 11:15 pm

Rainmeter for changing parameters in .avs file (AVISYNTH)?

protator » January 6th, 2019, 5:43 am

Hi everyone,

I've been doing a lot of video encoding lately and all the little manual edits to the avisynth scripts to adjust filters to different content were rather tedious.

So I was thinking of making a RM skin as a GUI with dials for certain parameters.

But how?
I've created a bunch of rm skins in the past, but only by using existing plug-ins that provided data about cpu, gpu ... the usual stuff.

I'd need the script to open the .avs file, go to a certain line and either change a specific value or, in case it's simpler that way, replace the whole line.
I've read somewhere that there's a "writetofile" function in rm, but the forum search didn't turm up anything useful.

Big Thx in advance.
User avatar
balala
Rainmeter Sage
Posts: 9053
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

balala » January 6th, 2019, 8:32 am

protator wrote:
January 6th, 2019, 5:43 am
I'd need the script to open the .avs file, go to a certain line and either change a specific value or, in case it's simpler that way, replace the whole line.
I've read somewhere that there's a "writetofile" function in rm, but the forum search didn't turm up anything useful.
Yes, there is, the !WriteKeyValue bang, but using it Rainmeter can write only to .ini formatted file, replacing / adding some options.
Otherwise maybe with .lua support. But it's not easy at all.
How does a such file looks like and what would you like to write there?
User avatar
protator
Posts: 26
Joined: October 14th, 2014, 11:15 pm

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

protator » January 6th, 2019, 10:10 am

This would be a worst case scenario:

Code: Select all

SetMemoryMax(1024)
SetMTMode(5,4)
Tweak(sat=1.02,cont=1.03).distributor()
SetMTMode(1)
AutoAdjust(auto_balance=true,chroma_limit=1.02,balance_str=0.02,use_dither=false,threads_count=2).distributor()
SetMTMode(2)
KNLMeansCL(d=1,a=2,s=4,h=1.0,channels="y",wmode=0,wref=1.0,device_type="gpu",device_id=1,info=false).distributor()
aWarpSharp2(thresh=190,blur=15,type=1,depth=2).distributor()
MSmooth(threshold=1,strength=1,chroma=true,highq=true).distributor()
aWarpSharp2(thresh=190,blur=15,type=1,depth=4).distributor()
FastLineDarkenMOD(strength=50,luma_cap=255,threshold=3,thinning=0).distributor()
SetMTMode(5)
DCTFilter(1,1,1,1,1,1,1,0).distributor()
SetMTMode(2)
maa2(mask=1,chroma=false,ss=2.0,aa=48,aac=16,threads=3,show=0).distributor()
return(last)
There's nothing exiting going on in these scripts, at most one or two global variables (like increasing the allocated ram in this case) followed by calls for the desired filter plug-ins and whatever variables they have.
For just a bit of color correction a script could be as short as this:

Code: Select all

SetMTMode(5,4)
Tweak(sat=1.02,cont=1.03).distributor()
return(last)
It should be possible to spread the filter parameters out so there are lines with just the lone values.

But just being able to toggle a filter on or off by adding/deleting a "#" to/from a line would already be a big QoL feature.
No more copy/past'ing stuff together from sample scripts, just one script with all my fav filters in it and a rm skin with a bunch of badly labled buttons^^... that'd be a good start.
User avatar
balala
Rainmeter Sage
Posts: 9053
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

balala » January 6th, 2019, 4:25 pm

Let's clarify a few thing first:
  • Not sure what you mean by:
    protator wrote:
    January 6th, 2019, 10:10 am
    It should be possible to spread the filter parameters out so there are lines with just the lone values.
  • protator wrote:
    January 6th, 2019, 10:10 am
    But just being able to toggle a filter on or off by adding/deleting a "#" to/from a line would already be a big QoL feature.
    Is the # character the commenting out character in these scripts? Would you like to add / remove a such character in front of some lines? Have I understood well what you would like to achieve?
Yincognito
Posts: 682
Joined: February 27th, 2015, 2:38 pm

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

Yincognito » January 7th, 2019, 6:52 pm

balala wrote:
January 6th, 2019, 8:32 am
Yes, there is, the !WriteKeyValue bang, but using it Rainmeter can write only to .ini formatted file, replacing / adding some options. Otherwise maybe with .lua support. But it's not easy at all.
protator wrote:
January 6th, 2019, 10:10 am
This would be a worst case scenario:

Code: Select all

SetMemoryMax(1024)
SetMTMode(5,4)
Tweak(sat=1.02,cont=1.03).distributor()
SetMTMode(1)
AutoAdjust(auto_balance=true,chroma_limit=1.02,balance_str=0.02,use_dither=false,threads_count=2).distributor()
SetMTMode(2)
KNLMeansCL(d=1,a=2,s=4,h=1.0,channels="y",wmode=0,wref=1.0,device_type="gpu",device_id=1,info=false).distributor()
aWarpSharp2(thresh=190,blur=15,type=1,depth=2).distributor()
MSmooth(threshold=1,strength=1,chroma=true,highq=true).distributor()
aWarpSharp2(thresh=190,blur=15,type=1,depth=4).distributor()
FastLineDarkenMOD(strength=50,luma_cap=255,threshold=3,thinning=0).distributor()
SetMTMode(5)
DCTFilter(1,1,1,1,1,1,1,0).distributor()
SetMTMode(2)
maa2(mask=1,chroma=false,ss=2.0,aa=48,aac=16,threads=3,show=0).distributor()
return(last)
But just being able to toggle a filter on or off by adding/deleting a "#" to/from a line would already be a big QoL feature.
No more copy/past'ing stuff together from sample scripts, just one script with all my fav filters in it and a rm skin with a bunch of badly labled buttons^^... that'd be a good start.
I think this might be much easier to achieve than expected. One could just use the !WriteKeyValue bang in a Rainmeter skin to write this in an .ini format file, e.g. [!WriteKeyValue SomeRandomSectionName SomeKeyNameOrRowNumberID SomeKeyValueAkaAvsRowContent "SomeIniFile"]. This would create (or rather update) that .ini file into something like:

Code: Select all

[SomeRandomSectionName]
Row001=AutoAdjust(auto_balance=true,chroma_limit=1.02,balance_str=0.02,use_dither=false,threads_count=2).distributor()
Row002=SetMTMode(2)
............................
And then, just use the RunCommand plugin to execute a batch file (aka a .bat or .cmd) by setting the RunCommand's measure Parameter=SomeBatchFile.cmd. That batch file would have to change the previous .ini file's extension to an .avs one, remove the "[SomeRandomSectionName]" and "Row001=" strings from the file's contents and then execute the script. A button in the skin that would do the latter would bear a name like "Commit Changes And Run" or something like that. Voila!

Since Protator said that he created other skins as well, I assumed he would know how to implement this in detail. Of course, he should know the basics on batch commands - if not, there is always Google and StackOverflow ready to help with it... ;-)

So yes, it can be done. No Lua bull... you know what I mean. :D
User avatar
balala
Rainmeter Sage
Posts: 9053
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

balala » January 7th, 2019, 7:19 pm

Yincognito wrote:
January 7th, 2019, 6:52 pm
I think this might be much easier to achieve than expected. One could just use the !WriteKeyValue bang in a Rainmeter skin to write this in an .ini format file, e.g. [!WriteKeyValue SomeRandomSectionName SomeKeyNameOrRowNumberID SomeKeyValueAkaAvsRowContent "SomeIniFile"]. This would create (or rather update) that .ini file into something like:

Code: Select all

[SomeRandomSectionName]
Row001=AutoAdjust(auto_balance=true,chroma_limit=1.02,balance_str=0.02,use_dither=false,threads_count=2).distributor()
Row002=SetMTMode(2)
............................
And then, just use the RunCommand plugin to execute a batch file (aka a .bat or .cmd) by setting the RunCommand's measure Parameter=SomeBatchFile.cmd. That batch file would have to change the previous .ini file's extension to an .avs one, remove the "[SomeRandomSectionName]" and "Row001=" strings from the file's contents and then execute the script. A button in the skin that would do the latter would bear a name like "Commit Changes And Run" or something like that. Voila!

Since Protator said that he created other skins as well, I assumed he would know how to implement this in detail. Of course, he should know the basics on batch commands - if not, there is always Google and StackOverflow ready to help with it... ;-)

So yes, it can be done. No Lua bull... you know what I mean. :D
Yep, maybe this might be a solution as well. It's a bit weird in my opinion, but might work.
Let's wait for protator's reply, to see what he think about these solutions. Then we'll see...
Yincognito
Posts: 682
Joined: February 27th, 2015, 2:38 pm

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

Yincognito » January 7th, 2019, 7:33 pm

Here is a very basic sample skin (it only writes stuff to a AVSScript.avs file in the @Resources folder of the current skin):
AVS_1.0.rmskin
No need to change file's extension to .avs, Rainmeter can write to it as it is. One could use [!WriteKeyValue "" "" "#Row001#" "#@#AVSScript.avs"] to create an empty section "[]" and rows that have no key name on them, but that would make identifying rows more difficult. I've included this method in the skin, but it's commented. It's tested and it works with rows like "AutoAdjust(auto_balance=true,chroma_limit=1.02,balance_str=0.02,use_dither=false,threads_count=2).distributor()" that use multiple "=" and stuff.

To remove the "[Section]" and "Row001=" strings from the file, a batch along the lines of this or this would do the trick. Of course, it would have to be adapted for the needs of this task.
You do not have the required permissions to view the files attached to this post.
Last edited by Yincognito on January 7th, 2019, 7:46 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 9053
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

balala » January 7th, 2019, 7:40 pm

In the meantime, one more question: if no .lua script used, how will know Rainmeter what to write back into the file? Because protator initially asked to:
protator wrote:
January 6th, 2019, 5:43 am
I'd need the script to open the .avs file, go to a certain line and either change a specific value or, in case it's simpler that way, replace the whole line.
I think Rainmeter natively can't do this: can't read the content of the file, add a character to certain lines, then write back everything.
Yincognito
Posts: 682
Joined: February 27th, 2015, 2:38 pm

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

Yincognito » January 7th, 2019, 7:57 pm

balala wrote:
January 7th, 2019, 7:40 pm
In the meantime, one more question: if no .lua script used, how will know Rainmeter what to write back into the file? Because protator initially asked to:

I think Rainmeter natively can't do this: can't read the content of the file, add a character to certain lines, then write back everything.
Well, as far as I understood, the OP already has some "standard" script in mind when doing this, so it would be all about changing some values in an already typical line. So, the line AutoAdjust(auto_balance=true,chroma_limit=1.02,balance_str=0.02,use_dither=false,threads_count=2).distributor() would probably stay the same, except you change a few variables there and it would become AutoAdjust(auto_balance=false,chroma_limit=5.02,balance_str=1.02,use_dither=true,threads_count=1).distributor() or something.
balala wrote:
January 7th, 2019, 7:40 pm
I think Rainmeter natively can't do this: can't read the content of the file, add a character to certain lines, then write back everything.
Oh, but it actually can :great: ... if you set the section name to [Variables] and load it in the skin with a @IncludeVariables=FileName and only then modifying things with !WriteKeyValue-s. A bit of a back-reference, but theoretically doable. Am I right, my friend? :D
User avatar
balala
Rainmeter Sage
Posts: 9053
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rainmeter for changing parameters in .avs file (AVISYNTH)?

balala » January 7th, 2019, 8:06 pm

Yincognito wrote:
January 7th, 2019, 7:57 pm
Oh, but it actually can :great: ... if you set the section name to [Variables] and load it in the skin with a @IncludeVariables=FileName and only then modifying things with !WriteKeyValue-s. A bit of a back-reference, but theoretically doable. Am I right, my friend? :D
Doing it this way, yes, it can be done, but later processing is required, as yourself wrote, to remove section and option names.
Question is if it worth? :confused: