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 > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 7th November 2015, 21:48   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
TWriteAVI v2.05 - 29 July 2018

TWriteAVI by Tritical, Squid_80 and Mikeytown2, v2.0 update StainlessS.
Moved here from MPEG 2 Encoding forum. http://forum.doom9.org/showthread.ph...71#post1745671

Code:
TWriteAVI v2.05

TWriteAVI v2.0, write to lossless file whatever can be played, to AVI (or WAV), and using the ForceProcessAVI/WAV functions, can write the
files without playing them (and faster than eg VDub Video Analysis Pass [about 70% of VDub time]).

DO NOT USE with MT, is already multi-threaded and will crash/mess up AVI or WAV file format.

Function TWriteAvi(clip c,String filename,bool "overwrite"=false,bool "showall"=false,string "fourcc"="",int "dwChannelMask"=-1)

 c, Video clip with optional audio. ALL valid colorspaces with exception of YV411.
 Filename: NOT optional. Output filename.
 Overwrite: Fails on existing unless overwrite==True.
 Showall: Default false. Shows all codecs, not just ones supporting  your clip colorspace.
 Fourcc: Default "". Characters UPPER case (usually) fourCC code for codec, eg "ULY0" for YV12 UT_Video rec601.
 dwChannelMask: Default -1.
     -1 = No Override, Use standard mapping as for v2.6 OPT_dwChannelMask.
     0 = Non Located ie multiple MONAURAL channels.
     Otherwise, need 1 bit set for each valid channel, see dwChannelMask flags at below link.
        https://msdn.microsoft.com/en-us/library/windows/desktop/dd390971%28v=vs.85%29.aspx
        Or in brief defaults here on Wiki:- http://avisynth.nl/index.php/Internal_functions#OPT_dwChannelMask
        Or in full, https://msdn.microsoft.com/en-us/library/windows/hardware/dn653308%28v=vs.85%29.aspx

 Removed old Idxname arg (was not much use).
 Writes clip to filename returning original clip (after equivalent of Trim(0,0), audio trim/pad to same len as video).
 Audio 8, 16, 24 and 32 bit, also Float. Up to 8 channels (7.1), written as uncompressed PCM or IEEE 32 bit Float format.
 Will auto close output FILE on last frame.
 NOTE, for clips where audio is longer/shorter than video, TWriteAVI will do equivalent to Trim(0,0) to trim/pad audio to same length
 as video (no effect if no audio).

 v2.03, Modified behaviour a little. Now if frames not requested in strictly sequential order, will write all intervening frames between
 last written frame and requested frame, if requested frame already written then requested frame will not be written a second time.

#######

ForceProcessAVI(clip c,bool "Debug"=True)
 Force Process clip c, ie read from first to last frame, for TWriteAVI writes the AVI file (Video + Audio) without having to play clip.
 Debug, default True, sends some progress info to DebugView (google).

##############

Function TWriteWAV(clip c,String filename,bool "overwrite"=false,int "dwChannelMask"=-1)
 c, clip with audio.
 Filename: NOT optional. Output filename.
 Overwrite: Fails on existing unless overwrite==True.
 dwChannelMask: Default -1.
     -1 = No Override, Use standard mapping as for v2.6 OPT_dwChannelMask.
     0 = Non Located ie multiple MONAURAL channels.
     Otherwise, need 1 bit set for each valid channel.

 Writes audio from clip to filename returning original clip (return audio is NOT trimmed to same length as video).
 Audio 8, 16, 24 and 32 bit, also Float. Up to 8 channels (7.1), written as uncompressed PCM or IEEE 32 bit Float format.
 Will auto close on last sample.
 NOTE, entire audio is written to WAV, not just the length of video clip, [maybe use Trim(0,0) beforehand to trim/pad].
#######

ForceProcessWAV(clip c)
 Force Process clip c audio only, ie read from first to last audio sample, for TWriteWAV writes the WAV file (Audio) without having to play clip.

#######

