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. Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se |
|
|
#1 | Link |
|
Registered User
Join Date: Jun 2009
Location: UK
Posts: 269
|
Setting filenames and opening files
Hi all, I have a few questions for anyone who is familiar with the internals of AVIsynth. Not urgent. Consider this a moment of light relief from your intensive hacking and modding duties.
![]() Q1) If I write a script such as: Code:
Filename = "text" + ".avi" AVIsource(Filename) Q2) What I'm working around to is the following idea: Suppose I (or someone else) wrote a function or a plug-in that prompts the user for a filename/path (via a standard Windows-style file selector) and then returns that filename/path, and used it as follows: Code:
Filename = SelectFile() AVIsource(Filename) Q3) Has anyone ever written such a file-selector plug-in, or thought of adding such a function to Avisynth itself? Cheers.
|
|
|
|
|
|
#2 | Link |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
The assignment takes place during script loading, which occurs when the controlling application first opens the script file and before any frames are requested.
So if you had a plugin that prompted for an input file, the prompt would appear on script loading (so-called 'compile time'). For an example of such a plugin (albeit for the output file rather than input file), see SoundOut(). |
|
|
|
|
|
#3 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Such a plugin would need to be implemented as a compile time plugin (as Gavino says) and would be processed in
script order and results available to other following compile time functions (like string concatenation, in script order) and also standard filter functions (whose constructors are also called in script order).
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
|
|
|
|
|
#4 | Link |
|
Registered User
Join Date: Apr 2013
Location: Vienna, Austria
Posts: 55
|
I really like this idea. It should be supported out of the box.
As i liked it and it sounded like an hour of work, i started implementing. It really was easy, but unfortunately i still struggle with the win32 wchar and this stuff.. so in the end it took nearly 3,5 hours ;-) First you need to install microsoft visual c++ redistributeable version 2010, i believe the 32 bit one. Try the x64 one if this fails. http://www.microsoft.com/de-at/download/confirmation.aspx?id=5555 In attachment, you find the source code and a built version in the /release directory. Place the dll in the avisynth plugins folder and use it this way: Code:
fileselectionpopup() directshowsource(SELECTEDFILE) subtitle (SELECTEDFILE) Last edited by jordanh; 27th June 2013 at 23:44. Reason: private link deleted |
|
|
|
|
|
#5 | Link | |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Quote:
Code:
filename = fileselectionpopup() directshowsource(filename) # also allowing simply: directshowsource(fileselectionpopup()) |
|
|
|
|
|
|
#6 | Link | |
|
Registered User
Join Date: Apr 2013
Location: Vienna, Austria
Posts: 55
|
Quote:
You are welcome to patch it ;-) (you just need visual studio 2010 c++ express for it, its free. I think its really not more than retruning the "filename" string instead of hardcoded "true" from the fileselectionpopup function... Other features that may be interesting for this plugin would be to introduce parameters for fileselectionpopup() like fileselectionpopup(extensions = ".mxf,.mpg...",startfolder = "c:\") EDIT: acutally, i like setting stuff into hardcoded variable names. This way, it is just more obvious what is going on when you look over a script. It is a kind of standardisation. The negative sides of hardcoded variable names is clear: first there is the documentation issue, second it can be overwritten. It would be better to use more complex variablenames for this kind of integration. Last edited by jordanh; 23rd June 2013 at 19:11. |
|
|
|
|
|
|
#7 | Link |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Here how to return strings:-
Code:
char * strlit="AnyOldName";
int len=strlen(strlit);
char * s=new char[len+1];
if(s==NULL)
env->ThrowError("Cannot Allocate string mem");
strcpy(s,strlit); // dup
char *e=s+len; // point at nul
// make safe copy of string (freed on Avisynth closure)
AVSValue ret = env->SaveString(s,e-s); // e-s is text len only (excl nul) {SaveString uses memcpy)
// AVSValue ret = env->SaveString(s); // alternative, Avisynth uses strlen to ascertain length
// AVSValue ret = env->SaveString(s,-1); // alternative, Avisynth uses strlen to ascertain length
delete [] s; // delete our temp s buffer
return ret; // return Saved Str as AVSValue
// return strlit; // Alternative to MOST of above code char* converted to AVSValue.
// return "AnyOldName"; // Alternative to ALL of above code char* converted to AVSValue.
// String literals are read only and at constant address and so need not be saved.
EDIT: Dont use the one in red above (Its a bit naughty). Would be nice if it was as Avisynthesizer, using template to select source clips and auto create an avs based on template. (EDIT: This is complete BS, create avs from within avs ??? (although it still could have usage)) EDIT: OK, a bit less BS, run template AVS, import clip into that template using fileselector, which is basically what has been the suggested use by OP (I post like I play chess, without bothering to think) Fixed name a bad idea, would make selecting multiple files eg input clip and output log files awkward.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 14th December 2018 at 10:51. |
|
|
|
|
|
#8 | Link |
|
Registered User
Join Date: Apr 2008
Location: California, USA
Posts: 127
|
My two cents
A more useful variant would be a single AVIsynth command or plug-in call that paused the AVIsynth script while it waited for user input. In this way the input could be assigned to a variable used for anything the coder needed, including opening the designated file name. The feature should have both a default and timer variable that, if specified, set the maximum seconds before the process is aborted to return the specified default value.
A nice plus would be if the input supported a CTRL-V clipboard paste. |
|
|
|
|
|
#9 | Link |
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Worth noting that most of these considerations (use of SaveString and freeing locally allocated memory) also apply when setting a script variable instead of returning a string.
In jordanh's function, there is actually a memory leak of up to 1256 bytes per call (although fairly unimportant in a function that is called only at compile-time and probably only once). |
|
|
|
|
|
#10 | Link |
|
Registered User
Join Date: Apr 2013
Location: Vienna, Austria
Posts: 55
|
OK, now it is getting interesting.
Up in front, i dont see any issues with the "execution time" of this stuff. From my understanding, it behaves like this: 1) the avisynthplugininit function of all plugins is called at start of runtime, or "compile time" as the other say, in script order 2) getFrame is only called when the initializing application requests a frame. one just needs to do the SetVar stuff within the init function, thats it. Its just about the script order. I tend to open a new thread for gathering requirements of a new "external communcation plugin". First i must ask about the environment everyone is envisioning. You have to know, in my head it it only gets interesting when it can also be used in non-interactive mode. Meaning that avisynth is invoked by a background service and no user is logged in to the server where avisynth is runing on. Please state a few comments on this. I see SNMP, Mail, GUI by Script, commandline and many else communications. What makes sense, is there anything that gives unlimited power like just calling external programs and returning their return value? @Stainless: Thats extremely good code up there, thanks! Why not put that to the c++ wiki on avisynth.org? :-) @forensic: i did not understand the CTRL-V stuff. what kind of usercontext are you reffering to, what exactly is the content of clipboard? EDIT: we could send preview frames as base64 string (websites?) too :-) Last edited by jordanh; 24th June 2013 at 22:10. |
|
|
|
|
|
#11 | Link | |||
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Avisynthplugininit, just lets Avisynth know what functions are available, their names, argument names and types, so it can check
what is legal during compile time. (EDIT: Avisynth does not know what arg values are legal, and your code must do checks on those) Quote:
Before that, during compile time, as constructors are called and Filtered clips added to the graph, the parts of the graph that has already been built are available to compile time filters, and even runtime clip functions eg can getframe on already existing partial chain, although some tricks may be necessary if using standard builtin funcs like eg AverageLuma. (GScript is wonderfull). EDIT: You can even force a filter constructor/destructor during compile time (after processing using eg GScript) so making any output file available to subsequent functions (I love automation), useful in a sort of prescan to avoid 2 pass (EDIT: Do 2 pass but automatically, one after the other, 1st pass without display so possibly a bit quicker) . Quote:
(eg MediaInfo) but only returns a status on whether process was successfully started. Code:
RT_Call(String Cmd,bool "Hide"=false,bool "Debug"=false)
Run an external program using supplied cmd command line, hiding the console window if Hide==True.
Debug, If true, send some debug info to debugview including return code from called process.
DOS Filenames should be enclosed in quotes to avoid the system misinterpreting spaces in filenamess, see RT_QuoteStr().
Returns 0 if process successfully started, otherwise non zero (ie 1).
Example to write Aspect Ratio in form "1.333" to file D:\OUT\MEDINFO.TXT using command line version of MediaInfo.
RT_Call(RT_QuoteStr("D:\TEST\MediaInfo.Exe") + " --LogFile=" + RT_Quotestr("D:\OUT\MEDINFO.TXT") + \
" --Inform=Video;%DisplayAspectRatio% " + RT_Quotestr("D:\VID\1.mpg"))
EDIT: There is also an example somewhere on-site using ImageMagic (although I think that spelling is wrong). CallCmd (based on Call) does pretty much the same thing but is a standard filter function which allows calling an external command on particular frames, or in constructor,/destructor of filter. Quote:
By the way, latest Avisynth header for v2.5 is version 3, you used version 2 in FileSelector example. Would prefer to see something that does not depend on the Foundation class libraries, I'm not a Windows progger but have done a little WINAPI stuff eg RT_Call mentioned above. @Forensic, presumably you meant text on clipboard, when I get around to it I'll see if I can figure out how to do that, for RT_Stats (ie just get text from clipboard rather than CTRL-V, EDIT: if you meant BitMap, then say, I guess it would not be much more difficult).
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 25th June 2013 at 09:27. |
|||
|
|
|
|
|
#12 | Link | |
|
Registered User
Join Date: Apr 2013
Location: Vienna, Austria
Posts: 55
|
Quote:
In the end, the fileselection plugin i sumitted above does the SetVar stuff only when it is exported main function is called in the avs script. Avisynth is still able to build the graph. I stay at: No problem regarding "execution" time. Any other feature requests, design proposals or similar? Especially use-cases for needed userinteraction (besides loading a source file) would be interesting... Last edited by jordanh; 25th June 2013 at 01:03. |
|
|
|
|
|
|
#14 | Link | |
|
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,406
|
Quote:
The void pointers within Avisynthplugininit are intended to pass info from that func into your Create type funcs, but only the Avisynth "Glitterati" seem to know much about that. (eg alloc mem, init and pass secret info to your create func, I think, also I think, something in Avisynth SDK docs, "Non-clipsample" I think, something to do with fonts and AtExit) Building the Graph is basically compile time. Execution time is never going to be an issue with a Fileselector (except that you have to wait for a human to do something, you could wait hours). EDIT: A Timeout on such a File Selector (as suggested by Forensic) is likely to be a much bigger deal that the FileSelector itself. Would love to see non Foundation Class Library source (to give me a starter), I could then include similar funcs into RT_stats. would need FS (Fileselector) for Existing file ie input and non existing files eg Output, also Multiselect files for group selection. (EDIT: I also usually only use VS6 or Toolkit III compilers and so would not want anything reliant on VS2008 etc, also, I think Foundation Class Library stuff not available in some Express versions VS and so would want to avoid). I'm as said earlier, not a windows progger, never actually liked the PC, but all other machines now deceased, so have no alternative except Apple. Would love it though if you could impart some of you knowledge, so I could copy most of it off you. ![]() EDIT: Thanx J, that's now two (I think) entries on Wiki I've got. J, I have a thread that is really for C to Avisynth CPP quick learner guide that might have something that might interest you. Obviously you are an accomplished programmer and dont need any kind of beginner guide (much less of a CPP beginner than me) but there may (or may not) be some things that might be of use, not too long, might be worth a look). here: http://forum.doom9.org/showthread.php?t=163082 EDIT: The main reason I suggest this is I've put in debug messages to see where the init is and constructor/destructor calls are etc. EDIT: Also, I think I'm correct in saying that during eg Eval/ScriptClip, you are then in a NEW compile time period, where a chunk of text is evaluated in real time, where previous statements about compile time mostly hold true. EDIT: RT_Stats has an RT_Debug() function which outputs strings to DebugView Window, great for tracking whats happening, can also wrap it in ScriptClip or eg FrameEvaluate to see what is happening during Frame Serving stage.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 25th June 2013 at 16:42. |
|
|
|
|
|
|
#15 | Link |
|
Super Moderator
![]() Join Date: Nov 2001
Location: Netherlands
Posts: 6,375
|
@jordanh,
Please use avisynth.nl the next time. I've added it to http://avisynth.nl/index.php/Cplusplus_API#AddFunction. |
|
|
|
|
|
#16 | Link |
|
Registered User
Join Date: Apr 2013
Location: Vienna, Austria
Posts: 55
|
Thanks Wilbert!
@everything else: I would like to have a look at avisynth source code in order to learn how and when all this stuff is done. By now i didnt look too much into the avisynth source code too much, but i am very interested in. Anyone has a clue where the script parsing and execution stuff is done? i wasnt able to find it in avisynth.cpp or directshow_source.cpp... @Stainlesss: sorry, i really dont understand your concerns. Refering to the submitted example plugin above, i could do anything i like once the script engine calls the exported (env->AddFunction) function that is called from the avs script in order to request a userinput. Did you try the plugin? |
|
|
|
|
|
#18 | Link | |
|
Excessively jovial fellow
Join Date: Jun 2004
Location: rude
Posts: 1,100
|
Quote:
|
|
|
|
|
|
|
#20 | Link |
|
Registered User
Join Date: Apr 2013
Location: Vienna, Austria
Posts: 55
|
@TheFluff: sorry for not explaining my reasons, thats a too long story. I basically agree with you, it was a bad decision to use this method in the example above.
However, the plugin above is clearly commented as non productive, example and not continued. You show a strange way to submit feature requests. The Plugin above cannot be continued, its just a proof of concept. Stainlesss already required non MS Foundation code, so it needs to be rewritten from scratch anyway. (its only about 20 interesting lines of code...) By now i still only have 3 requirements for the plugin: * dont use win32 api * support default and timeout * return values ..and only one usecase: file selection Arent there other situations when a user decision would be nice to have? Back to the Topic: Meanwhile thanks to Groucho i got out, that functions of interest are: Code:
//avisynth.cpp
// Constructor of ScriptEnvironment:
ScriptEnvironment::ScriptEnvironment()
...
global_var_table->Set("true", true);
global_var_table->Set("false", false);
global_var_table->Set("yes", true);
global_var_table->Set("no", false);
...
PrescanPlugins();//doesnt call any function of the plugin
ExportFilters(); //doesnt call any function of the plugin
This function is parsing a single function and its arguments Code:
//avisynth.cpp
AVSValue ScriptEnvironment::Invoke(const char* name, const AVSValue args, const char** arg_names) {...
//ends up in: (didnt get out what exactly this does)
// ... and we're finally ready to make the call
retval = f->apply(AVSValue(args3, args3_count), f->user_data, this);
Still, i struglle getting out, where the parsing stuff is used from. What i need to get out is where the part of "compilation" or parsing or whatever people above are referring to... |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|