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. |
8th October 2012, 23:34 | #1 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
CallCmd v1.04 - x86 & x64 -Execute command
Plugin to execute command on selectable frames or at startup or closedown.
Code:
v1.00, - 08 Oct 2012, Changed Frames spec, added Open,Close v1.01, - 21 Oct 2012, Add Synchronous Arg. v1.02, - 1 Jan 2013, Add error message on fail. v1.03, , SetLastError(ERROR_SUCCESS) prior to call. v1.04, - 3 Apr 2018, compile VS2008 (+x64) Code:
CallCmd() by StainlessS:- http://forum.doom9.org/showthread.php?t=166063 Based on Call by Nic:- http://forum.doom9.org/showthread.php?t=46506 -------------------------------------------------------------------------------- CallCmd() by StainlessS CallCmd(clip,string "Command"="", string "Frames"="",string "Insert"="",int "Digits"=6,bool "Once"=true,int "Offset"=0, bool "Hide"=false,bool "Debug"=false,string "Open"="",string "Close"="",int "Synchronous"=7) Command (default"") A command string that will be executed on each frame specified by the Frames arg. Can contain a single INSERT arg character which will be replaced by a string representing the frame number with optional OFFSET. If the command naturally contains the INSERT character then choose a different INSERT charcter or use two INSERT characters in the Command string to escape it (one of them will be removed in the executed command). Frames (default "") String to specify the frames upon which the COMMAND arg is executed. Comments beginning with '#' can occur in the FRAMES arg, SEMICOLON Cannot be used in a comment. SEMICOLON ";" or NewLine [Chr(10)] is used as a frame specifier terminator. COMMA "," specifies a frame range where the 2nd range end number can be '0' meaning last frame, and eg '-4' meaning 4 frames. "0,0" Specifies ALL frames. Example: FRAMES=" 1 # This is a comment, calls on frame 1. 3;5;7 # Calls on frames 3 and 5 and 7, SEMICOLON is SOFT End Of Line and terminates any COMMENT. 8 # Call Frame 8 ; 10 # *** IMPORTANT *** And because of SEMICOLON also calls on Frame 10. 14,16 # Calls on frames 14 to 16, COMMA specifies a frame range. 18,20;22 # Calls on Frame range 18 to 20 and frame 22. 24,-4 # Specifies frames 24 to 27, ie 4 frames starting at frame 24. " Insert (default "") Single character which will be replaced in the Command arg string by frame number + OFFSET arg. If the command naturally contains an INSERT character then choose a different INSERT arg charcter or use two INSERT characters in the Command string to escape the naturally occuring one (one of them will be removed in the executed command). Digits (default 6) Minimum number of digits generated in inserted text that replaces the INSERT character in the COMMAND arg. Once (default=true) If true then only executes frame commands once on each frame, if replayed, does not exec 2nd time. Offset (default 0) Offset added to frame number when generating text inserted into a frame command replacing the INSERT character. Hide (default false) If true, hide black console window on command execution. Debug (default false) If true, sends debug info to DebugView Window. DebugView (Highly recommended, allows viewing of info and warnings from the plugins and other programs) http://technet.microsoft.com/en-gb/sysinternals/bb545027 Open (default "") Command executed on plugin start up (Constructor), before first frame. No string replacements, ie INSERT, DIGITS and OFFSET have no effect. Close (default "") Command executed on plugin close down (Destructor), after last frame. No string replacements, ie INSERT, DIGITS and OFFSET have no effect. Synchronous (default 7, range 0 - 7) The Synchronous arg is a group of 3 bitflags, bit 0 if set means wait for process to terminate before returning from the 'Open' command. bit 1 if set means wait for process to terminate before returning from the 'Frames' commands. bit 2 if set means wait for process to terminate before returning from the 'Close' command. 0 = All Asynchronous, ie dont wait at all. 1 = Wait only on 'Open' command. 2 = Wait only on 'Frames' commands. 3 = Wait on 'Open' and 'Frames' commands. 4 = Wait on 'Close' command. 5 = Wait on 'Open' and 'Close' commands. 6 = Wait on 'Frames' and 'Close' commands. 7 = Wait on ALL commands (default). Beware, if you dont wait it is very possible that any future reliance upon output of command may fail due to the output file being in use. Also, if debug true and waiting for process to complete, then will also show the process return code on successful process creation (and completion) in DebugView, cannot do this if NOT waiting completion. ----------------------------------------------------------------------------- CallCmd, does NOT replace single quotes with double quotes in Command string, was source of problems in Call(). Instead wrap eg filenames containing spaces in double-quotes using perhaps: Function QuoteStr(String s) { return Chr(34) + s + Chr(34) } or use triple and single double-quotes eg CallCmd(BlankClip,Close="""d:\nicecho.exe @d:\report.txt "Appending" """) --- Executing on each playing, on every frame, hiding console window, sending debug info to debugview, and converting command string on frame eg 0 to "C:\PortableApps\ImageMagick\Mogrify.exe -flop C:\Temp\000000.tif" CallCmd(clip,"C:\PortableApps\ImageMagick\Mogrify.exe -flop C:\Temp\#.tif", "0,0",Insert="#",Once=false,Hide=true,Debug=true) At Open, executes delete on wildcard files silently, without asking confirmation. CallCmd(Open="""cmd /c DEL /Q "C:\TEMP\test_*.tif" """) To execute DOS type commands, in DOS console type "cmd /?" for cmd options, and eg DEL /? for delete options. ssS req VS 2008 runtimes. Available from MediaFire or SendSpace in Sig.
__________________
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; 4th April 2018 at 01:03. |
9th October 2012, 01:27 | #2 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Posted here by Martin53:
http://forum.doom9.org/showthread.ph...90#post1594690 Code:
CMD= "cmd/c del " + QuoteStr(TMPDIR + BASENAME + RD_NSTR + EXT) + \ " && ren "+ QuoteStr(TMPDIR + BASENAME + INSERT + EXT) + " " + QuoteStr(TMPDIR + BASENAME + RD_NSTR + EXT) + \" && " + QuoteStr(IM) + IMCMD + QuoteStr(TMPDIR + BASENAME + RD_NSTR + EXT) #RD_NSTR = "%0"+String(DIGITS)+"d" RD_NSTR = "000000" Code:
ColorBars().ShowFrameNumber().ConvertToRGB24().Trim(0,499) IM="C:\PortableApps\ImageMagick\Mogrify.exe" # ImageMagick Mogrify exe TMPDIR="C:\Temp\" # Output directory for images IMCMD =" -flop " # Image Magick Mogrify Command, Horizontal Flip (Or whatever). TYPE ="tif" # Extension type CMDFILESPEC=QuoteStr(TMPDIR + "#" + "." + TYPE) CMD= QuoteStr(IM) + IMCMD + CMDFILESPEC DEL= "cmd /c del /Q " + CMDFILESPEC W=Width # Remember orig width # ImageWriter(TMPDIR,0,-1, type=TYPE).RT_AverageLuma(n=0,w=1,h=1) # Force 1st image else error in ImageReader # -------------------------------- ImageWriter(TMPDIR,0,0, type=TYPE) CallCmd(CMD,"0,0",insert="#",once=false,hide=true) StackHorizontal(ImageSource(TMPDIR+"%06d."+TYPE,0,FrameCount-1)) Crop(W,0,-0,-0) # Comment out to show input and h-flipped output side by side CallCmd(DEL,"0,0",insert="#",once=false,hide=true) Return Last # -------------------------------- Function QuoteStr(String s){Chr(34) + s + Chr(34)} Tried going backwards and jumping about, seems to still work without problems and no images left in TMPDIR. If you set up a RAMDISK for temp files/file (and perhaps imagemagick), it might fly like a bat out of hell, then again it might not. RAMDISK.SYS or similar, http://en.wikipedia.org/wiki/List_of_RAM_drive_software). Would be interested in hearing if it made much (if any) difference. EDIT: Actually, the DEL command seems to take quite a bit of time to execute, perhaps CMD.exe would need to be on ramdisk too, or a better, a lightweight DEL type command obtained. It's disappointingly slow compared to the figures you gave for scriptclip version, dont know why yet. EDIT: See RT_Stats RT_FileDelete().
__________________
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; 3rd November 2014 at 16:31. |
20th October 2012, 17:55 | #3 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
StainlessS,
hope you don't mind that I respond so late. I'm very much involved in my daytime job and the frame substitution filter. Same will apply in the future, i'm afraid. Does C++ offer a "wait for return" switch for a shell call? With Visual Basic Script shell calls, I know such a switch. I never mentioned it before, because all Calls I could imagine would not reasonably continue before the shell command was executed. But it's a different thing with the DEL command. That could well be finished asynchronously. |
21st October 2012, 17:56 | #4 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
CallCmd waits for the process to both start and end (as Call did), I guess I could add an arg to return immediately,
It might well be the CMD.Exe that is slow to start though, I know it checks eg AutoRun type entries in the registry and probably an amount of other startup stuff. (CMD /D disables AutoRun). I'll add the arg soon. EDIT: RAMDISK dont seem to be beneficial, guess that the ScriptClip single tif version is hitting the disk cache all of the time and therefore gives better performance.
__________________
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; 21st October 2012 at 17:59. |
21st October 2012, 21:41 | #5 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
What would be really cool is to call an external program on frames and be able to return an image. There are some pretty cool filters (research) that you could call that only work on one frame. Usually they only support one frame or simple bmps. There are a lot of extra steps to make them process video. Being able to simply embed a command line to serve frames to external image processing would be amazingly easier.
I think it's quite easy to code; just read out the current frame in a loop and write it as a temp file as a BMP (the format is quite simple to do), call the command, the command does "process -i in.bmp out.bmp" and have the program wait, then read out.bmp and return that to Avisynth. If you have everything setup for development, it's just a few more lines of code; except writing the .bmp part, but I've done that by hand, you can copy the header from any existing file and just change the width and height and file length values. All I remember is it starts with BM One more feature, I might need at least 3 passes so next version have option to send each plane as separate calls (either r,g,b or y,u,v) Oh you know how nice that would be.. instead of fiddling with command lines and loading the results in an image viewer, it can all be done in AvsP with instant preview, all it's features for script editing, user sliders! It's like istant gui for cmd line. Last edited by jmac698; 21st October 2012 at 22:01. |
21st October 2012, 21:41 | #6 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
CallCmd() v1.01, New version, added 'Synchronous' arg.
@Jmac, oops you just clipped me. Think that the suggested plug would be another filter. Quote:
EDIT: I dont really see it as being any great improvement over using ImageWrite/CallCmd/ImageRead combo, just a lot more work for YOU.
__________________
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; 21st October 2012 at 22:04. |
|
21st October 2012, 22:12 | #8 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
http://forum.doom9.org/showthread.ph...54#post1594454
Also, dont know if you did eventually find the Showchannels update (as requested). Page 2 of Usage section. EDIT: @Martin53, trust you saw the MDepan stuff in RT_Stats (last post), together with the StrReplace problem that you would encounter (fixed here: http://forum.doom9.org/showthread.ph...53#post1596053)
__________________
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; 21st October 2012 at 22:32. |
1st January 2013, 22:11 | #9 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
New version v1.02, Appends system error message on fail when debug=true (debugview).
See first post.
__________________
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 ??? |
13th November 2013, 18:31 | #10 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Can any DOS wizard assist here ?
What I want to do is execute a line like this Code:
C:\WINDOWS\system32\cmd.exe /K "C:\BIN\ffprobe.exe -i D:\AVS\AVI\TEST.VOB" "C:\WINDOWS\system32\cmd.exe" is the DOS CLI /K means keep console window open on completion (will eventually use /C ie close on completion) "C:\BIN\ffprobe.exe -i D:\AVS\AVI\TEST.VOB" is command to be executed by the DOS CLI together with args for target executable. What I want is to redirect output from ffprobe (written to DOS CLI console window via stderr or stdout) to a file, is there a way to redirect output from a NON DOS command (DOS COMMAND being eg DIR) where the NON DOS command does not provide a way to accomplish same thing. thanks in advance
__________________
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 ??? |
13th November 2013, 18:45 | #11 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
I don't own ffprobe.exe . But generally the job split is like this:
- All executables should write to the streams stdout, stderr etc., i.e. this is not restricted to cmd.exe-internal commands. - Cmd.exe allows to redirect or pipe stdout to a file with the '>' operator overwriting or '>>' appending. There is a Syntax '2>' to redirect "stream 2" stderr: Try 'NonexistentCommand 2>test' at the command line. The file 'test' will contain cmd.exe's error message. You sure tried 'C:\WINDOWS\system32\cmd.exe /K "C:\BIN\ffprobe.exe -i D:\AVS\AVI\TEST.VOB" >Path\File'. What did happen instead of the expected behaviour? EDIT: Many old compiler packs contained a program TEE.EXE. You pipe any program's output to TEE and give TEE a file name. TEE mirrors its input to both stdout and the file. Last edited by martin53; 13th November 2013 at 18:49. |
13th November 2013, 18:48 | #12 | Link | |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Quote:
Code:
C:\WINDOWS\system32\cmd.exe /K "C:\BIN\ffprobe.exe -i D:\AVS\AVI\TEST.VOB 2> file.txt" |
|
13th November 2013, 18:55 | #13 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
Cmd.exe does not expect everything after /C or /K to be one quoted string.
Code:
C:\WINDOWS\system32\cmd.exe /K C:\BIN\ffprobe.exe -i D:\AVS\AVI\TEST.VOB 2> file.txt Code:
C:\WINDOWS\system32\cmd.exe /K C:\BIN\ffprobe.exe -i "D:\AVS\AVI path with spaces\TEST.VOB" 2> "D:\Output path with spaces\file name with spaces.txt" |
13th November 2013, 18:55 | #14 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Dang but you are correct.
Had already tried same but failed, musta screwed up somewhere and thought it down to cmd.exe needing executable string at END of line (according to "CMD /?"). Thank you. EDIT: I consider my bottom, justly smacked
__________________
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 November 2013 at 17:41. |
13th November 2013, 20:02 | #16 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
ffprobe.exe is part of ffmpeg, although may not always come with all packages.
Using string to CallCmd (EDIT: well actually RT_Call, but almost same thing) Code:
C:\WINDOWS\system32\cmd.exe /K "C:\BIN\ffprobe.exe" -i D:\AVS\AVI\TEST.VOB 2> D:\AVS\AVI\TEST.TXT Code:
ffprobe version N-44264-g070b0e1 Copyright (c) 2007-2012 the FFmpeg developers built on Sep 7 2012 17:35:17 with gcc 4.7.1 (GCC) configuration: --enable-gpl --enable-version3 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable- frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib libavutil 51. 72.100 / 51. 72.100 libavcodec 54. 55.100 / 54. 55.100 libavformat 54. 25.105 / 54. 25.105 libavdevice 54. 2.100 / 54. 2.100 libavfilter 3. 16.100 / 3. 16.100 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 15.100 / 0. 15.100 libpostproc 52. 0.100 / 52. 0.100 [mpeg @ 0231c500] max_analyze_duration 5000000 reached at 5024000 Input #0, mpeg, from 'D:\AVS\AVI\TEST.VOB ': Duration: 00:08:49.63, start: 499.807267, bitrate: 5068 kb/s Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 64:45 DAR 16:9], 7500 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), s16, 384 kb/s Stream #0:2[0x81]: Audio: ac3, 48000 Hz, stereo, s16, 192 kb/s Code:
C:\WINDOWS\system32\cmd.exe /K C:\BIN\ffprobe.exe -i "D:\A V S\AVI\TEST.VOB" 2>"D:\A V S\AVI\TEST.TXT" then fails, could not find any combination of single/triple quotes that worked for all three paths. EDITED: One of the problems is that, enclosed in quotes, ffprobe complains about it's own file name being supplied as an arg to ffprobe, perhaps it is only an ffprobe problem, and not a general prob.
__________________
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 November 2013 at 02:11. |
1st December 2013, 15:54 | #17 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
Just updated to V1.02 as you proposed, but now cannot open my clip any more:
I just need CallCmd in destructor. But V1.02 complains about the empty frames string and refuses to go on. Btw the V1.02 plugin has name 1.01 on mediafire - or I'm struggling with 1.01 and 1.02 was not published. M53 EDIT: not true. The new version complained about the other calls that were not yet corrected to the new syntax, but still read "-3" as frame identifier, instead of using the new 'Close=' parameter. Last edited by martin53; 1st December 2013 at 16:14. Reason: found the bug |
1st December 2013, 19:09 | #18 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Sorry, yes v1.01 should have read v1.02, just forgot to rename the containing folder before zipping, shall re-upload now using correct name.
Quote:
something like this Code:
colorbars CallCmd(command="CMD DIR C:\",frames="-3",debug=true) Code:
00000001 0.00000000 CallCmd: Constructor IN 00000002 0.00001575 CallCmd: CallCmd: v1.02 - 01 Jan 2012 - by StainlessS 00000003 0.00004092 CallCmd: Command for Frames = 'CMD DIR C:\' 00000004 0.00016734 CallCmd: FRAMES: About to Parse Frames String 00000005 0.00019256 CallCmd: FRAMES: Line 1:1 *NON PARSE* $-3 @ -3 This being more like call on close Code:
colorbars CallCmd(close="""CMD /C "DIR C:\" """,debug=true) Code:
00000001 0.00000000 CallCmd: Constructor IN 00000002 0.00001629 CallCmd: CallCmd: v1.02 - 01 Jan 2012 - by StainlessS 00000003 0.00004046 CallCmd: Command for Frames = '' 00000004 0.00006518 CallCmd: Close Command (Destructor) = 'CMD /C "DIR C:\" ' 00000005 0.00018594 CallCmd: FRAMES: About to Parse Frames String 00000006 0.00021042 CallCmd: Doing command on 0 Frames 00000007 0.00023386 CallCmd: Constructor OUT 00000008 2.17909861 CallCmd: Destructor IN 00000009 2.17913342 CallCmd: Close (Destructor) on command 'CMD /C "DIR C:\" ' 00000010 2.23332262 CallCmd: SUCCESS Creating Process (WAIT) 00000011 2.23336267 CallCmd: WAIT, Process returned 0 (0x00000000) 00000012 2.23341632 CallCmd: Destructor OUT EDITED: EDIT: OOPS, now I understand, you mean your script still used old frames spec of -3, thought you meant that the new version still worked with old spec, silly me.
__________________
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; 1st December 2013 at 19:37. |
|
2nd December 2013, 18:35 | #19 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
StainlessS,
I got everything running . I was trying to say that I used 3 calls, and only had converted one to the "close=" syntax. Therefore, the first of the other two remaining script lines produced the output you wrote: "...*NON PARSE* $-3 @ -3" - and I misunderstood this as an error message of the line I had already changed. After I also changed the other two lines, it was fine! |
5th December 2013, 23:40 | #20 | Link |
Registered User
Join Date: Aug 2008
Posts: 233
|
I simply MUST try this ... I would love to get rid of my crazy Call25Helper.exe hack. Unfortunately, I have been really short on time to test out new things. I will try this out and get back to you. Thanks, Stainless.
|
Tags |
call, execute |
Thread Tools | Search this Thread |
Display Modes | |
|
|