Default channel Mappings when dwChannelMask = Default -1:
    0x00004, // 1   -- -- Cf
    0x00003, // 2   Lf Rf
    0x00007, // 3   Lf Rf Cf
    0x00033, // 4   Lf Rf -- -- Lr Rr
    0x00037, // 5   Lf Rf Cf -- Lr Rr
    0x0003F, // 5.1 Lf Rf Cf Sw Lr Rr
    0x0013F, // 6.1 Lf Rf Cf Sw Lr Rr -- -- Cr
    0x0063F, // 7.1 Lf Rf Cf Sw Lr Rr -- -- -- Ls Rs

Speaker_Location:-
    SPEAKER_FRONT_LEFT             0x1
    SPEAKER_FRONT_RIGHT            0x2
    SPEAKER_FRONT_CENTER           0x4
    SPEAKER_LOW_FREQUENCY          0x8          # Shown above as Sw (Sub Woofer)
    SPEAKER_BACK_LEFT              0x10
    SPEAKER_BACK_RIGHT             0x20
    SPEAKER_FRONT_LEFT_OF_CENTER   0x40
    SPEAKER_FRONT_RIGHT_OF_CENTER  0x80
    SPEAKER_BACK_CENTER            0x100
    SPEAKER_SIDE_LEFT              0x200
    SPEAKER_SIDE_RIGHT             0x400

Not used by Default Mappings:
    SPEAKER_TOP_CENTER             0x800
    SPEAKER_TOP_FRONT_LEFT         0x1000
    SPEAKER_TOP_FRONT_CENTER       0x2000
    SPEAKER_TOP_FRONT_RIGHT        0x4000
    SPEAKER_TOP_BACK_LEFT          0x8000
    SPEAKER_TOP_BACK_CENTER        0x10000
    SPEAKER_TOP_BACK_RIGHT         0x20000
Code:
From Doom9 Forum thread:- http://forum.doom9.org/showthread.php?t=172837

The original TWriteAVI was intended to produce lossless intermediate file for HC-Enc, as HC-Enc later did this itself, there was no
longer any call for TWriteAVI. [EDIT: From two posts below, seems it may have been initially written for use with VDub]

TWriteAVI v2.0, can write lossless whatever can be played to AVI (or WAV), and using the ForceProcessAVI/WAV functions, can write the
files without playing them (and faster than eg VDub Video Analysis Pass [EDIT: about 70% of VDub time]).

Two Pass:

    WhateverSource(...)
    A_Two_Pass_Function(Pass=1) # Create some kind of deshaker log or whatever.
    ForceProcessAVI()           # Force Pass 1, creating log (A function From TWriteAVI plug)
    A_Two_Pass_Function(Pass=2) # Use created log
    return Last

The ForceProcessAVI function forcibly processes both video and audio streams (ie reads each frame/sample in sequence),
so that any eg log files produced by either video and/or audio processing filter will be forcibly written to disk.
ForceProcessAVI/WAV are runtime functions not filters and so only return on completion.

Simultaneous play and save AVI

    WhateverSource(...)
    FN="Output.AVI"
    FOURCC="ULY0" # Ut_Video
    TWriteAVI(FN,Overwrite=true,fourcc=FOURCC).
    return Last


Do some kind of processing and save AVI, Then play Lossless file.

    WhateverSource(...)
    FN="Output.AVI"
    FOURCC="ULY0" # Ut_Video
    Sharpen(0.3)                                 # Whatever
    TWriteAVI(FN,Overwrite=true,fourcc=FOURCC).  # Write Sharp AVI whilst clip is played
    ForceProcessAVI()                            # Force Write above TWriteAVI file without playing clip.
    AVISource(FN)                                # Load Saved AVI
    return Last                                  # Play Sharpened AVI lossless clip

TWriteWAV/ForceProcessWAV, work in similar way to the AVI writing functions.

See also Avisynth settings for WaveExtensible and Float output for compatible players (otherwise audio may be converted to 16bit on output
from avisynth to a player).

# For Float/WaveExtensible player eg MPC-HC (Else comment out below if Player not capable)
    Global OPT_UseWaveExtensible = (AudioChannels>2||AudioBits>16)      # If more than 2 channels or > 16 bit, set true (Also Float, ie > 16 bits).
    Global OPT_AllowFloatAudio   = (IsAudioFloat)                       # Must be set true to play in eg Media Player Classic - Home Cinema


