View Full Version : TWriteAVI - Write AVI/WAV files in Avisynth
StainlessS
7th November 2015, 22:48
Edit: 3rd Oct 2022.
Good news from Asd-g, x64 (and x86) build: TWriteAVI v2.5.1 (//github.com/Asd-g/AviSynth-TWriteAVI)
So above linked TWriteAVI now copes writing all AVS v2.60 Std colorspace [EDIT: EXCEPT YV411] AVI files bigger than 2GB [Tested writing 8.7GB file].
TWriteAVI by Tritical, Squid_80 and Mikeytown2, v2.0 update StainlessS.
Moved here from MPEG 2 Encoding forum. http://forum.doom9.org/showthread.php?p=1745671#post1745671
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
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)
EDIT: Process two instances of a two pass filter
WhateverSource(...)
Clip1 = Trim(0,-2000) # 2000 frames
File1="D:\File1.txt"
Clip2 = Trim(2000,0) # remainder
File2="D:\File2.txt"
Clip1.A_Two_Pass_Function(Pass=1,LogFile=File1)
ForceProcessAVI() # Clip1, Force Pass 1
Clip2.A_Two_Pass_Function(Pass=1,LogFile=File2)
ForceProcessAVI() # Clip2, Force Pass 1
Result1 = Clip1.A_Two_Pass_Function(Pass=2,LogFile=File1) # Clip 1 Pass 2
Result2 = Clip2.A_Two_Pass_Function(Pass=2,LogFile=File2) # Clip 2 Pass 2
return Result1++Result2
vampiredom
9th November 2015, 08:06
Excellent work, as always, StainlessS. And a huge thanks to you for this one. You helped me out, big time.
StainlessS
9th November 2015, 17:22
Glad you like V.
Also note, can use eg
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:
kypec
18th December 2015, 18:52
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 scriptsource = 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# 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 output = GetSourceFilename("avi") the script works as expected. Do you have any idea why it fails with concatenated string above?
StainlessS
18th December 2015, 20:31
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.
StainlessS
18th December 2015, 21:13
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"
kypec
19th December 2015, 19:35
:thanks:
I didn't realize that ScriptName() returns filename with full path. Your suggestion worked perfectly, thank you!
StainlessS
20th December 2015, 07:00
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.
StainlessS
20th December 2015, 08:41
TwriteAVI, v2.01, Update, see 1st post.
Minor mod only, Show Error massage with Filename on Open Error.
raffriff42
20th December 2015, 13:46
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: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?
StainlessS
20th December 2015, 14:30
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
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
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
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.
raffriff42
20th December 2015, 16:19
Thanks, that's very neat!
Reel.Deel
20th December 2015, 17:00
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 (https://web.archive.org/web/20080505031739/http://avisynth.org/mediawiki/index.php?title=External_filters&action=history) around the time it was added so maybe he's the one that summed it up nicely :).
How would it be used in a 2-pass scenario? How would it be used to create a lossless copy?
Maybe something like this:
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.
kypec
21st December 2015, 12:11
I used the plugin in my workflow like this - first, the intermediate AVI file is created by running the following script through AVSMeter (http://forum.doom9.org/showthread.php?t=165528):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 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 (http://forum.doom9.org/showthread.php?t=144140) for performing the actual encoding. :(
StainlessS
21st December 2015, 16:50
Kypec,
In your first script, could add to end
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.php?p=1749752#post1749752
Some functions that may assist in your task
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:
to feed Avisynth output directly to x264 encoder doing first pass
I'll try knock something simple up which you can mod to suit.
StainlessS
21st December 2015, 19:43
Here an Avisynthesizer_MOD BATCH script template (Avisynthesizer_MOD here: http://forum.doom9.org/showthread.php?t=166820&highlight=Avisynthesizer_MOD)
EDIT: See post #25 for later version of script:- http://forum.doom9.org/showthread.php?p=1750834#post1750834
BATCH-KYPEC-AviSource.avst
#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).
StainlessS
23rd December 2015, 15:26
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
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.
johnmeyer
23rd December 2015, 19:36
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:<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>
StainlessS
23rd December 2015, 20:01
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. :thanks:
raffriff42
23rd December 2015, 21:45
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)[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 (http://www.robvanderwoude.com/errorlevel.php) (robvanderwoude.com)
2. Returning an error level from a batch file:exit /b 42
To test this, after you run the batch file, type: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"
johnmeyer
23rd December 2015, 21:51
I had a little time waiting for a render to finish. Here's an old installation batch file from 1991:
@ECHO OFF
CLS
ECHO .
ECHO .............................................................................
ECHO . Installation Program for the Passport Multimedia Music Demo
ECHO . Version: 3.0
ECHO .
ECHO . This Demo is for use with Windows 3.0 with Multimedia Extensions
ECHO .............................................................................
ECHO .
IF NOT EXIST YN.COM GOTO ERROR
ECHO This program will install the Passport Multimedia Music Demo in the drive and
ECHO directory that you specify. We suggest using a directory called \PASSPORT.
ECHO If the directory you specify does not exist then we will create it for you.
ECHO .
YN Do you want to install the DEMO now?
IF NOT ERRORLEVEL 1 GOTO EXIT
ECHO .
ECHO Enter the drive and directory where you want the demo installed.
ECHO DO NOT include the "\" character at the end. Eg. Enter... C:\PASSPORT
ANSWER Enter drive and directory:
MD %ANSWER%
CLS
:D1PROMPT
IF EXIST PASSPORT.TBK GOTO D1OK
ECHO .
ECHO Insert Disk #1 into the floppy drive, or...
ECHO if installing from CDROM just...
PAUSE
GOTO D1PROMPT
:D1OK
ECHO .
ECHO Copying the files, please wait.....
ECHO .
COPY PASSPORT.TBK %ANSWER%
IF ERRORLEVEL 1 GOTO ERROR2
COPY README %ANSWER%
COPY INSTALL.BAT %ANSWER%
COPY TBKMM.* %ANSWER%
COPY *.COM %ANSWER%
CLS
:D2PROMPT
ECHO .
ECHO Insert Disk #2 into the floppy drive, or...
ECHO if installing from CDROM just...
PAUSE
CLS
IF NOT EXIST MTPDEMO.EXE GOTO D2PROMPT
ECHO .
ECHO Copying the files, please wait.....
ECHO .
COPY MTPDEMO.EXE %ANSWER%
IF ERRORLEVEL 1 GOTO ERROR2
COPY TRAXDEMO.EXE %ANSWER%
COPY TIMEMIDI.DLL %ANSWER%
COPY *.M?? %ANSWER%
COPY *.WAV %ANSWER%
CLS
ECHO .
ECHO . This demo requires ToolBook 1.5 or newer. A runtime version of
ECHO . Toolbook is provided with the demo. You should install this runtime
ECHO . version of Toolbook now if you do not have Toolbook 1.5 or newer
ECHO . available on your system.
ECHO .
YN Do you want to install runtime Toolbook 1.5 now?
IF NOT ERRORLEVEL 1 GOTO MIDIMAP
:D3PROMPT
ECHO .
ECHO Insert Disk #3 into the floppy drive, or...
ECHO if installing from CDROM just...
PAUSE
CLS
IF NOT EXIST TBOOK.EXE GOTO D3PROMPT
ECHO .
ECHO Copying the files, please wait.....
ECHO .
COPY TBOOK.EXE %ANSWER%
COPY *.DLL %ANSWER%
:MIDIMAP
COPY MIDIMAP.* %ANSWER%
CLS
ECHO .
ECHO In order for the songs in this demo to play correctly you must have the MIDI
ECHO Mapper setup correctly. A MIDIMAP.CFG file is provided on this disk that
ECHO contains several MIDI Mapper setups. One of these setups should be
ECHO appropriate for your system. If you want, we will rename your existing
ECHO MIDIMAP.CFG to MIDIMAP.ORG and copy our new MIDIMAP.CFG into your Windows'
ECHO System directory.
ECHO .
ECHO .
YN Do you want this MIDIMAP.CFG file installed in your Windows directory?
IF NOT ERRORLEVEL 1 GOTO NOMAP
ECHO .
ECHO Enter the drive and directory where Multimedia Windows is installed.
ECHO DO NOT include the "\" character at the end. Eg. Enter... C:\MMWIN
ANSWER Enter drive and directory:
ECHO .
COPY %ANSWER%\SYSTEM\MIDIMAP.CFG %ANSWER%\SYSTEM\MIDIMAP.ORG
COPY MIDIMAP.PAS %ANSWER%\SYSTEM\MIDIMAP.CFG
IF ERRORLEVEL 1 GOTO ERROR3
ECHO .
ECHO A new MIDIMAP.CFG file has been copied to your Windows directory.
ECHO .
ECHO You should choose the MIDI Mapper from the Control Panel and select the
ECHO setup that matches your system. If you encounter any problems with the MIDI
ECHO Mapper, you can restore your original MIDI Mapper file by copying MIDIMAP.ORG
ECHO to MIDIMAP.CFG in your Windows' System directory.
PAUSE
:NOMAP
CLS
ECHO .
ECHO The Passport Multimedia Music Demo has been installed.
ECHO .
ECHO To execute the demo, assuming that you installed it in C:\PASSPORT,
ECHO first select the correct hard disk volume. Type...
ECHO .
ECHO . C: ...and press Enter, then type...
ECHO . CD \PASSPORT
ECHO . WIN TBOOK PASSPORT
ECHO .
ECHO . ...or choose "RUN" or "NEW" from Windows' Program Manager and enter
ECHO .
ECHO . C:\PASSPORT\TBOOK PASSPORT ...in the command line field.
ECHO .
GOTO EXIT
:ERROR
ECHO ERROR: You must make the source floppy or CDROM drive the default drive
ECHO in order to run the install program. i.e. Type....
ECHO .
ECHO A: (or B:, or D: etc.)
ECHO If installing from CDROM... CD \PASSPORT (select the source directory)
ECHO INSTALL
GOTO EXIT
:ERROR2
ECHO ERROR: An error occured while copying files. The Demo was not installed.
ECHO .
GOTO EXIT
:ERROR3
ECHO ERROR: An error occured while copying MIDIMAP.CFG. It was not installed.
ECHO .
:EXIT
ECHO .
StainlessS
23rd December 2015, 22:08
Thanks very much john, unfortunately for right now I dont need it (Will come in handy in future though, mucho grassy ass :) )
EDIT: See post #25 for later version of script:- http://forum.doom9.org/showthread.php?p=1750834#post1750834
Here, script together with some Success detection (will though probably see user abort mid encode as success)
#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"
### FINAL BAT Output file Extension Including '.' eg '.MP4'
EXT = ".MP4"
###
myName = "KYPEC: " # Name for DebugView
FOURCC = "ULY0" # UT_Video YV12 rec601 Lossless codec
AUTODEL= True # Auto Delete Existing FINAL output file (created by Batch, otherwise ffmpeg will ask)
###################################
###################################
###################################
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 below in BAT file (3 underscore either side):-
# "___AVS___" For *.avs input
# "___AVI___" For *.avi input
# "___ONAME___" For FULL PATH OUTPUT Filename without extension
# "___OFILE___" For FULL PATH OUTPUT Filename Including extension
# "___OEXT___" For output extension ONLY (including '.' eg '.MP4').
BAT_TMPT=("""
C:\BIN\ffmpeg.exe -i "___AVS___" "___OFILE___"
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
Bat = RT_String("%s\\%s.BAT",BATOUTPUT_DIR,Node)
Avi = RT_String("%s\\%s.AVI",LOSSLESS_DIR,Node)
Avs = RT_String("%s\\%s.AVS",AVSOUTPUT_DIR,Node)
oName = RT_String("%s\\%s",OUTPUT_DIR,Node) # Excluding file Extension
oFile = RT_String("%s\\%s%s",OUTPUT_DIR,Node,EXT) # Including file Extension
#
AVS_TMPT = RT_StrReplace(AVS_TMPT,"___AVI__",AVI)
#
FndS = RT_String("___AVI___\n___AVS___\n___ONAME___\n___OFILE___\n___OEXT___\n")
RepS = RT_String("%s\n%s\n%s\n%s\n%s\n",AVI,AVS,oName,oFile,EXT)
BAT_TMPT = RT_StrReplaceMulti(BAT_TMPT,FndS,RepS)
#
RT_DebugF("\nWriting AVS '%s'\n>>>>>>%s\n<<<<<<",AVS,Avs_TMPT,name=myName) RT_WriteFile(Avs,"%s",Avs_TMPT) # Write AVS file
RT_DebugF("\nWriting BAT '%s'\n>>>>>>%s\n<<<<<<",Bat,Bat_TMPT,name=myName) RT_WriteFile(Bat,"%s",Bat_TMPT) # Write BAT file
###### Write and play processed clip
RT_DebugF("Calling TWriteAVI Constructor '%s'",AVI,name=myName) TWriteAVI(AVI,Overwrite=true,Fourcc=FOURCC)
###################################
################################### EDIT ALL BELOW depending upon desired result
###################################
###### Immediate write AVI without play, comment out to return Processed clip simultaneously writing.
RT_DebugF("Calling ForceProcessAVI",name=myName) ForceProcessAVI
### Optional, Comment Out Below if returning ORIGINAL Processed clip, NOT LOSSLESS nor MessageClip, Free 'Last' memory usage for encoder.
RT_DebugF("Last=0 SetMemoryMax(256) : Free Memory for encoder ",name=myName) Last=0 SetMemoryMax(256)
###### Call Encoder, ONLY IF ForceProcessAVI used else AVI will not exist.
OldEx = Exist(oFile)
OldTim = (OldEx) ? RT_GetFileTime(oFile,1) : ""
(OldEx) ? RT_DebugF("Output Already Exists, Modification Time = %s",OldTim,name=myName) : NOP
(AUTODEL && OldEx) ? RT_DebugF("Deleting existing Output",name=myName) : NOP
(AUTODEL && OldEx) ? RT_FileDelete(oFile) : NOP
RT_DebugF("Calling Encode BAT '%s'",BAT,name=myName)
Assert(RT_Call(BAT,Hide=False,Debug=True)==0,RT_String("RT_Call: Start Process Failed on\n%s",BAT))
NewEx = Exist(oFile)
NewTim = (NewEx) ? RT_GetFileTime(oFile,1) : ""
(NewTim!="") ? RT_DebugF("Output Modification Time = %s",NewTim,name=myName) : NOP
Assert(NewTim > OldTim ,RT_String("RT_Call: output FAILED\n%s",BAT)) # Call Encoder, Only if ForceProcessAVI used.
###### Return Lossless, ONLY IF used above ForceProcessAVI else AVI will not Exist
#RT_DebugF("Loading Lossless",name=myName) AviSource(AVI)
######
RT_DebugF("ALL DONE",name=myName)
#Return Last
Return MessageClip("Done")
Leaving previous posts as-is, so that other posts make sense.
EDIT:
Raffriff, nearly missed your post on previous page.
Thanks, much to think about there.
I was wondering, any body on forum use PowerShell ?
I have it installed (v1.0 I think), but have never used it.
Its gotta be a bit better than DOS (sorry Grouchy, I meant CLI).
EDIT: I guess I could always output error code to a file and retrieve inside AVS script.
EDIT: John, Presumably YN and ANSWER are included in the install package ?
(think I may have a "YN.EXE" or similar somewhere, but from some kind of MSDOS extension pack)
EDIT: Output avs and bat file contents to DebugView.
EDIT: Added "Last=0 SetMemoryMax(256)", Free Memory for encoder.
EDIT: Writes something like this to DebugView
00000003 1.67913342 KYPEC:
00000004 1.67915308 KYPEC: Writing AVS 'D:\KYPEC\AVSOUTPUT\K.AVS'
00000005 1.67917871 KYPEC: >>>>>>
00000006 1.67920256 KYPEC: Return AVISource("D:\KYPEC\LOSSLESS\K.AVI")
00000007 1.67922628 KYPEC:
00000008 1.67925012 KYPEC: <<<<<<
00000009 1.67972112 KYPEC:
00000010 1.67974770 KYPEC: Writing BAT 'D:\KYPEC\BATOUTPUT\K.BAT'
00000011 1.67977369 KYPEC: >>>>>>
00000012 1.67979753 KYPEC: C:\BIN\ffmpeg.exe -i "D:\KYPEC\AVSOUTPUT\K.AVS" "D:\KYPEC\OUTPUT\K.MP4"
00000013 1.67982185 KYPEC: Pause REM Wait user press key : Comment out if required (Precede Pause with 'REM ', or delete this line)
00000014 1.67984557 KYPEC:
00000015 1.67986977 KYPEC: <<<<<<
00000016 1.68027031 KYPEC: Calling TWriteAVI Constructor 'D:\KYPEC\LOSSLESS\K.AVI'
00000017 1.68605030 KYPEC: Calling ForceProcessAVI
00000018 5.35039806 KYPEC: Last=0 SetMemoryMax(256) : Free Memory for encoder
00000019 5.35354996 KYPEC: Output Already Exists, Modification Time = 2015-12-24 00:19:05.953
00000020 5.35366869 KYPEC: Deleting existing Output
00000021 5.35411119 KYPEC: Calling Encode BAT 'D:\KYPEC\BATOUTPUT\K.BAT'
00000022 5.35486317 RT_Call: D:\KYPEC\BATOUTPUT\K.BAT
00000025 17.86802101 RT_Call: Process returned = 0 (0x00000000)
00000026 17.86905670 KYPEC: Output Modification Time = 2015-12-24 00:19:49.640
00000027 17.86947441 KYPEC: ALL DONE
raffriff42
24th December 2015, 02:34
Hmm, batch-fu fading:EDIT sorry, it's "if errorlevel 1" not "if %errorlevel% 1"
MysteryX
24th December 2015, 03:43
This doesn't work with float audio.
If I'm using this, then I'm getting really weird distortion in the audio. Without the pitch shift, it outputs OK. With pitch shift, it plays fine on the computer with float output.
Not sure what's going on here.
LoadPlugin(P+"TimeStretch.dll")
ResampleAudio(48000)
TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)
ConvertAudioTo32bit()
LoadPlugin(P+"TWriteAVI.dll")
TWriteWAV("Job5_Output.wav", true)
ForceProcessWAV()
StainlessS
24th December 2015, 06:29
Update, seems to do OK. DOS/CLI is/was insanely grotesque :eek:
BATCH-KYPEC-AviSource.avst (put in Avisynthesizer_Mod Template directory)
#ASYNTHER BATCH-KYPEC-AviSource
# Avisynthesizer_Mod TEMPLATE FILE, Above is shown in Avisynthesizer_Mod as "BATCH-KYPEC-AviSource"
#
# BATCH mode:= Select all input files in Explorer, SendTo Avisynthesizer, creates an AVS for each file selected.
#
# Requires Avisynthesizer_Mod, TWriteAVI v2.0, RT_Stats, GScript, (and as supplied: ffmpeg.exe, UT_Video codec).
#
# Can ReMake the Avisynthesizer_Mod Template by (ie Edit avs, when happy update Avisynthesizer_Mod template)
# Setting below SourceFilename to "***FILE***" replacing '*' with UnderScores.
# And Un-Comment 'Return Last' line after Trim/Crop etc section.
# 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
#
########## CONFIG #################
# FULL PATH Directories, DONT End In BACKSLASH/SLASH (MUST EXIST)
LOSSLESS_DIR = "D:\KYPEC\LOSSLESS"
AVSOUTPUT_DIR = "D:\KYPEC\AVSOUTPUT"
BATOUTPUT_DIR = "D:\KYPEC\BATOUTPUT"
OUTPUT_DIR = "D:\KYPEC\OUTPUT"
### FINAL BAT Output file Extension Including '.' eg '.MP4'
EXT = ".MP4"
###
myName = "KYPEC: " # Name for DebugView
FOURCC = "ULY0" # UT_Video YV12 rec601 Lossless codec
AUTODEL = True # Auto Delete Existing FINAL output file (created by Batch, otherwise ffmpeg will ask)
RETCLIP = 2 # Return clip: 0=Processed Input, 1=Lossless : 2=MessageClip
FORCEWRITE = True # MUST BE TRUE if RETCLIP==1 (Lossless)
ENCODE = True # Cannot be True unless FORCEWRITE==True
### Encoder Command, (can be Multi-Line)
# Can use strings as in BAT Template described later(ie ___AVS___, ___AVI___,___ONAME___,___OFILE___,___EXT___,___OERR___)
ENCCMD = ("""
"C:\BIN\ffmpeg.exe" -i "___AVS___" "___OFILE___"
""")
###################################
###################################
###################################
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.
###################################
###################################
###################################
Assert(RETCLIP>=0 && RETCLIP<=2,RT_String("%s 0 <= RETCLIP <= 2",myName))
Assert(FORCEWRITE || RETCLIP!=1,RT_String("%s RETCLIP Cannot be 1 when FORCEWRITE==False",myName))
Assert(FORCEWRITE || !ENCODE,RT_String("%s ENCODE Cannot be True when FORCEWRITE==False",myName))
# AVS Template to Load Lossless AVI file, ___AVS___ is self name ie name of the AVS file, ___AVI___ name of AVI to load.
AVS_TMPT=("""
FN="___AVI__"
Ex=Exist(FN) RT_DebugF("%s\n Avisource('%s')%s","___AVS___",FN,(Ex)?"":Chr(10)+" Does NOT Exist",name="AVS_SCRIPT: ")
Return AVISource(FN)
""")
###
# BAT Template to encode Lossless AVI file to output, Can use below in BAT file (3 underscore either side):-
# "___AVS___" For *.avs input
# "___AVI___" For *.avi input
# "___ONAME___" For FULL PATH OUTPUT Filename without extension
# "___OFILE___" For FULL PATH OUTPUT Filename Including extension
# "___OEXT___" For output extension ONLY (including '.' eg '.MP4').
# "___OERR___" For output error file.
BAT_TMPT=("""
set result=0
___ENCODER___
set result=%ERRORLEVEL%
@ECHO.%result%>"___OERR___"
if %result% NEQ 0 Pause REM Pause on error
Exit %result%
""")
GSCript("""
###################################
Node = RT_FilenameSplit(SourceFilename,get=4) # Filename Node only, no path nor extension
Bat = RT_String("%s\\%s.BAT",BATOUTPUT_DIR,Node)
Avi = RT_String("%s\\%s.AVI",LOSSLESS_DIR,Node)
Avs = RT_String("%s\\%s.AVS",AVSOUTPUT_DIR,Node)
oName = RT_String("%s\\%s",OUTPUT_DIR,Node) # Excluding file Extension
oFile = RT_String("%s\\%s%s",OUTPUT_DIR,Node,EXT) # Including file Extension
oErr = RT_String("%s\\%s.ERR",BATOUTPUT_DIR,Node) # BAT Error code file
#
AVS_TMPT = RT_StrReplaceMulti(AVS_TMPT,RT_string("___AVS___\n___AVI__\n"),RT_string("%s\n%s\n",AVS,AVI))
#
BAT_TMPT = RT_StrReplace(BAT_TMPT,"___ENCODER___",ENCCMD)
FndS = RT_String("___AVI___\n___AVS___\n___ONAME___\n___OFILE___\n___OEXT___\n___OERR___\n")
RepS = RT_String("%s\n%s\n%s\n%s\n%s\n%s\n",AVI,AVS,oName,oFile,EXT,oErr)
BAT_TMPT = RT_StrReplaceMulti(BAT_TMPT,FndS,RepS)
#
RT_DebugF("\nWriting AVS '%s'\n>>>>>>%s\n<<<<<<",AVS,Avs_TMPT,name=myName) RT_WriteFile(Avs,"%s",Avs_TMPT) # Write AVS file
RT_DebugF("\nWriting BAT '%s'\n>>>>>>%s\n<<<<<<",Bat,Bat_TMPT,name=myName) RT_WriteFile(Bat,"%s",Bat_TMPT) # Write BAT file
###### Write and play processed clip
RT_DebugF("Calling TWriteAVI Constructor '%s'",AVI,name=myName) TWriteAVI(AVI,Overwrite=true,Fourcc=FOURCC)
if(FORCEWRITE) {
RT_DebugF("Calling ForceProcessAVI",name=myName) ForceProcessAVI
if(ENCODE) {
if(RETCLIP != 0) {
RT_DebugF("Last=0 SetMemoryMax(256) : Free Memory for encoder ",name=myName) Last=0 SetMemoryMax(256)
}
#RT_FileDelete(AVI) # Simulate ERROR ... AVI is missing
#RT_FileDelete(AVS) # Simulate ERROR ... AVS is missing
RT_DebugF("Calling CallEncoder",name=myName) CallEncoder(BAT,oFile,AUTODEL,oErr)
}
}
if(RETCLIP==1) {RT_DebugF("Loading Lossless",name=myName) AviSource(AVI)}
Else if(RETCLIP==2) {MessageClip("Done")}
RT_DebugF("ALL DONE",name=myName)
Return Last
########################################
Function CallEncoder(String BAT,String oFile,Bool AUTODEL,String oErr) {
myName="CallEncoder: " Exist(oERR) ? RT_FileDelete(oErr) : NOP
OldEx = Exist(oFile) OldTim = (OldEx) ? RT_GetFileTime(oFile,1) : ""
(OldEx) ? RT_DebugF("Output Already Exists, Modification Time = %s",OldTim,name=myName) : NOP
(AUTODEL && OldEx) ? RT_DebugF("Deleting existing Output",name=myName) : NOP
(AUTODEL && OldEx) ? RT_FileDelete(oFile) : NOP
RT_DebugF("Calling Encode BAT '%s'",BAT,name=myName)
E = RT_Call(BAT,Hide=False,Debug=True)
LastErr = RT_GetLastErrorString() # Not necessarily our error
Assert(E==0,RT_String("%s::RT_Call: Start Process Failed on\n%s\nLastSysError='%s'",myName,BAT,LastErr))
NewEx = Exist(oFile) NewTim = (NewEx) ? RT_GetFileTime(oFile,1) : ""
(NewTim!="") ? RT_DebugF("Output Modification Time = %s",NewTim,name=myName) : NOP
E=(NewTim > OldTim)?0:-1
if(Exist(oErr)) {
Lines = RT_FileQueryLines(oErr)
E = (Lines>0) ? RT_NumberValue(RT_ReadTxtFromFile(oErr ,Lines=1)) : E
if(Lines>0) {RT_DebugF("Got Error Code from BAT Command Error File(%d:$%0.8X)",E,E,name=myName)}
Else {RT_DebugF("Cannot Read Error Code from BAT Command Error File",name=myName)}
RT_FileDelete(oErr) # Delete Error status file
} Else {RT_DebugF("Error file from BAT Command does Not Exist",name=myName)}
Assert(E==0 ,RT_String("RT_Call: output FAILED(%d:$%0.8X)\n%s\nLastSysError='%s'",E,E,BAT,LastErr))
return 0
}
""")
Success
00000003 1.65224695 KYPEC:
00000004 1.65226638 KYPEC: Writing AVS 'D:\KYPEC\AVSOUTPUT\K.AVS'
00000005 1.65229297 KYPEC: >>>>>>
00000006 1.65231669 KYPEC: FN="D:\KYPEC\LOSSLESS\K.AVI"
00000007 1.65234113 KYPEC: Ex=Exist(FN) RT_DebugF("%s\n Avisource('%s')%s","D:\KYPEC\AVSOUTPUT\K.AVS",FN,(Ex)?"":Chr(10)+" Does NOT Exist",name="AVS_SCRIPT: ")
00000008 1.65236557 KYPEC: Return AVISource(FN)
00000009 1.65238917 KYPEC:
00000010 1.65241277 KYPEC: <<<<<<
00000011 1.65284038 KYPEC:
00000012 1.65286601 KYPEC: Writing BAT 'D:\KYPEC\BATOUTPUT\K.BAT'
00000013 1.65289271 KYPEC: >>>>>>
00000014 1.65291655 KYPEC: set result=0
00000015 1.65294039 KYPEC:
00000016 1.65296435 KYPEC: "C:\BIN\ffmpeg.exe" -i "D:\KYPEC\AVSOUTPUT\K.AVS" "D:\KYPEC\OUTPUT\K.MP4"
00000017 1.65298820 KYPEC:
00000018 1.65301192 KYPEC: set result=%ERRORLEVEL%
00000019 1.65303564 KYPEC: @ECHO.%result%>"D:\KYPEC\BATOUTPUT\K.ERR"
00000020 1.65305948 KYPEC: if %result% NEQ 0 Pause REM Pause on error
00000021 1.65308321 KYPEC: Exit %result%
00000022 1.65310729 KYPEC:
00000023 1.65313101 KYPEC: <<<<<<
00000024 1.65353608 KYPEC: Calling TWriteAVI Constructor 'D:\KYPEC\LOSSLESS\K.AVI'
00000025 1.65913367 KYPEC: Calling ForceProcessAVI
00000026 3.09556413 KYPEC: Last=0 SetMemoryMax(256) : Free Memory for encoder
00000027 3.09607911 KYPEC: Calling CallEncoder
00000028 3.10097837 CallEncoder: Calling Encode BAT 'D:\KYPEC\BATOUTPUT\K.BAT'
00000029 3.10162950 RT_Call: D:\KYPEC\BATOUTPUT\K.BAT
00000032 5.16657209 AVS_SCRIPT: D:\KYPEC\AVSOUTPUT\K.AVS
00000033 5.16659260 AVS_SCRIPT: Avisource('D:\KYPEC\LOSSLESS\K.AVI')
00000034 12.88903522 RT_Call: Process returned = 0 (0x00000000)
00000035 12.89036369 CallEncoder: Output Modification Time = 2015-12-24 17:36:33.843
00000036 12.89667034 CallEncoder: Got Error Code from BAT Command Error File(0:$00000000)
00000037 12.90277195 KYPEC: ALL DONE
Fail, where different to above. (Missing AVI, deliberately deleted ie test fail)
00000034 8.45142555 AVS_SCRIPT: D:\KYPEC\AVSOUTPUT\K.AVS
00000035 8.45144844 AVS_SCRIPT: Avisource('D:\KYPEC\LOSSLESS\K.AVI')
00000036 8.45147228 AVS_SCRIPT: Does NOT Exist
00000037 14.11865234 RT_Call: Process returned = 1 (0x00000001)
00000038 14.11867142 CallEncoder: Got Error Code from BAT Command Error File(1:$00000001)
StainlessS
24th December 2015, 07:48
MysteryX,
Can you provide your full script, and what are you playing, resultant WAV in another scipt, or
AudioDub WavSource() from Lossless WAV or
result or TWriteWAV audiodubbed onto source clip or what.
Does output WAV play OK ?
Also, try using TimeStretched/TimeStretched_32Bit/TimeStretched_Float clip as source (does that work).
Where did you find TimeStretch.dll (Wilberts latest) ?
LSmash/FFMpegSource ? (and version).
Also see TWriteAVI.avs scipt in 1st post and in particular this stuff
Global OPT_UseWaveExtensible = (AudioChannels>2||AudioBits>16) # If more than 2 channels or > 16 bit, set true.
Global OPT_AllowFloatAudio = (IsAudioFloat) # Must be set true to play in eg Media Player Classic - Home Cinema
# Otherwise Avisynth output converted to 16 bit.
EDIT: Wiki:http://avisynth.nl/index.php/Internal_functions#OPT_AllowFloatAudio
EDIT: Also, try different source filter.
EDIT: And what player ?
EDIT: You could play the output WAV by using eg Wavsource("Job5_Output.wav") at end of script instead of doing the
timestretch etc a second time when playing (or remove the ForceProcessWAV) to write at same time as play (no jumping about
else will switch off writing WAV).
EDIT: Without TWriteWAV/ForceProcessWAV, does it play OK a second time without weirdness ?
(although you would probably need to halt just before end and SEEK back to beginning, to avoid effect of player reset)
EDIT: I gotta get some sleep, bye.
EDIT: Good afternoon.
And tell me that you are not trying to use MT again.
The VirtualDub source inside TWriteAVI/WAV does its own multi-threading/double buffering, all MT would do is try to mess up the
AVI/WAV (as it tries to write it multiple times into same stream, perhaps messing up file format and such).
Switch off MT before TWriteAVI/WAV and/or ForceProcessAVI/WAV.
You might be able to switch it back on again afterwards, not sure. MT afterwards may request multiple out of order
frames/samples from TWriteAVI/WAV and cause writing to file out of order too.
I cannot do anything to make MT compatible (if it were possible) as that is well beyond me, I dont use MT
and my machine is duel core, so would have no real way of testing anyway.
MysteryX
24th December 2015, 18:41
I'm not using MT. I'm reading the full script, commenting the MT code, writing the script file back and executing the temp script. I'll do more tests and post samples later.
StainlessS
24th December 2015, 18:47
I'm not using MT. I'm reading the full script, commenting the MT code, writing the script file back and executing the temp script. I'll do more tests and post samples later.
Thanx MX.
Post #25 Updated.
MysteryX
26th December 2015, 19:15
Ok this is strange. Here's my script.
P="Encoder\"
LoadPlugin(P+"Shader.dll")
Import(P+"ColorMatrix.avsi")
Import(P+"ResizeX.avsi")
file="Job4_Input.avi"
AviSource(file, audio=True, pixel_type="YV12")
ResizeX(384, 288)
LoadPlugin(P+"TimeStretch.dll")
ResampleAudio(48000)
TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)
ConvertAudioTo32bit()
LoadPlugin(P+"TWriteAVI.dll")
TWriteWAV("Job4_Output.wav", true)
ForceProcessWAV()
When I open this script in MPC-HC, the WAV output file is good.
If I play the same script in VirtualDub, however, the WAV output is distorted.
Here's my source video (https://www.spiritualselftransformation.com/files/media-encoder-old.mpg)
Here's the corrupt audio output. (https://mega.nz/#!6IZnFIAB!6uZZpz50LXGiGj6wQMl77QKjzFqJV6GIS_f4jAjIhFo)
StainlessS
26th December 2015, 20:04
I doubt that I can use your Shader.dll on my machine.
ColorMatrix.avsi, ResizeX (presume ResizeX is for Shader.dll) should not be relevant, as problem is audio and no point in complicating things.
In the script via MPC-HC you are playing the Pre-TwriteWAV audio Or at least you would be if final Return Last, dont see how your
script works without return Last, as ForceProcess() returns 0 (I think), would get a message something like "does not return a clip".
downloading your clip. (by the way, VDub does not support Float, if your try that)
EDIT: TWiteWAV returns original audio.
MysteryX
27th December 2015, 03:37
It returns an error but it works anyway. I could add "Return Last".
You say it returns original audio, or processed audio, or processed audio with distortion?
If VDub doesn't support float, it could explain why it fails to process properly, as the audio is in float format by default after processing.
MysteryX
28th December 2015, 02:16
I tried again, here's my script. Still the same problem.
P="Encoder\"
AviSource("Preview.avi", audio=True, pixel_type="YV12")
ConvertAudioTo32bit()
LoadPlugin(P+"TimeStretch.dll")
ResampleAudio(48000)
TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)
LoadPlugin(P+"TWriteAVI.dll")
TWriteWAV("Preview2.wav", true)
ForceProcessWAV()
return last
With AVSMeter, it returns a valid audio. What's interesting is that the audio file gets generated twice. Same with MPC-HC, it gets generated twice. With VirtualDub, it gets generated once and it's distorted.
Still no clue what's going on.
StainlessS
28th December 2015, 07:36
I'm getting exceptions in VDUB, but not VDubMod with just this
#P="Encoder\"
#LoadPlugin(P+"TimeStretch.dll")
#LoadPlugin(P+"TWriteAVI.dll")
#AviSource("Preview.avi", audio=True, pixel_type="YV12")
AviSource("media-encoder-old.mpg.AVI", audio=True, pixel_type="YV12")
TWriteWAV("Preview2.wav", true)
return last
Loading [EDIT: avs] into VD, play a little and then exit, crash, unhandled CPP exception.
EDIT:
gets generated twice
Yes, once for ForceProcessWAV, and then again to play, as you do not load in the already written lossless file.
Unhandled CPP exception above is probably related to your error, so I must find that 1st.
I'm getting this below crash dump from VDub,
VirtualDub crash report -- build 35491 (release)
--------------------------------------
Disassembly:
7c812f40: 013b add [ebx], edi
7c812f42: c60f84 mov byte ptr [edi], 84h
7c812f45: 9d popfd
7c812f46: 1e push ds
7c812f47: 0300 add eax, [eax]
7c812f49: 8975e4 mov [ebp-1ch], esi
7c812f4c: 834dfcff or dword ptr [ebp-04h], 0ffh
7c812f50: e81c000000 call 7c812f71
7c812f55: 8b45e4 mov eax, [ebp-1ch]
7c812f58: e8b4f5feff call 7c802511
7c812f5d: c20c00 ret 000c
7c812f60: ff db 0ffh
7c812f61: ff db 0ffh
7c812f62: ff db 0ffh
7c812f63: ff00 inc dword ptr [eax]
7c812f65: 0000 add [eax], al
7c812f67: 00712f add [ecx+2fh], dh
7c812f6a: 817c9090909090 cmp dword ptr [eax+edx*4-70h], 8d909090
8d
7c812f72: 45 inc ebp
7c812f73: cc int 3
7c812f74: 50 push eax
7c812f75: ff154412807c call dword ptr [7c801244]
7c812f7b: c3 ret
7c812f7c: 90 nop
7c812f7d: 90 nop
7c812f7e: 90 nop
7c812f7f: 90 nop
7c812f80: 90 nop
7c812f81: 8bff mov edi, edi
7c812f83: 55 push ebp
7c812f84: 8bec mov ebp, esp
7c812f86: 83ec50 sub esp, 50h
7c812f89: 8b4508 mov eax, [ebp+08h]
7c812f8c: 8365b800 and dword ptr [ebp-48h], 00h
7c812f90: 8945b0 mov [ebp-50h], eax
7c812f93: 8b450c mov eax, [ebp+0ch]
7c812f96: 56 push esi
7c812f97: 8b7514 mov esi, [ebp+14h]
7c812f9a: 83e001 and eax, 01h
7c812f9d: 85f6 test esi, esi
7c812f9f: 8945b4 mov [ebp-4ch], eax
7c812fa2: c745bc812f817c mov dword ptr [ebp-44h], 7c812f81
7c812fa9: 0f8499000000 jz 7c813048
7c812faf: 8b4d10 mov ecx, [ebp+10h]
7c812fb2: 83f90f cmp ecx, 0fh
7c812fb5: 0f871d1f0300 ja 7c844ed8
7c812fbb: 85c9 test ecx, ecx
7c812fbd: 894dc0 mov [ebp-40h], ecx
7c812fc0: 7407 jz 7c812fc9
7c812fc2: 57 push edi
7c812fc3: 8d7dc4 lea edi, [ebp-3ch]
7c812fc6: f3a5 rep movsd
7c812fc8: 5f pop edi
7c812fc9: 8d45b0 lea eax, [ebp-50h]
7c812fcc: 50 push eax
7c812fcd: ff151015807c call dword ptr [7c801510]
7c812fd3: 5e pop esi <-- FAULT
7c812fd4: c9 leave
7c812fd5: c21000 ret 0010
7c812fd8: 85ff test edi, edi
7c812fda: 0f8e5e8effff jle 7c80be3e
7c812fe0: 8b55fc mov edx, [ebp-04h]
7c812fe3: 89550c mov [ebp+0ch], edx
7c812fe6: 0fb716 movzx edx, word ptr [esi]
7c812fe9: 8b7df8 mov edi, [ebp-08h]
7c812fec: 8a143a mov dl, [edx+edi]
7c812fef: 8811 mov [ecx], dl
7c812ff1: 8b780c mov edi, [eax+0ch]
7c812ff4: 0fb6d2 movzx edx, dl
7c812ff7: 668b1457 mov dx, [edi+edx*2]
7c812ffb: 663b16 cmp edx, [esi]
7c812ffe: 0f85bb8c0300 jnz 7c84bcbf
7c813004: 8b5008 mov edx, [eax+08h]
7c813007: 668b5a04 mov bx, [edx+04h]
7c81300b: 3819 cmp [ecx], bl
7c81300d: 0f84b98c0300 jz 7c84bccc
7c813013: 46 inc esi
7c813014: 46 inc esi
7c813015: 41 inc ecx
7c813016: ff4d0c dec dword ptr [ebp+0ch]
7c813019: 75cb jnz 7c812fe6
7c81301b: e91e8effff jmp 7c80be3e
7c813020: 8b4d10 mov ecx, [ebp+10h]
7c813023: e84c73ffff call 7c80a374
7c813028: 8b550c mov edx, [ebp+0ch]
7c81302b: 8bd8 mov ebx, eax
7c81302d: 43 inc ebx
7c81302e: e9399effff jmp 7c80ce6c
7c813033: 8bd9 mov ebx, ecx
7c813035: 895d08 mov [ebp+08h], ebx
7c813038: e92e9dffff jmp 7c80cd6b
7c81303d: 8b35 mov esi, [ebp]
7c81303f: 9c pushfd
Built on Althena on Sun Oct 27 15:59:07 2013 using compiler version 1400
Windows 5.1 (Windows XP x86 build 2600) [Service Pack 3]
Memory status: virtual free 1933M/2048M, commit limit 5201M, physical total 3318M
EAX = 0012f4d0
EBX = 02184478
ECX = 00000000
EDX = 00000003
EBP = 0012f520
ESI = 0012f560
EDI = 0012f560
ESP = 0012f4cc
EIP = 7c812fd3
EFLAGS = 00200206
FPUCW = ffff027f
FPUTW = ffffffff
Crash reason: Unhandled Microsoft C++ Exception
Crash context:
An exception occurred in module 'kernel32'.
Pointer dumps:
EAX 0012f4d0: e06d7363 00000001 00000000 7c812fd3 00000003 19930520 0012f59c 023668a4
EBX 02184478: 0475dda0 0475aac0 00000000 53504665 61684320 4665676e 43205350 676e6168
ESI 0012f560: 0012f6d8 023067a9 0012f59c 023668a4 0012f7bc 0012f8b4 02184478 01c64bc8
EDI 0012f560: 0012f6d8 023067a9 0012f59c 023668a4 0012f7bc 0012f8b4 02184478 01c64bc8
ESP 0012f4c8: 00000000 0235a2a0 e06d7363 00000001 00000000 7c812fd3 00000003 19930520
0012f4e8: 0012f59c 023668a4 20656c69 63657073 65696669 0a002e64 cccccc00 cccccccc
0012f508: cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc 0012f560 02314e32
0012f528: e06d7363 00000001 00000003 0012f554 0012f6d8 0012f570 e06d7363 00000001
EBP 0012f520: 0012f560 02314e32 e06d7363 00000001 00000003 0012f554 0012f6d8 0012f570
0012f540: e06d7363 00000001 00000000 00000000 00000003 19930520 0012f59c 023668a4
0012f560: 0012f6d8 023067a9 0012f59c 023668a4 0012f7bc 0012f8b4 02184478 01c64bc8
0012f580: cccccccc 01c64bc8 cccccccc cccccccc 01c64bc8 cccccccc cccccccc 01c659b8
Thread call stack:
7c812fd3: kernel32!RaiseException [7c800000+12f81+52]
7c812fd3: kernel32!RaiseException [7c800000+12f81+52]
02314e32: TWriteAVI!_AvisynthPluginInit3@8 [02300000+c670+87c2]
023067a9: TWriteAVI!000067a9
0230617a: TWriteAVI!0000617a
023060eb: TWriteAVI!000060eb
0230f539: TWriteAVI!_AvisynthPluginInit3@8 [02300000+c670+2ec9]
0230f1fb: TWriteAVI!_AvisynthPluginInit3@8 [02300000+c670+2b8b]
02312b32: TWriteAVI!_AvisynthPluginInit3@8 [02300000+c670+64c2]
02312a7a: TWriteAVI!_AvisynthPluginInit3@8 [02300000+c670+640a]
023129eb: TWriteAVI!_AvisynthPluginInit3@8 [02300000+c670+637b]
0154d1de: AviSynth!DllGetClassObject [01440000+1e8c8+ee916]
0145c582: AviSynth!avs_is_yv24 [01440000+1a2a4+22de]
01514057: AviSynth!DllGetClassObject [01440000+1e8c8+b578f]
0144e7f7: AviSynth!0000e7f7
0144e3b9: AviSynth!0000e3b9
0144e31e: AviSynth!0000e31e
01453032: AviSynth!00013032
0145e03a: AviSynth!avs_is_yv24 [01440000+1a2a4+3d96]
0145e1e0: AviSynth!avs_is_yv24 [01440000+1a2a4+3f3c]
73b55e6d: AVIFIL32!AVIFileRelease [73b50000+5e5f+e]
004e1df2: AVIReadHandlerTunnelW32::Release()
004e961a: InputFileAVI::~InputFileAVI()
004e97a8: InputFileAVI::(special)()
004ea4dc: VDInputFileFLM::Release()
0047548e: VDProject::CloseAVI()
004563a1: Deinit()
00460803: WinMain@16()
005fc456: __tmainCRTStartup()
7c816037: kernel32!RegisterWaitForInputIdle [7c800000+15fee+49]
-- End of report
Very interesting but means little to me :)
MysteryX
28th December 2015, 23:45
I tried another approach with wavi.exe. I'm still getting the same distortion.
However, if I remove "ResampleAudio(48000)", it works!
Removing ResampleAudio also fixes the issue with TWriteAVI
StainlessS
29th December 2015, 01:49
However, if I remove "ResampleAudio(48000)", it works!
Changes to Float.
MysteryX
29th December 2015, 02:34
Changes to Float.
and if I re-change it to 16-bit afterwards, it still doesn't work.
Any way to resample then?
StainlessS
29th December 2015, 03:13
I'm on it, but I dont know if I will be able to find problem. Some of it is just beyond me (the VDub source is not terribly transparent,
especially if you aint a CPP progger).
MysteryX
29th December 2015, 03:15
I'm on it, but I dont know if I will be able to find problem. Some of it is just beyond me (the VDub source is not terribly transparent,
especially if you aint a CPP progger).
I'm not using VDub, but avs2yuv
StainlessS
29th December 2015, 03:21
The TwriteAVI stuff is VDub source code based, I was working mainly in the dark and guessing how to get it working.
I think it was from (from memory) VD 1.411, and my CPP aint too good, based only on 6 week course (1 week of which
instructor was sick [EDIT: and about 2/3 weeks of basic C which I did not need]) about Jan 1996. It would be better if
CPP guy could take over, now that it's mostly working, is real hard work for me.
EDIT: By the way, I think avs2yuv is also Vdub source based.
StainlessS
6th January 2016, 06:09
TwriteAVI update, v2.02, see 1st post.
TWriteAVI (where audio) now does equivalent to Trim(0,0) on source clip to trim/pad audio to exact same length as video,
and closes output file when both video/audio completely written. Returns the Trim()'ed source clip.
Give it a whirl willya MysteryX.
EDIT: Included this in AVS directory
MysteryX.avs
AviSource("media-encoder-old.mpg.AVI", audio=True, pixel_type="YV12") # length, 44.100KHz
Trim(0,0)
WAVNAME = "Preview.wav"
FORCE = True
USETHEFORCELUKE = True
#ConvertAudioTo32bit() # 32Bit PCM 44.1Khz
ResampleAudio(48000) # FLOAT 48Khz
TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484) # FLOAT 48Khz
TWriteWAV(WAVNAME, true)
(FORCE) ? ForceProcessWAV() : NOP # Optional
(FORCE&&USETHEFORCELUKE) ? AudioDub(WavSource(WAVNAME)) : NOP # Use Lossless ForceProcessWav file (Optional)
# 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
return last
EDIT: Change above USETHEFORCELUKE to true
EDIT: The above ConvertAudioTo32bit() is maybe just a time waster, possibly remove.
EDIT: Also, best add 'Trim(0,0) after AviSource (identical length audio, trimmed or padded, always a good idea in almost any script).
MysteryX
7th January 2016, 18:17
Tried it. Still have the same distortion when adding ResampleAudio
StainlessS
8th January 2016, 11:00
MysteryX, did you do anything to change volume level in WAV that you posted, is more quiet than output of TWriteWAV.
(Although I converted mpeg with ffmpeg to AVI).
I'm not hearing this distortion, here. (there seems to be a sort of buzz in your corrupt WAV on phones, but not on speaker,
not hearing any distortion in TWriteWAV output [execpt for some hissing near beginning which is in original Video Clip]).
MysteryX
11th January 2016, 05:21
I'm still definitely hearing heavy distortion. I'm checking that I have the right version of your DLL: edited on January 5th 2016, that looks good.
I tried on two different videos and had the same problem for both.
I was previously converting all videos into AVI. Now I'm instead using LWLibavVideoSource (within L-SMASH) as it is using the same code and gives the exact same input. I'm looking to remove the "Convert to AVI" option in my software if everything works fine with this.
Here's my audio export script.
I'll note that if I comment ResampleAudio, it works fine and the exported audio is still 32-bit float. Which means the issue isn't with float data; perhaps with the 48000hz sample rate?
P="Encoder\"
LoadPlugin(P+"LSMASHSource.dll")
LoadPlugin(P+"KNLMeansCL.dll")
LoadPlugin(P+"Shaders\Shader.dll")
Import(P+"SuperResXBR.avsi")
LoadPlugin(P+"svpflow1.dll")
LoadPlugin(P+"svpflow2.dll")
Import(P+"InterFrame2.avsi")
Import(P+"ResizeX.avsi")
file="Input.mpg"
LWLibavVideoSource(file, cache=false, threads=2)
AudioDub(LWLibavAudioSource(file, cache=false))
ConvertToYV24()
KNLMeansCL(D=1, A=2, h=2.1, cmode=true, device_type="GPU", device_id=1)
Trim(1750, 1875)
Crop(4, 40, -4, -28)
ConvertToYV12()
SuperResXBR(1, 1, xbrEdgeStrength=2, xbrSharpness=1.2, MatrixIn="601")
ConvertToYV12()
InterFrame(Cores=8, NewNum=60000, NewDen=1001, GPU=true)
SuperResXBR(1, 1, xbrEdgeStrength=2, xbrSharpness=1.2, WidthOut=1240, HeightOut=728)
ResizeX(1240, 720, 0, 4, -0, -4)
Trim(0,0)
LoadPlugin(P+"TimeStretch.dll")
ResampleAudio(48000)
TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)
LoadPlugin(P+"TWriteAVI.dll")
TWriteWAV("Job2_Output.wav", true)
ForceProcessWAV()
StainlessS
11th January 2016, 14:08
I tried another approach with wavi.exe. I'm still getting the same distortion.
However, if I remove "ResampleAudio(48000)", it works!
Removing ResampleAudio also fixes the issue with TWriteAVI
I think it was from (from memory) VD 1.411,
By the way, I think avs2yuv is also Vdub source based.
Well, I have no idea what the problem is, if you get same results in avs2yuv, then I find it hard to believe that the problem has not come to light before
(ie not TWriteWAV problem), as avs2yuv is quite heavily used by some (but not me).
All the TWriteWAV thing (and also avs2yuv) does is pass on a request for a number of audio samples to the previous audio filter, and pass it back to the filter that asked for it, it also calls TwriteWAV VDub code (internal to both TWriteWAV and avs2yuv) to write the samples to file.
TWriteWAV/avs2yuv do not concern themselves about sample rate and such (apart from setting it up in constructor call, on opening WAV file), all they do is request samples as requested of them, and write samples via vdub code, if it was faulty, then it would be faulty for every WAV (same for avs2yuv), ResampleAudio, TimeStretchPlugin, or whatever else should make no difference, and apart from eg BytesPerSample should make little difference to internal Vdub code, it just affects the sizes of buffers and bytes written.
I dont think I can do any more, dont think even a TWriteWAV problem. You need a simple script, removing as much/many of the filter calls as possible, and also pre-convert using ResampleAudio and Timestretch etc, and write to file somehow (perhaps using SoundOut, dont know if that uses VDub code internally), and only use eg Soundout result as input audio without any processing whatsoever in test of TWriteWAV/avs2yuv.
I anticipate that if you do as above, that the problem will reside in the SoundOut output audio, ie nothing to do with either TWriteWAV or avs2yuv.
MysteryX
13th January 2016, 16:55
Now this is the weirdest thing ever. I'm testing it again.
I have avs2yuv.exe in two locations. One on the C drive (part of my program) and one of the F drive (for testing)
If I call this from the F folder, it works.
avs2yuv "Job1_Temp.avs" -o -
I copy/pasted that exact avs2yuv file into the other folder in the C drive. If I run the exact same command from the C drive, then I get the distortion !?
Could it be some kind of security permission issue?
If I instead use AVSMeter.exe, and run it from both folders, I get the exact same issue: one works, one doesn't, with the exact same executable.
Edit: It's only causing problem within that one specific folder. I tried moving avs2yuv into other folder, some with longer paths, and it worked. I copy avs2yuv from \Encoder into \Encoder\Shaders, and the copy of the file works fine... !? If I copy avs2yuv.exe as avs2yuv2.exe into the same folder, however, that one fails too. And I can tell it's not avs2yuv's fault because the same thing happens with AvsMeter.
StainlessS
13th January 2016, 17:48
So whatever it is, it looks like it is particular to your system only ?
:confused:
EDIT: Just try re-create you Program folder, by copy/paste contained files, somewhere else on C drive,
or perhaps same location with different Folder name.
If works OK, then try rename new folder to original folder name, and retry again, what happens?
EDIT: Presumably Avs2yuv calls WAVI.EXE, yes ? (I dont use either, when I referred to avs2yuv in post #44, I should
have referred to Wavi.exe as originally mentioned by you in my quote of you, in post #44)
MysteryX
13th January 2016, 18:29
Wow. I found it. I have an older DLL version of AviSynth 2.6 MT in that folder.
I updated that DLL and now it works.
That was a sneaky one...
StainlessS
13th January 2016, 18:55
Nice one MX :)
Distortion caused by MT mutli-threading stuff trying to write WAV out of sequence (maybe, perhaps, just a guess).
Groucho2004
13th January 2016, 19:36
Distortion caused by MT mutli-threading stuff trying to write WAV out of sequence (maybe, perhaps, just a guess).
SEt's MT dll behaves exactly like the official ST version if one does not use any MT specific statements (SetMTMode, GetMTMode,...).
MysteryX
13th January 2016, 21:15
It's not related to MT. There just was a bug in the older version of AviSynth which was fixed afterwards.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.