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

Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 9th December 2019, 20:38   #5001  |  Link
dREV
Registered User
 
dREV's Avatar
 
Join Date: Jan 2019
Location: Antarctica
Posts: 74
Quote:
Originally Posted by FranceBB View Post
Not related to the Access Violation, but to the quality instead.
You are bringing everything to 16bit stacked, filtering with f3kdb with 16bit precision, then you are using DitherPost as default to bring everything to 8bit to filter with maa2, lastly you're using DitherPost(mode=6) which is dithering with the Floyd Steinberg error diffusion, then you're converting it again from 8bit dithered to 16bit planar, then you're bringing it to stacked MSB and LSB again, you apply your denoise and then you convert from 16bit stacked to 16bit interleaved and you output it as interleaved.

Why?


Doesn't this make more sense?

Code:
#Here we're telling f3kdb to take your 8bit source, filter it with 16bit precision and output 16bit stacked

#Debanding 16bit stacked

f3kdb(input_depth=8, output_mode=1, output_depth=16)

#Now we're gonna truncate everything to 8bit, 
#apply anti-aliasing with maa2 and then use the original 16bit stacked we received from f3kdb 
#and apply only the changes made by maa2 thus retaining 16bit precision

#antialiasing 8bit, 16bit stacked output
s16 = last
DitherPost (mode=-1)
maa2()
Dither_convert_8_to_16 ()
s16.Dither_limit_dif16 (last, thr=1.0, elast=2.0)

#16bit stacked resize and debanding

ly = GradFun3mod(thr=0.35,yuv444=true, resizer="DebilinearM", lsb_in=true, lsb=true)
lc = nnedi3_resize16(1280*2, 720*2,lsb_in=true,lsb=true,kernel_d="Spline36",kernel_u="Spline36",src_top=0.0,src_left=0.50,nlsb=false)
lu = lc.UtoY()
lv = lc.VtoY()
YtoUV(lu,lv,ly)


#your 16bit stacked degrain filter

Something()

#16bit planar output (your target is x265 which will handle 16bit planar just fine; just remember to add --dither to the command line)

ConvertFromStacked()
Thanks for your critique of my script. It's really helpful and will be looking at it more intently to better my script in the hopes I can speed up my encoding time or get better quality or both. However, sorry seems I took out the s16 code from my script example. Could you let me know if your critique still applies or not? I've indicated it with the color red (and some others) and yes I do use --dither. Link is here.

Also, would like to know why I cannot use Prefetch(2) for 720p or if I even need it or if 1 is good enough. For my DVD's in 480p it runs just fine with Prefetch(2) but if a source requires anti-aliasing using maa2() even at 480p I have no choice but to use Prefetch(1) as I get Access Violation.

I don't get it. With 8 gigs I thought that should be enough. Could it be that AviSynth issue running out of memory?

Last edited by dREV; 9th December 2019 at 20:54. Reason: stuff
dREV is offline  
Old 10th December 2019, 08:40   #5002  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,746
To access most of your RAM, do you execute it with a 64-bit application? Apart from that, an access violation can have different reasons, maybe also a code error in one of the used plugins, so it's probably worth a closer investigation. Try running it in AVSMeter64, this tool should produce quite verbose error messages. Also don't underestimate that an encoder itself needs RAM too (in this regard, 8 GB can already be "rather low" when processing FullHD content, too little for x265 already).
__________________

New German Gleitz board
MediaFire: x264 | x265 | VPx | AOM | Xvid
LigH is offline  
Old 10th December 2019, 10:50   #5003  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
What LigH said,
+, have a look at your Windows logs for both Application and System errors.
My Computer/Properties/Manage/Event Viewer/Windows Logs/
Application, & System

