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 Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th August 2006, 17:47   #1  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
Crash with multiple instances of subtitle()

I am using the latest AviSynth and I am getting an exception with one of my scripts. Can anyone comment?

http://forum.doom9.org/showthread.php?t=114594

Last edited by raymod2; 24th August 2006 at 05:24.
raymod2 is offline   Reply With Quote
Old 12th August 2006, 19:28   #2  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
I tried commenting out the function calls to externel filters (EEDI2 and TDeint). It got farther this time (frame 42010) but it still crashed. So the bug appears to be in AviSynth itself. Please advise on how to proceed to debug this problem.
raymod2 is offline   Reply With Quote
Old 14th August 2006, 02:35   #3  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,168
You know the drill. Empty plugin directory. Simplest script that demonstates the problem (no .avsi's, paste the code inline). Explicit instruction how to cause the problem. Revision of any pluggins and codecs. Where to get them if they are not available from avisynth.org (plugins without source not supported). Does a BlankClip pseudo source demonstrate the problem (i.e is the problem data dependant or a bug in ...Source) And no super wide posts!

Also 2.5.6a will give the address of the failing instruction and the read/write target address in the message (Note XPsp2 will commit suicide rather than be this helpfull) 2.5.7 will just say "system exception" doh!.

If you have VS, run it under the debugger. Even without symbols you can at least get the .dll where the crash is happening. If you can compile avisynth, build a RELSYM build and debug that.

BlankClip pseudo source:-
Code:
V=Mpeg2Source(xxx.d2v)
A=WavSource(xxx.wav)
AudioDub(V, A)
BlankClip(Last) # Match source shape!
IanB is offline   Reply With Quote
Old 14th August 2006, 19:32   #4  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
I replaced my calls to AviSource() with BlankClip() and the failure still occurs. I have included the script as an attachment since it is too big to paste as code. It requires no external files or filters. The way I have been testing it is to run it through x264 as follows. It always crashes before it finishes all 95761 frames.

x264 -B 750 -f 0:0 -b 3 --b-pyramid -w -p 1 -r 1 -A none --me dia -m 1 --progress -o NUL script.avs
Attached Files
File Type: txt script.txt (27.3 KB, 111 views)
raymod2 is offline   Reply With Quote
Old 21st August 2006, 06:15   #5  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
@IanB: Were you able to reproduce the crash with the script I provided?
raymod2 is offline   Reply With Quote
Old 22nd August 2006, 02:20   #6  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,168
It doesn't fail in 5 minutes. I will look at it some more when I can dedicate a big chunk of machine time to it.
IanB is offline   Reply With Quote
Old 22nd August 2006, 04:52   #7  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
It takes more than 5 minutes. Closer to half an hour. I'd like to get to the bottom of this because I have spent countless hours trying to find a workaround and it's been holding up a project of mine.
raymod2 is offline   Reply With Quote
Old 23rd August 2006, 02:41   #8  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,168
Okay, it's the extreme number of Subtitle calls.

Subtitle allocates it's resources when the 1st frame to be subtitled is rendered. It releases them when the 11th frame after the last to be subtitled is rendered.

In your script each little piece of clip you trim is subtitled from beginning to end, so the GDI resources don't get released and eventually you run out and windows crashes.

As a work around don't subtitle the last 11 frames of each little segment.
Code:
function Process(clip in, bool interlaced, string name, string score, string run)
{
   in = interlaced ? Deinterlace(in, true) : in
   in = in.LanczosResize(656,480)
   in = in.subtitle(name,   16, 16, align = 7, last_frame=in.FrameCount-12)
   in = in.subtitle(score, 328, 16, align = 8, last_frame=in.FrameCount-12)
   in = in.subtitle(run,   640, 16, align = 9, last_frame=in.FrameCount-12)
   return in
}
This will cause the GDI resource to be released for each clip segment.

Likewise you are allocating a resizer per clip segment as well. Resize the entire input clip once before you chop it up. And similarly with the deinterlacing. i.e. have a master resized clip and a master deinterlaced and resized clip and feed segments of the appropriate one to Process() for subtitling.

Longer term I will see if I can restructure the AntiAliaser code to free the GDI resource earlier and not crash when they run out. It really only needs to keep the alpha_calcs array once the text is painted into it. Just need to make sure all the text painting routines conform.

Last edited by IanB; 23rd August 2006 at 02:48. Reason: [/code]
IanB is offline   Reply With Quote
Old 24th August 2006, 02:53   #9  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
@IanB: Thanks. I tried your workaround (last_frame=in.FrameCount-12) and it no longer crashes. Please let me know when the fix is released.

@mods: In the meantime maybe you could rename the topic to something like "crash with multiple instances of subtitle()".

P.S. Is there really a problem with having many instances of the resizing filter and the deinterlacing filters? I don't see how I can avoid this and still make the script easy to read and modify.
raymod2 is offline   Reply With Quote
Old 24th August 2006, 04:31   #10  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
it should be easier the way ianb suggests - just take the resize line out of "process" and put it after the input and before the process stuff is called.

[edit]
btw, if you edit your first post and click "go advanced", you can edit the thread title on your own
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 24th August 2006, 05:32   #11  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
You can't resize before you deinterlace.
raymod2 is offline   Reply With Quote
Old 24th August 2006, 06:29   #12  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,168
Quote:
Originally Posted by ianb
i.e. have a master resized clip and a master deinterlaced plus resized clip and feed segments of the appropriate one to Process() for subtitling.
Code:
....
VideoA=LanczosResize(600, 400)

Deinterlace(.....)
VideoB=LanczosResize(600, 400)
....
xyzzy1=VideoA.Trim(1234, 5678).Process(....)
xyzzy2=VideoB.Trim(5679, 9876).Process(....)
.....
Lots of instances of any filter is not great, it cost memory sometimes big chunks like in Overlay's internal YV24 buffers. In the case of the resizers they use dynamicly assembled code which take a small but noticable amount of time to compile, so lots of resizers means lots of startup delay.
IanB is offline   Reply With Quote
Old 24th August 2006, 06:33   #13  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
Quote:
Originally Posted by raymod2
You can't resize before you deinterlace.
ah, i missed that.

then you can put the deinterlace call before the resizer at the beginning of the script
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 1st September 2006, 06:26   #14  |  Link
raymod2
Registered User
 
Join Date: Jan 2005
Posts: 96
FYI: This bug also exists in SubtitleEx() and it can be suppressed with the workaround Ian described above.
raymod2 is offline   Reply With Quote
Old 4th September 2006, 03:51   #15  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,168
Just an update

This is not really a bug so much as a restriction. Raymod's original script causes 720 instances of the SubTitile filter object to be created. In an attempt to minimise resource usage the GDI resources needed to paint the text are only created when the first frame to be subtitled is rendered. So as the clip plays, more and more GDI resources are allocated, until eventually they run out. The bug part of the problem is the code doesn't check the return codes and blindly uses a Null pointer.

As the resources are released 10 frames after the last frame needing subtitling is rendered the workaround causes that frame to be rendered and the GDI resources hence get released.

I have commited to CVS fixes for checking the return value, so now instead of getting a GPF you will get a runtime exception thrown, which for non AVS aware apps will produce frames rendered with an Error Text (assuming the total lack of global resources doesn't choke something else).

Also in an attempt to avoid the problem the GDI resources are explicitly released when the last frame of a clip is rendered as well as frames outside the span of 10.
IanB 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 08:56.


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