A demo included with TWriteAVI v2.0, splices 1000 clips together using temporary lossless intermediate files,
this necessary due to some kind of system resources limitiation using Avisynth (limited to opening about 28 video
files at one time).

Q. What is TWriteAVI for ?
A. Writes lossless AVI/WAV where required, specifically why you may want to do this is your problem, TWriteAVI is just the solution.

Soundout plugin, allows for writing WAV files, BUT, returns immediately and so WAV will not be available for use until some time later,
TWriteWAV together with ForceProcessWAV ensures WAV file is available on disk on return from ForceProcessWAV.

ssS
Available @ Mediafire below in my sig.
Avs v2.58 dll, and Avs/+ v2.60 dll, + source + VS2008 Project Files + AVS Script Demo Files. (~345KB)
__________________
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; 29th July 2018 at 16:50. Reason: Update
StainlessS is offline   Reply With Quote
Old 9th November 2015, 07:06   #2  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
Excellent work, as always, StainlessS. And a huge thanks to you for this one. You helped me out, big time.
vampiredom is offline   Reply With Quote
Old 9th November 2015, 16:22   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
Glad you like V.

Also note, can use eg

Code:
KillAudio(Last).ForceProcessAVI()
rather than VirtualDub "Run Video Analysis Pass" to create some kind of metrics file (DeShaker logs or whatever),
KillAudio just so it dont bother scanning all audio too, should be a bit faster than VDub analysis, and can also
do whole (EDIT:two pass) thing in single script. (I did something like that yesterday, seemed quite a bit faster but I did not time it).

EDIT: Timed above twice each (both same each time), VDub analysis 47 secs, ForceProcessAVI 33 secs, so is somewhat faster (~70% of VD time).

EDITED:
__________________
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; 9th November 2015 at 17:12. Reason: faux pas
StainlessS is offline   Reply With Quote
Old 18th December 2015, 17:52   #4  |  Link
kypec
User of free A/V tools
 
kypec's Avatar
 
Join Date: Jul 2006
Location: SK
Posts: 830
Problems with filename?

Hi Stainless,

your plugin was very useful to me but suddenly I'm facing a problem which I can't seem to resolve.
Please have a look at my script
Code:
source = GetSourceFilename("mkv")
FFVideoSource(source)
Crop(12, 2, -4, -2)
KNLMeansCL(d=1, a=2, s=4, h=5.0, device_type="GPU")
AddBorders(0, 0, 0, 4)
output = "processed-" + GetSourceFilename("avi")
TWriteAvi(output, overwrite=true, fourcc="MAGY")
Shared function looks like this
Code:
# Replaces the script filename (ending with ".avs") with the same filename but supplied extension (ends with ".extension")
function GetSourceFilename(string extension) {
	position = FindStr(ScriptName(), ".avs")
	return LeftStr(ScriptName(), position-1) + "." + extension
}
It fails on the last line (number 7) with error message Evaluate: Unrecognized exception!. I'm using the latest Avisynth 2.6 build on Windows 8.1. When I replace the output variable with simple
Code:
output = GetSourceFilename("avi")
the script works as expected. Do you have any idea why it fails with concatenated string above?
kypec is offline   Reply With Quote
Old 18th December 2015, 19:31   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
Code:
Avisource("K.avi")
output = "D:\KAYPEC\Z.AVI"      # FAIL
#output = "Z.AVI"               # OK
#output = "OUT\Z.AVI"           # OK
TWriteAvi(output, overwrite=true, fourcc="ULY0")
return last
Seems I may not have tested with full path only relative (dont think I altered anything to do with paths).

Trying to find the problem.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 18th December 2015, 20:13   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
What a silly Billy I am , I had mis-spelt the directory name ie KAYPEC instead of KYPEC, thats why my attempt failed.

Change your 'ScriptName' to 'ScriptFile' (both of them), and it should work OK.
You were creating filename something like:- "D:\KYPEC\processed-D:\KYPEC\K.avi"

EDIT: You created eg "processed-D:\KYPEC\K.avi"
which when turned into full path became "D:\KYPEC\processed-D:\KYPEC\K.avi"
__________________
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; 18th December 2015 at 20:16.
StainlessS is offline   Reply With Quote
Old 19th December 2015, 18:35   #7  |  Link
kypec
User of free A/V tools
 