Quote:
Originally Posted by dREV View Post
It's AviSynth+ 0.1.0 r2772 using the 32 bit version with the 10 bit hack pipeline for HEVC in MeGUI 2525.
Best update to avs+ v3.4.0:- https://github.com/AviSynth/AviSynthPlus/releases
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 10th December 2019 at 11:00.
StainlessS is offline  
Old 10th December 2019, 20:55   #5004  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
Definitely update Avisynth+ like StainlessS said.
As to the lack of RAM, if you're using x86, you might wanna take a look at this: https://forum.doom9.org/showthread.php?t=163281
I successfully made Avisynth x86 use more than 7 GB of RAM on my 32 GB system by splitting each filter into a separate process so that each process can allocate 2 GB of RAM and Avisynth as a whole can allocate as much RAM as possible.
As to the modifications in red, I'll take a look at it later as I'm really in a hurry right now.
FranceBB is online now  
Old 16th December 2019, 10:02   #5005  |  Link
dREV
Registered User
 
dREV's Avatar
 
Join Date: Jan 2019
Location: Antarctica
Posts: 74
Quote:
Originally Posted by LigH View Post
To access most of your RAM, do you execute it with a 64-bit application? Apart from that, an access violation can have different reasons, maybe also a code error in one of the used plugins, so it's probably worth a closer investigation. Try running it in AVSMeter64, this tool should produce quite verbose error messages. Also don't underestimate that an encoder itself needs RAM too (in this regard, 8 GB can already be "rather low" when processing FullHD content, too little for x265 already).
You mean AviSynth+ 64 bit? No, I'm using the 32 bit version but I use the 64 bit HEVC and H264 encoders using the 10 bit hack pipeline. I lost detail when using jpsdr's ResampleMT/Desample with real.finder's updated DebilinearMscript 2-3 months ago. No clue if it's like the 32 bit now have not done any testings. My RAM is around 70% to 95% depending if I'm idle or watching YouTube (and having opened too many tabs) waiting on my encode to finish and other things. My issue is that if I don't take the precautions when using maa2 I have to wait for the indexing of lsmash to finish and that could take an hour or two and then go into each script and edit out/in "Prefetch(0)" to "Prefetch(1)" which adds to my annoyance and wastes my time especially when I wanna go to sleep.

I've only gotten this Access Violation majority of times when using real.finder's maa2 script in combination with Prefetch(1). It never fails. With older versions of maa2 this issue is non-existent. Maybe cuz real.finder's updated maa2 script uses HBD or something? I've used AVSMeter 32 bit version and it gives no errors just does it as if no issues.

Encoder needs RAM? That's news to me I never heard this before. I'm content with just 720p sources at the moment.

Quote:
Originally Posted by StainlessS View Post
What LigH said,
+, have a look at your Windows logs for both Application and System errors.
My Computer/Properties/Manage/Event Viewer/Windows Logs/
Application, & System

Best update to avs+ v3.4.0:- https://github.com/AviSynth/AviSynthPlus/releases
I'm not sure what that first one is about. My thing says it's not working maybe cuz I turned it off or something when I was turning/blocking telemetry on my PC. What does that have to do with the issue tho? Also, thanks I had no idea there was an update to Avisynth+. I thought pinterf was still doing but nothing kept turning up on his GitHub page and I haven't kept up to reading the AviSynth+ thread. Not sure why but got a lil bit more better details with this and seems the new AviSynth+ updater has included stuff for AMD users like me. I can't tell if I'm getting better speeds since I'm encoding using maa2 at the moment and that usually fluctuates. Ranging from 64 fps to 82 fps at the moment.

Quote:
Originally Posted by FranceBB View Post
Definitely update Avisynth+ like StainlessS said.
As to the lack of RAM, if you're using x86, you might wanna take a look at this: https://forum.doom9.org/showthread.php?t=163281
I successfully made Avisynth x86 use more than 7 GB of RAM on my 32 GB system by splitting each filter into a separate process so that each process can allocate 2 GB of RAM and Avisynth as a whole can allocate as much RAM as possible.
As to the modifications in red, I'll take a look at it later as I'm really in a hurry right now.
Nah, I'm on a 64 bit OS but using 32 bit AviSynth+ as mentioned above and my reasoning.

I've did a few tweaks using your critique if I understood it correctly. However, I cannot use your f3kdb settings cuz I get errors. MeGUI complains that the resolution is not the same plus there was some things that wasn't working out right like when I would use Gradfun3 with mask using lsb as I need it to be the first thing done before applying any other filter to lessen any detail loss. Anyways here's what I been using

