Log in

View Full Version : TWriteAVI - Write AVI/WAV files in Avisynth


Pages : 1 [2]

yup
3rd April 2016, 17:20
StainlessS!
What could install on my PC?
When open script in MPC HC
LoadPlugin("TWriteAVI.dll")
#SetMTMode(3,8)
FFVideoSource("psalom103-muxed.mkv")
#SetMTMode(2,8)
nnedi3(field=-2,threads=1)
output=LanczosResize(960,720)
TWriteAvi("testbig.avi", overwrite=true, fourcc="ULY0")
ForceProcessAVI() # Forcibly write AVI
Return MessageClip("DONE")
After changing work only single thread version, when try MT I get error could not overrite file.
I am testing Your mod plugin.
yup.

StainlessS
3rd April 2016, 17:44
Hi Yup, I see you on-line now.

A few moments ago, you posted that you had a problem with "Module Not found", you seem to have gotten past that and now cannot delete existing
"testbig.avi". I would guess that something is 'holding on to" existing avi (has a lock on it or something), and so cannot be deleted.
Suggest try delete avi manually and retry, if you cannot manually delete, you might have to reboot to be sure whatever is 'holding on to' avi is no longer doing it.

EDIT: Also try with different player to MPC-HC (it sometimes tries to do some extra clever stuff).

EDIT: You should (I think) be able to use MT mode prior to writing file, but need to switch to single thread for writing (or it will crash),
the Vdub source does its own multi-threading.

yup
3rd April 2016, 18:24
StainlessS!

Now processing single thread script, if I reach limit 127 GB and gone I am reporting.
How I can change from MT to single thread before call TWriteAvi, SetMTMode(1)?

yup.

StainlessS
3rd April 2016, 19:12
Now processing single thread script, if I reach limit 127 GB and gone I am reporting.
I'm not sure what that means.

How I can change from MT to single thread before call TWriteAvi, SetMTMode(1)?
Sorry, no idea I dont use MT (dont have it).
Perhaps someone else can advise [Although I think I remember Groucho saying somewhere that it was SetMTMode(5)].

Found this here:- http://avisynth.nl/index.php/MT

SetMTmode

SetMTmode(int mode,int threads)

Place this at the first line in the Avisynth file to enable temporal (that is more than one frame is processed
at the same time) multithreading. Use it later in the script to change the mode for the filters below it.

int mode = 2

there are 6 modes:

Mode 1 is the fastest but only works with a few filter
Mode 2 should work with most filters but uses more memory
Mode 3 should work with some of the filters that don't work with mode 2 but is slower
Mode 4 is a combination of mode 2 and 3 and should work with even more filter but is both slower and uses more memory
Mode 5 is slowest (slower than not using SetMTMode) but should work with all filters that don't require linear
frameserving (that is, the frames come in order (frame 0,1,2 ... last)).
Mode 6 is a modified mode 5 that might be slightly faster

A more detailed explanation of the modes 1 and 2 can be read here: MT modes explained

int threads = 0

number of threads to use. Set to 0 to set it to the number of processors available. It is not possible to
change the number of threads other than in the first SetMTMode.


EDIT: By the way, I tested with all AVS demos provided in zip file and worked fine with the modified plugin (largest file size produced was 3.45GB).

EDIT: From above mode 5
should work with all filters that don't require linear frameserving
What about filters that DO REQUIRE linear frame serving, without the MT stuff constantly trying to interfere when VDub source
is trying to write entire frames (not just bits of them) and in the correct order for file format (not just any old order that MT wants to do it in) ? (anybody any clue about that, what about RequestLinear from TIVTC I think, would that work ?)