kypec's Avatar
 
Join Date: Jul 2006
Location: SK
Posts: 830

I didn't realize that ScriptName() returns filename with full path. Your suggestion worked perfectly, thank you!
kypec is offline   Reply With Quote
Old 20th December 2015, 06:00   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
Kypec, just a tip, you can use RT_Debug or eg RT_DebugF("%s",StringVar,name="KYPEC: ") to output any suspect
variables to DebugView, in your above case it would output something like "KYPEC: processed-D:\KYPEC\K.avi" for the erroneous path string.

EDIT: From RT_Stats plugin.
__________________
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; 20th December 2015 at 08:06.
StainlessS is offline   Reply With Quote
Old 20th December 2015, 07:41   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
TwriteAVI, v2.01, Update, see 1st post.

Minor mod only, Show Error massage with Filename on Open Error.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 20th December 2015, 12:46   #10  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
I read the whole thread and part of the linked one and I still don't know what TWriteAVI is or what it does.
Never mind, Reel.Deal has summed it up nicely:
Quote:
http://avisynth.nl/index.php/TWriteAVI

Serve AVI file to program requesting it as well as write an avi file. Useful for speeding up 2 pass encodes at the cost of hard drive space.
Now, how do I use it? You just load the script, and it writes the whole file to disk?
How would it be used in a 2-pass scenario? How would it be used to create a lossless copy?
raffriff42 is offline   Reply With Quote
Old 20th December 2015, 13:30   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
The original TWriteAVI was intended to produce lossless intermediate file for HC-Enc, as HC-Enc later did this itself, there was no
longer any call for TWriteAVI. [EDIT: From two posts below, seems it may have been initially written for use with VDub]

TWriteAVI v2.0, can write lossless whatever can be played to AVI (or WAV), and using the ForceProcessAVI/WAV functions, can write the
files without playing them (and faster than eg VDub Video Analysis Pass [EDIT: about 70% of VDub time]).

Two Pass
Code:
WhateverSource(...)
A_Two_Pass_Function(Pass=1) # Create some kind of deshaker log or whatever.
ForceProcessAVI()           # Force Pass 1, creating log (A function From TWriteAVI plug)
A_Two_Pass_Function(Pass=2) # Use created log
return Last
EDIT: The ForceProcessAVI function forcibly processes both video and audio streams (ie reads each frame/sample in sequence),
so that any eg log files produced by either video and/or audio processing filter will be forcibly written to disk.
ForceProcessAVI/WAV are runtime functions not filters and so only return on completion.

Simultaneous play and save AVI
Code:
WhateverSource(...)
FN="Output.AVI"
FOURCC="ULY0" # Ut_Video
TWriteAVI(FN,Overwrite=true,fourcc=FOURCC).
return Last

Do some kind of processing and save AVI, Then play Lossless file.
Code:
WhateverSource(...)
FN="Output.AVI"
FOURCC="ULY0" # Ut_Video
Sharpen(0.3)                                 # Whatever
TWriteAVI(FN,Overwrite=true,fourcc=FOURCC).  # Write Sharp AVI whilst clip is played
ForceProcessAVI()                            # Force Write above TWriteAVI file without playing clip.
AVISource(FN)                                # Load Saved AVI
return Last                                  # Play Sharpened AVI lossless clip
A demo included with TWriteAVI v2.0, splices 1000 clips together using temporary lossless intermediate files,
this necessary due to some kind of system resources limitiation using Avisynth (limited to opening about 28 video
files at one time).

Q. What is TWriteAVI for ?
A. Writes lossless AVI/WAV where required, specifically why you may want to do this is your problem, TWriteAVI is just the solution.

EDIT: Perhaps Kypec and Vampiredom would like to comment on their usage.

EDIT: Soundout, allows for writing WAV files, BUT, returns immediately and so WAV will not be available for use until some time later,
TWriteWAV together with ForceProcessWAV ensures WAV file is available on disk on return from ForceProcessWAV.