Code:
dither_convert_8_to_16()

#Debanding - Gradfun3 16bit lsb with mask=0
#misc filter(s) 16 bit lsb - only if needed like smdegrain
s16 = last
DitherPost(mode=-1)

#line darkening (sometimes)
maa2()

dither_convert_8_to_16())
s16.Dither_limit_dif16 ()
ly = GradFun3mod(thr=0.35,yuv444=true, resizer="DebilinearM", lsb_in=true, lsb=true)
lc = nnedi3_resize16(1280*2, 720*2,lsb_in=true,lsb=true,kernel_d="Spline36",kernel_u="Spline36",src_top=0.0,src_left=0.50,nlsb=false)
lu = lc.UtoY()
lv = lc.VtoY()
YtoUV(lu,lv,ly)

DitherPost(mode=-1)

ConvertBits(bits=16) #I want this here to get more bitrate but at first I did some tests using what you wrote
ConvertToStacked()

# grain
ConvertFromStacked().ConvertToDoubleWidth()
What you think? I got a lil bit more detail like this and not sure on the fps since taking out TurnRight and Left since I didn't know maa2 had it in the script. Could you let me know what this is that you wrote?
Quote:
#Now we're gonna truncate everything to 8bit,
#apply anti-aliasing with maa2 and then use the original 16bit stacked we received from f3kdb
#and apply only the changes made by maa2 thus retaining 16bit precision

#antialiasing 8bit, 16bit stacked output
What do you mean by using the original 16 bit stacked received from f3kdb and apply only the changes made by maa2 retaining 16 bit precision? I understand the 16 bit precision but not the rest you wrote. And the "antialiasing 8 bit, 16 bit stacked output" part? Like adding dither 8 to 16 after maa2? I'm not understanding this if it's not that as I don't think maa2 has 16 bit.

Last edited by dREV; 16th December 2019 at 10:12. Reason: stuff
dREV is offline  
Old 16th December 2019, 15:07   #5006  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,821
Quote:
Originally Posted by dREV View Post
Also, would like to know why I cannot use Prefetch(2) for 720p or if I even need it or if 1 is good enough. For my DVD's in 480p it runs just fine with Prefetch(2) but if a source requires anti-aliasing using maa2() even at 480p I have no choice but to use Prefetch(1) as I get Access Violation.
Lsmash taking an hour or two to index seems completely mental, unless it's indexing a large number of files first before MeGUI encodes.

If I add maa2() to a script in MeGUI's Script Creator and preview it, when I close the Script Creator MeGUI invariably complains about an error and wants to close. MeGUI doesn't use Avisynth+ 3.4 as it's portable Avisynth yet and I haven't tested 3.4 as I still have Avisynth 2.6 installed, but it happens when using Avisynth 2.6 too. If I comment out maa2() before loading a script to add it to the job queue (as from memory, the same thing happens) then uncomment maa2() before running the encoding job, it's usually fine from there. I'm not using MeGUI's OneClick encoder. I'm running XP.

Maybe there's some weird problem with maa2() that only effects MeGUI, but I have no idea what could cause it. Have you tried opening a script containing maa2() with another program such as MPC-HC to see if there's still an access violation, assuming you have Avisynth installed? You can tell MeGUI to use the installed Avisynth to see if anything changes. I'm pretty sure for me, opening the script with a different program is not a problem, but don't quote me on that because I haven't used maa2() for a while and my memory is terrible.

Last edited by hello_hello; 16th December 2019 at 15:24.
hello_hello is offline  
Old 16th December 2019, 18:12   #5007  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,869
Quote:
Originally Posted by dREV View Post
Could you let me know what this is that you wrote?
What do you mean by using the original 16 bit stacked received from f3kdb and apply only the changes made by maa2 retaining 16 bit precision? I understand the 16 bit precision but not the rest you wrote. And the "antialiasing 8 bit, 16 bit stacked output" part? Like adding dither 8 to 16 after maa2? I'm not understanding this if it's not that as I don't think maa2 has 16 bit.
Well, you were filtering with 16bit precision, however maa2 works in 8bit planar only. The thing is that there's a "trick" to avoid losing 16bit precision when using an 8bit filter. Instead of either truncating or dithering down to 8bit, use maa2 and then bring it back to 16bit, we can do the following:


Code:
s16 = last
With this command we're basically gonna tell Avisynth to store into our variable "s16" our 16bit stacked output that we've received from f3kdb.

Now we're going to brutally truncate everything to 8bit planar so that maa2 can work, but don't worry, we're NOT gonna use it directly!

Code:
DitherPost (mode=-1)
Ok, now that we have a truncated 8bit planar result, we can use maa2 since it only supports this bit depth:

Code:
maa2()
Now that we have filtered with maa2, we're gonna bring it back to 16bit stacked.

Code:
Dither_convert_8_to_16 ()
Now, here's the tricky part.
If we go on with our filterchain like this we would lose precision 'cause we have brutally truncated our original 16bit stacked to 8bit planar in order to use maa2, so the 16bit stacked we ended up with at the end is "fake" in the sense that it has gone through a loss of precision.
But... remember what I wrote at the very beginning? We stored our original 16bit stacked BEFORE the anti-aliasing in our variable "s16". So now the idea is to tell Avisynth "Hey, take the original 16bit stacked clip, compare it with the anti-aliased 8bit planar one that we brought to the "fake" 16bit stacked and subtract the changes". This way it's as if we applied anti-aliasing with 16bit precision.


Quote:
Nah, I'm on a 64 bit OS but using 32 bit AviSynth+ as mentioned above and my reasoning.
That's exactly what I'm saying: since you're using 32bit Avisynth+ on a 64bit OS, you can allocate 4 GB maximum, however if you use MPPipeline you can allocate 4GB per process so if you split your script in as many processes as the filters you have, you can allocate 4GB per scrip, so if you have like 3 filters you can allocate 12 GB of RAM instead of 4GB.

Quote:
I cannot use your f3kdb settings cuz I get errors.
I see...

Last edited by FranceBB; 16th December 2019 at 20:03.
FranceBB is online now  
Old 17th December 2019, 04:13   #5008  |  Link
dREV
Registered User
 
dREV's Avatar
 
Join Date: Jan 2019
Location: Antarctica
Posts: 74
Quote:
Originally Posted by hello_hello View Post
Lsmash taking an hour or two to index seems completely mental, unless it's indexing a large number of files first before MeGUI encodes.
That was on the one included in MeGUI and it's from 2017. It takes that long because I use trim to look for banding scenes per episode could be a lot. I've had files where I had to encode over 75 times to get all the banding scenes maybe cuz I'm being too much of a perfectionist.

Quote:
Originally Posted by hello_hello View Post
If I add maa2() to a script in MeGUI's Script Creator and preview it, when I close the Script Creator MeGUI invariably complains about an error and wants to close. MeGUI doesn't use Avisynth+ 3.4 as it's portable Avisynth yet and I haven't tested 3.4 as I still have Avisynth 2.6 installed, but it happens when using Avisynth 2.6 too. If I comment out maa2() before loading a script to add it to the job queue (as from memory, the same thing happens) then uncomment maa2() before running the encoding job, it's usually fine from there. I'm not using MeGUI's OneClick encoder. I'm running XP.

Maybe there's some weird problem with maa2() that only effects MeGUI, but I have no idea what could cause it. Have you tried opening a script containing maa2() with another program such as MPC-HC to see if there's still an access violation, assuming you have Avisynth installed? You can tell MeGUI to use the installed Avisynth to see if anything changes. I'm pretty sure for me, opening the script with a different program is not a problem, but don't quote me on that because I haven't used maa2() for a while and my memory is terrible.
What I did was take the AviSynth+ dll from either the System32 folder or the SysWOW64 folder (dunno which one) and put it in the MeGUI root folder and in the MeGUI/Tools/avs folder to replace the old one. Open MeGUI go to the log tab under Versions it should say this:

--[Information] [12/16/2019 4:46:35 PM] AviSynth+: 3.4 (20-10-2019) (inactive)
--[Information] [12/16/2019 4:46:35 PM] AviSynth+ portable: 3.4 (20-10-2019) (active)

There might be more AviSynth dll's in MeGUI in other folders so may wanna use the search function to find em.

No, I haven't opened it in MPC-HC cuz I dunno how you guys do that. I've seen YouTube videos do that but no steps exactly what they did to get it to be viewed on MPC-HC. I'm using k-lite too codec pack. Would like to know how to do it on AVSPmod as well.


Quote:
Originally Posted by FranceBB View Post
Well, you were filtering with 16bit precision, however maa2 works in 8bit planar only. The thing is that there's a "trick" to avoid losing 16bit precision when using an 8bit filter. Instead of either truncating or dithering down to 8bit, use maa2 and then bring it back to 16bit, we can do the following:


Code:
s16 = last
With this command we're basically gonna tell Avisynth to store into our variable "s16" our 16bit stacked output that we've received from f3kdb.

Now we're going to brutally truncate everything to 8bit planar so that maa2 can work, but don't worry, we're NOT gonna use it directly!

Code:
DitherPost (mode=-1)
Ok, now that we have a truncated 8bit planar result, we can use maa2 since it only supports this bit depth:

Code:
maa2()
Now that we have filtered with maa2, we're gonna bring it back to 16bit stacked.

Code:
Dither_convert_8_to_16 ()
Now, here's the tricky part.
If we go on with our filterchain like this we would lose precision 'cause we have brutally truncated our original 16bit stacked to 8bit planar in order to use maa2, so the 16bit stacked we ended up with at the end is "fake" in the sense that it has gone through a loss of precision.
But... remember what I wrote at the very beginning? We stored our original 16bit stacked BEFORE the anti-aliasing in our variable "s16". So now the idea is to tell Avisynth "Hey, take the original 16bit stacked clip, compare it with the anti-aliased 8bit planar one that we brought to the "fake" 16bit stacked and subtract the changes". This way it's as if we applied anti-aliasing with 16bit precision.
Isn't that what I did with my script? It sounds like it.

Also, I worked out the error as I was confused how to implement dither_convert_8_to_16() with Gradfun3 deband filter as I need that. I had no idea that f3kdb(input_depth=8, output_mode=1, output_depth=16) can replace dither_convert_8_to_16() in avspmod and did a test encode and worked out. It's basically the same as above just the removal of the first dither 8 to 16 code.

Code:
f3kdb(input_depth=8, output_mode=1, output_depth=16) 

#Debanding - Gradfun3 16bit lsb with mask=0
#misc filter(s) 16 bit lsb - only if needed like smdegrain
s16 = last
DitherPost(mode=-1)

#line darkening (sometimes)
maa2()

dither_convert_8_to_16()
s16.Dither_limit_dif16 ()
ly = GradFun3mod(thr=0.35,yuv444=true, resizer="DebilinearM", lsb_in=true, lsb=true)
lc = nnedi3_resize16(1280*2, 720*2,lsb_in=true,lsb=true,kernel_d="Spline36",kernel_u="Spline36",src_top=0.0,src_left=0.50,nlsb=false)
lu = lc.UtoY()
lv = lc.VtoY()
YtoUV(lu,lv,ly)

DitherPost(mode=-1)

ConvertBits(bits=16) #I want this here to get more bitrate but at first I did some tests using what you wrote
ConvertToStacked()

# grain
ConvertFromStacked().ConvertToDoubleWidth()
What do you think now? Is it 16 precision fully even with the HDB 16 code after resize? I wasn't certain if this is what you were telling me a page ago of your first critique of my script. Would it matter if I add dither mode 6 in the DitherPost? Overall I got more bitrate with the above combination then the previous and looking forward to doing some more testings.