EDIT: Recompile of avs2avi posted in your thread yup:- http://forum.doom9.org/showthread.php?p=1763135#post1763135
EDIT: Avs2avi mod, completely untested (I've never used it).

StainlessS
3rd June 2016, 15:26
TWriteAVI v2.03, update, see 1st post.


07 Nov 2015. v2.0 Added v2.6 colour spaces (excluding YV411) + audio, + TwriteWAV + ForceProcess funcs. ssS.
20 Dec 2015. v2.01, Added Catch all Error Message.
06 Jan 2016. v2.02, Added Trim(0,0) to TWriteAVI, trim/pad audio to match video. Various other fixes.
03 June 2016. v2.03, Bugfix in GetFrame 'n' frame range limiting.
Changed behaviour for out of order frame request.

StainlessS
26th September 2016, 01:34
TWriteAVI v2.04, new version see first post.


26 Sept 2016. v2.04, Added Debug arg to ForceProcessAVI. [EDIT: Shows progress]
ForceProcessAVI, added Sleep(0) every 256 frames.
ForceProcessWAV, added Sleep(0) every 1 seconds worth of audio samples.
Fixed Skewed YUV chroma where mod 2 width.


Available @ Mediafire below in my sig.

StainlessS
29th July 2018, 16:48
TWriteAVI v2.05, new version, see 1st post.

Recompile with VS2008 (requires VS2008 runtimes).
Added VERSION resource in todays update, + a few other small changes.

EDIT: fixed AVS demo files to use either GSCript or AVS+ (requires one or the other).
EDIT: Avs v2.58 dll, and Avs/+ v2.60 dll, + source + VS2008 Project Files + AVS Script Demo Files. (~345KB)

StainlessS
29th July 2018, 19:41
Moved here from another thread:- https://forum.doom9.org/showthread.php?p=1847642#post1847642

By DavidHorman
I meant "why would it need inline ASM"
I would be quite happy with C/CPP alternative, maybe use asm if x86, and C if x64. (I dont imagine that the asm is that imperative).
In a few places, I found some alternative C in a later version of VirtualDub source, and added in TWriteAVI current version,

Here from Misc.cpp, (looks like _M_IX86 is always defined even when x64, so needs some attention)

#if defined(_M_IX86)

long __declspec(naked) MulDivTrunc(long a, long b, long c) {
__asm {
mov eax,[esp+4]
imul dword ptr [esp+8]
idiv dword ptr [esp+12]
ret
}
}

unsigned __declspec(naked) __stdcall MulDivUnsigned(unsigned a, unsigned b, unsigned c) {
__asm {
mov eax,[esp+4]
mov ecx,[esp+12]
mul dword ptr [esp+8]
shr ecx,1
add eax,ecx
adc edx,0
div dword ptr [esp+12]
ret 12
}
}
# else
long MulDivTrunc(long a, long b, long c) {
return (long)(((signed __int64)a * b) / c);
}

unsigned __stdcall MulDivUnsigned(unsigned a, unsigned b, unsigned c) {
return (unsigned)(((unsigned __int64)a * b + 0x80000000) / c);
}
# endif


EDIT: For x86, WIN32 is defined, for x64 both WIN32 and _WIN64 are defined.
EDIT: _M_AMD64 and _M_X64 are defined for x64 processors according to M$.

EDIT: FastWriteStream.cpp uses this (some kind of non-interruptable thread locking or something, dont know if easily possible in C)


// atomic add

__asm mov eax,this
__asm mov ebx,buffree
__asm lock add [eax]FastWriteStream.lDataPoint,ebx

...
// Atomically update data point and signal write thread

__asm mov eax,this
__asm mov ebx,len
__asm lock sub [eax]FastWriteStream.lDataPoint,ebx




EDIT: This seems to fix the asm in misc.cpp (another similar fix should be applied later in misc.cpp)

#if defined(_M_X64)
long MulDivTrunc(long a, long b, long c) {
return (long)(((signed __int64)a * b) / c);
}

unsigned __stdcall MulDivUnsigned(unsigned a, unsigned b, unsigned c) {
return (unsigned)(((unsigned __int64)a * b + 0x80000000) / c);
}
# else

long __declspec(naked) MulDivTrunc(long a, long b, long c) {
__asm {
mov eax,[esp+4]
imul dword ptr [esp+8]
idiv dword ptr [esp+12]
ret
}
}

unsigned __declspec(naked) __stdcall MulDivUnsigned(unsigned a, unsigned b, unsigned c) {
__asm {
mov eax,[esp+4]
mov ecx,[esp+12]
mul dword ptr [esp+8]
shr ecx,1
add eax,ecx
adc edx,0
div dword ptr [esp+12]
ret 12
}
}
# endif

VoodooFX
28th September 2022, 10:17
Looks like another wonderful plugin from you. Probably I'll apply it to my stuff. :thanks:
Btw, why don't you upload your plugins to GitHub? Any hopes for x64?

StainlessS
28th September 2022, 14:21
Watch out, it only copes with write up to 2GB (I think), does not do the the big version AVI (forgot what its called), source extracted from [EDIT: avs2avi, which was extracted from] VDub 1.4x
(I think, - not by me, by TBarry maybe, not sure) from before the big AVI was 'invented'.

GitHub, maybe one day.

EDIT: x64, it has Intel assembler, and I dont do that, sorry. [Was hopin' that Grouchy or Wonkey_Donkey was gonna help, but alas, must be too busy].
(Also, the source of more current VDub is a bit too much C++ for me to understand to convert to the "Big AVI" stuff)

EDIT: "Big AVI", maybe 'OpenDML' AVI.

VoodooFX
28th September 2022, 22:27
I've plugged it to a subs extractor, works like a charm, now it runs ~twice faster because with an intermediate file you don't need to run the processing+source decoding ~twice.

Don't care much about 2GB limit because x264 lossless compression on B/W masks is very efficient, usually less than 100MB on hours of video and it's faster than ULY0.

StainlessS
29th September 2022, 13:46
Oh good.
TWriteAVI (pre my updates) only handled video and so of more limited general use,
is a shame that it has not been updated to OpenDML bigger than 2GB, the source would generally be a lot more
useful in other apps [even unrelated to avs].
The current VDub 1.10.4 and VDub2 source are massive and making any sense of it would be a big job (especially for my C++, and no intel assembler).
Sad but there you go.

EDIT: I had never tested TWriteAVI over 2GB, so was not aware that it was size limited until relatively recently [2020 or thereabouts, maybe]

EDIT: JFYI, no reply necessary.

EDIT: Original TWriteAVI was by Tritical, Squid_80 and Mikeytown2, modded/extracted from existing [EDIT: avs2avi which was in turn taken from] VDub 1.4x [Avery Lee], which is (I think) derived from a number of other open sources.

VoodooFX
3rd October 2022, 09:38
Good news from Asd-g, x64 (and x86) build: TWriteAVI v2.5.1 (//github.com/Asd-g/AviSynth-TWriteAVI)

StainlessS
3rd October 2022, 12:03
Thanx very much to both of you [esp Asd-g], gonna have a good look at it. :)

StainlessS
3rd October 2022, 14:07
Right, had a bit of a test using the TWriteAVI (AVS folder) Demo scripts, one of which joins together 1000 20 frame files
into single 20,000 frame clip, and results in 1280x720 8.7 GB file, so is writing above 2GB OK now, lovely :)
[Separate script creates the 1000, 20 frame test files from a single source file]

Thanks again Asd-g, you is da man.

EDIT: Still limited to AVS v2.60 Std colorspaces.

Edit:
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].

EDIT:
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: 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. [EDIT: Demo encoder script @ post #25]