EDIT: Also note, if required, could use eg CallCmd() or RT_Call() to call some kind of processor/encoder on output AVI/WAV, perhaps also
auto creating simple AVS file if necessary for the encoder input.
__________________
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; 20th December 2015 at 16:23.
StainlessS is offline   Reply With Quote
Old 20th December 2015, 15:19   #12  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
Thanks, that's very neat!
raffriff42 is offline   Reply With Quote
Old 20th December 2015, 16:00   #13  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,115
Quote:
Originally Posted by raffriff42 View Post
Never mind, Reel.Deal has summed it up nicely:
That description's been there before I started to work on the wiki, Mikeytown2 was active around the time it was added so maybe he's the one that summed it up nicely .

Quote:
Originally Posted by raffriff42 View Post
How would it be used in a 2-pass scenario? How would it be used to create a lossless copy?
Maybe something like this:

Quote:
Originally Posted by tritical View Post
I hacked this up real quick using the avs2avi source code for reference...TWriteAvi. Basically it will pop up a dialog box on load so you can choose the compressor to use and configure it. So you could insert this filter at the very end of your avs script. Then open the script in vdub, set vdub up to encode the first pass for your two pass codec and TWriteAvi to encode the lossless version. Then on the second pass use the lossless version as input. Of course, its not automatic and you have to be there to choose the codec. However, if someone wants too, I think some sort of automated ability could be added easily enough.
Reel.Deel is offline   Reply With Quote
Old 21st December 2015, 11:11   #14  |  Link
kypec
User of free A/V tools
 
kypec's Avatar
 
Join Date: Jul 2006
Location: SK
Posts: 830
I used the plugin in my workflow like this - first, the intermediate AVI file is created by running the following script through AVSMeter:
Code:
source = GetSourceFilename("mkv")
FFVideoSource(source)
Crop(12, 2, -4, -2)
KNLMeansCL(d=1, a=2, s=4, h=5.0, device_type="GPU")
AddBorders(0, 0, 0, 4)
output = "processed-" + GetSourceFilename("avi")
TWriteAvi(output, overwrite=true, fourcc="MAGY")
Then, I feed this AVI file via another script to x264 doing 2-pass encode
Code:
source = GetSourceFilename("avi")
AviSource(source)
Maybe I could boost my workflow even more by utilizing the approach explained above: to feed Avisynth output directly to x264 encoder doing first pass while also writing the same processed video data to intermediate AVI file on disk and use this file for encoder second pass. However, I don't know how to chain all these tasks together (command line piping etc.) when I want to stay with my favorite Simple x264 Launcher for performing the actual encoding.
kypec is offline   Reply With Quote
Old 21st December 2015, 15:50   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
Kypec,
In your first script, could add to end
Code:
    ForceProcessAVI()  # Forcibly write AVI
    Return MessageClip("DONE")
Instead of calling AVSMeter (I guess you have used it that way since old v1.0 TWriteAVI).
ForceProcessAVI should be about same speed as AVSMeter, maybe a bit faster (a very tiny bit not really worth mentioning).

Before the above return MessageClip("DONE"),
Could insert code to create AVS and BAT files, avs to use avisynth to open the lossless file, and batch file that hands the avs as argument
to Simple x264 launcher.
Demo of creating any kind of script/bat file here:- http://forum.doom9.org/showthread.ph...52#post1749752