Quote:
Originally Posted by FranceBB View Post
That's exactly what I'm saying: since you're using 32bit Avisynth+ on a 64bit OS, you can allocate 4 GB maximum, however if you use MPPipeline you can allocate 4GB per process so if you split your script in as many processes as the filters you have, you can allocate 4GB per scrip, so if you have like 3 filters you can allocate 12 GB of RAM instead of 4GB.
I'll take a better look at it when I can. Thanks hoping for good things from it.

Last edited by dREV; 17th December 2019 at 04:18. Reason: stuff
dREV is offline  
Old 17th December 2019, 21:41   #5009  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,821
Quote:
Originally Posted by dREV View Post
What I did was take the AviSynth+ dll from either the System32 folder or the SysWOW64 folder (dunno which one) and put it in the MeGUI root folder and in the MeGUI/Tools/avs folder to replace the old one.
Did you check again after closing and re-opening MeGUI to make sure it doesn't replace them with the old Avisynth each time it starts?

Quote:
Originally Posted by dREV View Post
No, I haven't opened it in MPC-HC cuz I dunno how you guys do that. I've seen YouTube videos do that but no steps exactly what they did to get it to be viewed on MPC-HC. I'm using k-lite too codec pack. Would like to know how to do it on AVSPmod as well.
I put a shortcut to MPC-HC in the Windows SendTo folder so I can right click on a script and choose SendTo/MPC-HC. You can open scripts via MPC-HC's "File/Quick Open File" menu, but for some reason you can't see scripts by default. You have to select "All Files" from the drop down list of file types in the window for opening files.
For AvsPmod you either open an existing script or create a new one and it has a preview. I don't recall any special requirements for either, other than to have Avisynth installed, but I haven't installed Windows and programs from scratch in quite a while.

By the way, for MPC-HC, Ctrl+E re-opens the current video, so you can modify scripts and re-open them to view the change quite easily, or you can open the script in a second instance of the player to preview the difference. If you can't save changes to scripts because they're locked after MPC-HC opens them, try disabling the Avisynth source filter under Internal Filters in MPC-HC's options, or use Notepad to edit the the scripts. It ignores the locked status and lets you save changes, whereas other editors probably won't.
If a script is too slow MPC-HC will skip frames when you play it before possibly giving up completely, but you can still use the step button on the navigation bar to slowly step through frames etc.

Last edited by hello_hello; 17th December 2019 at 21:53.
hello_hello is offline  
Old 21st December 2019, 08:34   #5010  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Not sure if this has been flagged before. EDIT: v3.4.0

Code:
BITS=16
BlankClip.ConvertToYV12.ConvertBits(BITS)
X = 16
Y = 16
W = 128
H = 128
#COL=$00FFFFFF   # No Alpha
COL=$FFFFFFFF   # Full Alpha
WHT=BlankClip(Width=W,Height=H,Color=COL)   # Prob if RGB32 or YV12, but not YUV420P16
WHT=WHT.ConvertToYV12
#WHT=WHT.ConvertBits(BITS)
Overlay(WHT,x=X,y=Y)
crop(0,0,W+2*X,H+2*Y)                       # Crop Overlayed with 16 pixels border
PointResize(512,512)                        # for view
Rubbish at bottom of white
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 12th January 2020 at 14:31.
StainlessS is offline  
Old 29th December 2019, 20:44   #5011  |  Link
gpower2
gMKVExtractGUI author
 
gpower2's Avatar
 
Join Date: Aug 2003
Location: Greece / Thessaloniki
Posts: 251
Hey guys! I just installed AviSynth+ v3.4 and I am looking for the pdb file to load symbolas for AviSynth.dll but unfortunately they are not included in the release assets.

Any chance one of the devs could upload them somewhere?

PS.
I am trying to debug a custom application that uses AviSynth, however currently it fails to clear the resources, specifically when trying to delete the environment pointer:

Code:
IScriptEnvironment* environment;
...
delete environment;
environment = NULL;
It used to work with previous versions of AviSynth and AviSynth+ but now for some reason it gets stuck in an infinite loop when executing the delete statement...

Edit:
For any guru out there that can understand assembly, the instruction that gets stuck is:

Code:
07333830  mov         dword ptr [ebp-48h],eax

