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. |
|
|
Thread Tools | Search this Thread | Display Modes |
5th March 2009, 22:06 | #1 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
Can I access the script filename in a predefined string variable?
I usually name .avs scripts same as the video files.
Usually, my first script line reads something like 's= "myVideo" ' and I refer to that string in the source functions, appending ".avi", ".wav" or whatever. It would be extremely convenient to have a predefined variable (like "last"), that allowed me to use the name of the script file within the script. I would then just set 's' to the script name and as soon as I copied an .avs template to the filename of a video file, the script would work instantly on that file - no more need to edit the script! Maybe even calling a script that is called "myVideo--TFF.avs" is able to open "myVideo.avi" and setting a TFF switch - but that would require string separation commands, and I don't think I saw functions like BASIC's Left(), Mid() and InStr() in the doc..? Can anyone please help me on this? EDIT: I am copying stickboy's previous solution from the other thread here. stickboy! - I just changed from complete name to basename for *.avs files, because this way you just need to write 'GetScriptBasename()+".avi"' to reference your video file - Code:
function GetScriptBasename() { Try { assert(false) } Catch(err_msg) { err_msg = MidStr(err_msg, FindStr(err_msg, "(") + 1) filename = LeftStr(err_msg, StrLen(err_msg) - FindStr(RevStr(err_msg), ",") - 4) return filename } } Last edited by martin53; 6th March 2009 at 18:43. |
6th March 2009, 01:19 | #2 | Link |
Registered User
Join Date: Dec 2004
Location: Melbourne, AU
Posts: 1,963
|
There's LeftStr, MidStr, RightStr and FindStr functions. Unfortunately there's no function (that I know of) to give the name of the current script, maybe IanB will add it if we ask nicely enough.
|
6th March 2009, 14:22 | #5 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
It's been done before. See this thread; in particular, stickboy's solution.
|
11th March 2009, 14:04 | #8 | Link |
Registered User
Join Date: Dec 2007
Location: Enschede, NL
Posts: 301
|
I tried to solve the problem by writing a plugin that retrieves the commandline and from there gets the name of the script. It was my first C++ program and fun to make, and it works ok in a lot of cases, but not always (it doesn't work if you open the script from an open file dialog).
The other solution that's posted before is better. Getting the commandline from a plugin also gives the opportunity of getting the name of the calling program, which in turn gives a lot of possibilities for other tweaks. If anyone is interested in my new ProgramName solution which retrieves the name of the calling program, just say so. |
11th March 2009, 15:00 | #10 | Link |
Registered User
Join Date: Dec 2007
Location: Enschede, NL
Posts: 301
|
OK. It was my first C++ avisynth thingy. The interesting part is maybe the possibility in avisynth to generate different output for different programs, for example a simple fast output for previewing (with for example framenumbers) and a denoised slow output for encoding. You could also use this value to process things differently in the avisynth filter of ffdshow.
|
11th March 2009, 15:07 | #11 | Link | |
Registered User
Join Date: May 2006
Posts: 957
|
Quote:
I was looking for this about a week ago so that the script could automatically switch from the previews I was doing to the slow(ish) encoding script. In the end I just ended up using (true) ? a : b and manually editing the true/false.
__________________
x264 log explained || x264 deblocking how-to preset -> tune -> user set options -> fast first pass -> profile -> level Doom10 - Of course it's better, it's one more. |
|
11th March 2009, 16:28 | #12 | Link | |
Registered User
Join Date: Dec 2007
Location: Enschede, NL
Posts: 301
|
Quote:
Last edited by jmartinr; 20th December 2015 at 23:52. Reason: update download link |
|
21st November 2011, 05:02 | #14 | Link |
Registered User
Join Date: Aug 2008
Posts: 233
|
I know this is a fairly old thread... I remember reading it when it was new; as determining the script name is something that would be important and handy for me. I have revisited the problem from time to time, finding no perfect solution. (and to my knowledge, no complete solution for AviSynth 2.5.8 exists)
I do believe, however, that I have made a "slightly" more elegant modification to this wonderfully dirty method of getting the script name. Given the limitation that the error itself (from which the script name is parsed) can only work in a script and not in an .avsi file, I have striven to pare down the scripting as much as possible. First, let's make a parsing function called _ScriptName() and put that into an .avsi file: Code:
function _ScriptName(string err_msg) { err_msg = MidStr(err_msg, FindStr(err_msg, "(") + 1) filename = LeftStr(err_msg, StrLen(err_msg) - FindStr(RevStr(err_msg), ",")) return filename } Code:
Try {_} Catch(_) {_=_ScriptName(_)} # now access it for some function subtitle(_) I like the _ because it is brief as can be and it reminds me of Special Variables in other scripting languages. Plus, you only need one line of code in your script to get the variable - and it is a cool and bizarre-looking line at that! Last edited by vampiredom; 21st November 2011 at 17:10. Reason: fixed an error, heeded Gavino's advice. |
21st November 2011, 05:50 | #15 | Link |
typo lover
Join Date: May 2009
Posts: 595
|
avs2.6 has internal functions ScriptName()/ScriptFile()/ScriptDir().
What is lost does not have anything and many obtain, that is the reason I use 2.6.0a3.
__________________
my repositories |
21st November 2011, 10:26 | #16 | Link | ||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Quote:
function _ScriptName(string err_msg) Actually, just spotted you have used err_meg in the default line, so the assigned value was never used. Last edited by Gavino; 21st November 2011 at 10:30. |
||
21st November 2011, 10:29 | #17 | Link |
Registered User
Join Date: Dec 2007
Location: Enschede, NL
Posts: 301
|
Why don't you keep it simple and call your variable ScriptName?
__________________
Roelofs Coaching |
21st November 2011, 17:12 | #18 | Link | ||
Registered User
Join Date: Aug 2008
Posts: 233
|
Quote:
Quote:
Last edited by vampiredom; 21st November 2011 at 17:20. |
||
22nd November 2011, 20:09 | #19 | Link |
Registered User
Join Date: Aug 2008
Posts: 233
|
For completeness and forward-compatibility, it would make sense to have the _ScriptName() function attempt to return the results of the native function for those who have AviSynth 2.6 installed (or more future versions, presumably)
Code:
# in .avs script Try {_} Catch(_) {_=_ScriptName(_)} AVSfilename = _ # in .avsi file function _ScriptName(string err_msg) { Try { # If AviSynth 2.6 is installed, use the native function ScriptName() } Catch(err) { err_msg = MidStr(err_msg, FindStr(err_msg, "(") + 1) filename = LeftStr(err_msg, StrLen(err_msg) - FindStr(RevStr(err_msg), ",")) filename } } |
23rd November 2011, 00:34 | #20 | Link |
Registered User
Join Date: Dec 2007
Location: Enschede, NL
Posts: 301
|
Or maybe:
Code:
# in .avs script Try {_ = ScriptName()} Catch(_) {_=_ScriptName(_)} AVSfilename = _ # in .avsi file function _ScriptName(string err_msg) { err_msg = MidStr(err_msg, FindStr(err_msg, "(") + 1) filename = LeftStr(err_msg, StrLen(err_msg) - FindStr(RevStr(err_msg), ",")) filename } }
__________________
Roelofs Coaching |
Thread Tools | Search this Thread |
Display Modes | |
|
|