Some functions that may assist in your task
Code:
RT_FilenameSplit(string filename,int "get"=15)
 Splits the un-named filename string into component parts selected by 'get' bit flags arg and returns the
 parts joined together.
 'Get' (default 15, 1 -> 15), If set, Bit 0=DRIVE, 1=Dir, 2=Name, 4=Extension.
 Add 1 for Drive (bit 0), add 2 for Dir (bit 1), add 4 for Name (bit 2), add 8 for Extension (bit 3).
 Some combinations do not make sense, eg Drive + Extension (1+8=9). Below sensible options.
   1  = Drive (includes trailing ':')
   2  = Dir (includes trailing '\')
   3  = Drive + Dir
   4  = Name
   6  = Dir + Name
   7  = Drive + Dir + Name
   8  = Extension (includes leading '.')
   12 = Name + Extension
   14 = Dir + Name + Extension
   15 = Drive + Dir + Name + Extension
 Assuming a current working directory of eg "D:\avs\avi\", 'filename'="test.avi" and 'get'=15, returns "D:\avs\avi\test.avi",
 so given a relative filename and default 'get'=15, is equivalent to RT_GetFullPathName(filename).

***
***
***

RT_GetFullPathName(string "name")
 Creates an absolute or full path name for the specified relative path 'name'.
  eg 'RT_GetFullPathName("test.avs")' might return "D:\avs\test.avs".
 Throws and error if cannot return path.

***
***
***

RT_GetFileExtension(string s)
 Returns filename extension from the supplied filename, including '.' prefix.

RT_StrReplace(string source,string find,string replace,bool "sig"=True) # Based on Algorithm by Vampiredom, Gavino & IanB.
 String args 'source', 'find' and 'replace' unnamed and compulsory.
 Takes a source string, searches for all occurences of find string and replaces the found strings with the replace string.
 Can use "" in replace string (only in replace) to delete the found substrings from the source string.
 Newlines are treated no differently to other characters, and could be replaced/deleted.
 v1.14, added 'sig' arg,default true is Case Significant (as previous version). Set false for case insignificant find string.

RT_StrReplaceMulti(string source,string find,string replace,bool "sig"=True)
 String args 'source', 'find' and 'replace' unnamed and compulsory.
 Takes a source string, searches for all occurences of find substrings and replaces the found substrings with the replace substrings.
 Find string and Replace string are both multiline [Chr(10) separated] strings, both of n lines where find[i] and replace[i]
 are matched pairs, ie the first line of a multiline find is replaced by the first line of a multiline replace, etc.
 Can use "" in replace string (only in replace) to delete the found substrings from the source string.
 Differs from RT_StrReplace, in that both find and replace strings are multiline strings and MUST match in number of lines.
 Cannot use either carriage return [Chr(13)] or newline [Chr(10)] in find or replace as these are interpreted as end of current line,
 you would need to use RT_StrReplace() instead.
  eg S=RT_StrReplaceMulti("THE cat SAT.","SAT"+Chr(10)+"THE","sat"+Chr(10)+"The") produces "The cat sat.".
 v1.14, added 'sig' arg,default true is Case Significant (as previous version). Set false for case insignificant find string.

***
***
***

RT_QuoteStr(string)
 Non-clip function.
 Encloses supplied string arg in double quotes, Use on filenames containing spaces.
 Do NOT use with eg RT_FileDelete, only on filenames sent to a DOS command.

RT_WriteFile(String FileName, string format,dat1,...,datn,bool "Append"=False)
 Writes  a formatted string to FileName file. The unnamed 'format' string and optional unnamed 'dat' args are used to construct the
 text string that is written, uses C/CPP printf() style formatting.
 Format: compulsory string controlling format and describing the datn type args that are expected.
 datn: Variable number of data args of any type (excluding clip).
 Append, Default False, optional and MUST be supplied with name (eg Append=True) as we do not know where optional data args end,
 Appends to file if already exists, else opens new FileName.
OMITTED A lot more RT_WriteFile stuff.
EDIT:
Quote:
to feed Avisynth output directly to x264 encoder doing first pass
I'll try knock something simple up which you can mod to suit.
__________________
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 December 2015 at 16:27.
StainlessS is offline   Reply With Quote
Old 21st December 2015, 18:43   #16  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
Here an Avisynthesizer_MOD BATCH script template (Avisynthesizer_MOD here: http://forum.doom9.org/showthread.ph...ynthesizer_MOD)

EDIT: See post #25 for later version of script:- http://forum.doom9.org/showthread.ph...34#post1750834

BATCH-KYPEC-AviSource.avst
Code:
#ASYNTHER BATCH-KYPEC-AviSource
# Avisynthesizer_Mod TEMPLATE FILE, Above is shown in Avisynthesizer_Mod as "BATCH-KYPEC-AviSource"

# Below not enclosed in square brackets, so is Non-Repeating ie Batch Mode, multiple AVS files generated. 
SourceFilename = "___FILE___"                   # Source Filename inserted here by Avisynthesizer_Mod
###################################
# FULL PATH Directories, DONT End In BACKSLASH/SLASH
LOSSLESS_DIR  = "D:\KYPEC\LOSSLESS"
AVSOUTPUT_DIR = "D:\KYPEC\AVSOUTPUT"
BATOUTPUT_DIR = "D:\KYPEC\BATOUTPUT"
OUTPUT_DIR    = "D:\KYPEC\OUTPUT"
###
FOURCC = "ULY0"                                 # UT_Video YV12 rec601 Lossless codec
###################################
###################################
###################################
AVISource(SourceFilename)                       # Mod for your source filter, FFMpegSource or whatever (amend Avisynthesizer_Mod description to suit)
Trim(0,0)                                       # Trim/Pad audio to length
### Insert whatever you want, Trim, Crop, etc

# ...

Return Last                                     # COMMENT OUT, when happy with Trim/Crop etc.
###################################
###################################
###################################

# AVS Template to Load Lossless AVI file
AVS_TMPT=("""
    Return AVISource("___AVI__")
""")

###

# BAT Template to encode Lossless AVI file to output, Can use either "___AVS___" or "___AVI___" in BAT file.
BAT_TMPT=("""
    "C:\BIN\ffmpeg.exe" -i "___AVS___"   "___OUT_FILE___.MP4"    
    Pause                   REM Wait user press key : Comment out if required (Precede Pause with 'REM ', or delete this line)
""")

###################################
Node = RT_FilenameSplit(SourceFilename,get=4)   # Filename Node only, no path nor extension
Avi=RT_String("%s\\%s.AVI",LOSSLESS_DIR,Node)
Avs=RT_String("%s\\%s.AVS",AVSOUTPUT_DIR,Node)
Bat=RT_String("%s\\%s.BAT",BATOUTPUT_DIR,Node)
Out=RT_String("%s\\%s",OUTPUT_DIR,Node)         # Excluding file Extension, (You may want '.MKV' or '.MP4' or whatever, append in batch template)
#
AVS_TMPT = RT_StrReplace(AVS_TMPT,"___AVI__",AVI)
#
FndS     = RT_String("___AVI___\n___AVS___\n___OUT_FILE___\n")
RepS     = RT_String("%s\n%s\n%s\n",AVI,AVS,OUT) 
BAT_TMPT = RT_StrReplaceMulti(BAT_TMPT,FndS,RepS)
#
RT_DebugF("Writing AVS '%s'",AVS,name="KYPEC: ")
RT_WriteFile(Avs,"%s",Avs_TMPT)                 # Write AVS file
RT_DebugF("Writing BAT '%s'",Bat,name="KYPEC: ")
RT_WriteFile(Bat,"%s",Bat_TMPT)                 # Write BAT file
###################################
RT_DebugF("Calling TWriteAVI '%s'",AVI,name="KYPEC: ")
TWriteAVI(AVI,Overwrite=true,Fourcc=FOURCC)     # Write and play processed clip
###
RT_DebugF("Calling ForceProcessAVI",name="KYPEC: ")
ForceProcessAVI                                 # Immediate write without play, comment out to return Processed clip simultaneously writing.
#RT_DebugF("Loading Lossless",name="KYPEC: ")
#AviSource(AVI)                                 # Return Lossless, ONLY if used above ForceProcessAVI
RT_DebugF("Calling Encode BAT '%s'",BAT,name="KYPEC: ")
Assert(RT_Call(BAT,Hide=False,Debug=True)==0,RT_String("RT_Call: Call Failed on\n%s",BAT)) # Call Encoder, Only if ForceProcessAVI used. 
RT_DebugF("ALL DONE",name="KYPEC: ")
#Return Last
Return MessageClip("Done")
Select all input files in Explorer, SendTo Avisynthesizer, creates an AVS for each file selected.
Requires RT_Stats, TWriteAVI v2.0, ffmpeg.exe, UT_Video codec, Avisynthesizer_Mod.

EDIT: Changed to Hide=False in RT_Call command (Show ffmpeg window, allow ffmpeg ask 'Overwrite ?' and user press key after encode).
__________________
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; 6th January 2016 at 12:17. Reason: Update
StainlessS is offline   Reply With Quote
Old 23rd December 2015, 14:26   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
DOS GURU assistance needed for above script, [EDIT: Oops CLI GURU, if Groucho2004 is watching {I dont wanna be bitch slapped again} ]

this BAT batch template, need to detect and return ERRORLEVEL from ffmpeg call
Code:
BAT_TMPT=("""
    "C:\BIN\ffmpeg.exe" -i "___AVS___"   "___OUT_FILE___.MP4"    
    Pause                   REM Comment out if required (Precede Pause with REM)
""")
I just cannot remember anything about that stuff, any suggestions ?

Could synthesize error by using either RT_FileDelete(AVI) or RT_FileDelete(AVS) immediately before RT_Call line.

EDIT: Above not so much necessary as I forgot that RT_Call can only return SUCCESS status whether process started, and
not any return value from that process (we can only return a single item to avisynth, not 2 or more).
I shall try to find a way to access returned value, and try to complete RT_Stats mods and publish v2.0 RT_Stats soon.
Would still be helpful though if someone can post above ERRORLEVEL solution.
__________________
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; 23rd December 2015 at 15:30.
StainlessS is offline   Reply With Quote
Old 23rd December 2015, 18:36   #18  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,184
Quote:
Originally Posted by StainlessS View Post
DOS GURU assistance needed for above script, [EDIT: Oops CLI GURU, if Groucho2004 is watching {I dont wanna be bitch slapped again} ]

this BAT batch template, need to detect and return ERRORLEVEL from ffmpeg call
<snip>
I can provide more exact assistance if you need it (I created a lot of batch files, back in the day). However, rather than go back to my 1980s archives (I still have them), I quickly found this modern code from a Sony installation program. I've excerpted just the portion that contains the ERRORLEVEL call. Perhaps it will give you the syntax help you need:
Code:
<snip>
tasklist /FO CSV /NH >>PMH_Log_Files\tasklist.txt
FOR /F "tokens=1* delims=,? " %%a in (PMH_Log_Files\tasklist.txt) do (

if not %%a=="PMBVolumeWatcher.exe" (if /i not %%a=="PMBDeviceInfoProvider.exe" (if /i not %%a=="PMBContentAnalyzer.exe" (
echo %%a | findstr "PMB"
if not ERRORLEVEL 1 (
IF EXIST PMH_Log_Files\tasklist.txt (DEL /S /Q PMH_Log_Files\tasklist.txt
echo PlayMemories Home or Action Cam Movie Creator is running.
echo Quit PlayMemories Home or Action Cam Movie Creator before starting the program.
pause
exit
))))))

IF EXIST PMH_Log_Files\tasklist.txt (DEL /S /Q PMH_Log_Files\tasklist.txt)
<snip>
johnmeyer is offline   Reply With Quote
Old 23rd December 2015, 19:01   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,086
Thank you John,

I think I may add some kind of optional START_SUCCESS, SUCCESS, FAIL args(used for default return codes), (not really quite sure how yet), and if ALL given then try to return
some kind of start/good/bad answer (otherwise just return started as 0 for OK, as currently implemented).
(Programs can return their own error code, there is no STANDARD code so basically any return is possible from an executable).

I'll come back and look at what you've supplied above when I've figured out what I'm gonna do.

Again thanx.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 23rd December 2015, 20:45   #20  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,377
Quote:
Originally Posted by StainlessS View Post
need to detect and return ERRORLEVEL from ffmpeg call
1. Detecting an error level: it's easiest if you only care if %errorlevel% is zero (success) or nonzero (failure)
Code:
[try something...]
if errorlevel 1 goto failed
[do stuff]
goto :EOF

:failed
@echo failed! try again!
pause
goto :EOF
"if errorlevel 1" is true if %errorlevel% is 1, OR GREATER

If you want the exact error level, it's harder. See this (robvanderwoude.com)

2. Returning an error level from a batch file:
Code:
exit /b 42
To test this, after you run the batch file, type:
Code:
echo %errorlevel%
EDIT AutoHotkey, AutoIt, C++, C# etc can run a process and store the exit code.

EDIT sorry, it's "if errorlevel 1" not "if %errorlevel% 1"

Last edited by raffriff42; 24th December 2015 at 01:31.
raffriff42 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:55.


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