Last edited by gpower2; 29th December 2019 at 20:55.
gpower2 is offline  
Old 29th December 2019, 21:34   #5012  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
For reference, this is how I initialise (and destroy) IScriptEnvironment for AVS 2.6 (AVISYNTH_INTERFACE_VERSION 5/6):

Code:
const AVS_Linkage *AVS_linkage = 0;
typedef IScriptEnvironment * __stdcall CREATE_ENV(int);

int main()
{
  int iInterfaceVersion;
  IScriptEnvironment *AVS_env = 0;

  HINSTANCE hDLL = ::LoadLibrary("avisynth");
  if (!hDLL)
  {
    //Cannot load avisynth.dll
    return -1;
  }

  try
  {
    CREATE_ENV *CreateEnvironment = (CREATE_ENV *)GetProcAddress(hDLL, "CreateScriptEnvironment");
    if (!CreateEnvironment)
    {
      //Cannot load CreateScriptEnvironment()
      ::FreeLibrary(hDLL);
      return -1;
    }

    iInterfaceVersion = 7;
    while (!AVS_env)
    {
      iInterfaceVersion--;

      if (iInterfaceVersion < 5)
      {
        //Cannot create IScriptenvironment (AVSVersion too old)
        ::FreeLibrary(hDLL);
        return -1;
      }

      AVS_env = CreateEnvironment(iInterfaceVersion);
    }

    AVS_linkage = AVS_env->GetAVSLinkage();


    //Do your stuff



    //destroy
    AVS_env->DeleteScriptEnvironment();
    AVS_env = 0;
    AVS_linkage = 0;
  }
  catch (AvisynthError err)
  {
    printf("%s", (PCSTR)err.msg);
  }

  ::FreeLibrary(hDLL);
}
Note: This does not work for Avisynth 2.5!

There are additional checks I do, for example making sure avisynth.dll exports "AVS_linkage". If you're interested, look at the code of AVSMeter and/or avsr (link in my sig).
__________________
Groucho's Avisynth Stuff

Last edited by Groucho2004; 30th December 2019 at 20:23. Reason: updated code
Groucho2004 is offline  
Old 29th December 2019, 21:39   #5013  |  Link
gpower2
gMKVExtractGUI author
 
gpower2's Avatar
 
Join Date: Aug 2003
Location: Greece / Thessaloniki
Posts: 251
Thank you very much for your suggestions guys!

To be honest, I am using a patched version of AvisynthWrapper that MeGUI used (I am not sure if it still uses the same), for a C# application.

If I find the time, I may "play" with IScriptEnvironment2, although I am not sure if it's compatible with Avs 2.5 and Avs+ 3.4

But it would be nice to have the pdb files either way for such edge cases.
gpower2 is offline  
Old 29th December 2019, 21:50   #5014  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by gpower2 View Post
If I find the time, I may "play" with IScriptEnvironment2, although I am not sure if it's compatible with Avs 2.5 and Avs+ 3.4
It's compatible with AVS+ only but still experimental as far as I know.
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline  
Old 29th December 2019, 22:15   #5015  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,492
I deleted my post as I realised I don't really know what I'm talking about, but in any case I use IScriptEnvironment2 in conjunction with ->DeleteScriptEnvironment() to delete it, not just calling regular delete, so maybe that's the problem.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline  
Old 29th December 2019, 23:03   #5016  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,416
Quote:
Originally Posted by gpower2 View Post
Hey guys! I just installed AviSynth+ v3.4 and I am looking for the pdb file to load symbolas for AviSynth.dll but unfortunately they are not included in the release assets.

Any chance one of the devs could upload them somewhere?

PS.
I am trying to debug a custom application that uses AviSynth, however currently it fails to clear the resources, specifically when trying to delete the environment pointer:

Code:
IScriptEnvironment* environment;
...
delete environment;
environment = NULL;
It used to work with previous versions of AviSynth and AviSynth+ but now for some reason it gets stuck in an infinite loop when executing the delete statement...

Edit:
For any guru out there that can understand assembly, the instruction that gets stuck is:

Code:
07333830  mov         dword ptr [ebp-48h],eax
Shouldn't you set environment to NULL before you delete it? I'm not surprised if it crashes when done the other way; I'm pretty sure I had to hammer such a case out of the FFMS2 C-plugin once after changing how the AviSynth library got allocated.

But anyway, the reason is that 3.4 was built as Release, no *.pdb files were generated at all. Also, the packaging in CMakeLists.txt doesn't copy them over to Output/ even if they are generated.

http://www.mediafire.com/file/01xgi9...191227.7z/file

The current git HEAD hasn't changed too much since 3.4, so here's a build with the *.pdb and *.ilk files included.
qyot27 is offline  
Old 29th December 2019, 23:06   #5017  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by wonkey_monkey View Post
...I use IScriptEnvironment2 in conjunction with ->DeleteScriptEnvironment() to delete it...
Not sure if you need the new interface for additional functionality but you don't need IScriptEnvironment2 to use DeleteScriptEnvironment(), it works fine with IScriptEnvironment.
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline  
Old 29th December 2019, 23:21   #5018  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by qyot27 View Post
Shouldn't you set environment to NULL before you delete it? I'm not surprised if it crashes when done the other way; I'm pretty sure I had to hammer such a case out of the FFMS2 C-plugin once after changing how the AviSynth library got allocated.
Some info on the old 'delete' for AVS 2.5:
https://forum.doom9.org/showthread.p...te#post1631151

And the benefit of the newer DeleteScriptEnvironment():
https://forum.doom9.org/showthread.p...te#post1512400

When AVSMeter still used the 2.5 interface, I used this to destroy IScriptEnvironment:

AVS_env->~IScriptEnvironment();
AVS_env = 0;
__________________
Groucho's Avisynth Stuff

Last edited by Groucho2004; 29th December 2019 at 23:28.
Groucho2004 is offline  
Old 29th December 2019, 23:26   #5019  |  Link
gpower2
gMKVExtractGUI author
 
gpower2's Avatar
 
Join Date: Aug 2003
Location: Greece / Thessaloniki
Posts: 251
Quote:
Originally Posted by qyot27 View Post
Shouldn't you set environment to NULL before you delete it? I'm not surprised if it crashes when done the other way; I'm pretty sure I had to hammer such a case out of the FFMS2 C-plugin once after changing how the AviSynth library got allocated.

But anyway, the reason is that 3.4 was built as Release, no *.pdb files were generated at all. Also, the packaging in CMakeLists.txt doesn't copy them over to Output/ even if they are generated.

http://www.mediafire.com/file/01xgi9...191227.7z/file

The current git HEAD hasn't changed too much since 3.4, so here's a build with the *.pdb and *.ilk files included.
Actually the avisynth.h I am using doesn't contain a DeleteEnvironment definition in IScriptEnvironment class, so I can't use it.
Also, if I first assign it to NULL, how can I delete it afterwards? I am a bit of a n00b regarding C++ since I've never written anything at a professional level...

The code is posted in GitHub (really messy stuff, I just created a repo to have a versioning system while updating/cleaning it) and the relevant code is here in case anyone wants to take a peek.

Thanks for the debug build qyot27, I'll post any results here if I manage to have any!
gpower2 is offline  
Old 29th December 2019, 23:28   #5020  |  Link
gpower2
gMKVExtractGUI author
 
gpower2's Avatar
 
Join Date: Aug 2003
Location: Greece / Thessaloniki
Posts: 251
Quote:
Originally Posted by Groucho2004 View Post
Some info on the old 'delete' for AVS 2.5:
https://forum.doom9.org/showthread.p...te#post1631151

And the benefit of the newer DeleteScriptEnvironment():
https://forum.doom9.org/showthread.p...te#post1512400

When AVSMeter still used the 2.5 interface, I used this to destroy IScriptEnvironment (which was a tip IanB gave me and worked fine):

AVS_env->~IScriptEnvironment();
AVS_env = 0;
Wow, crazy stuff! Thanks for the tip Groucho, I think that might solve my problem permanently!
gpower2 is offline  
Closed Thread

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:58.


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