View Full Version : AVISynth and NeatVideo black frame problem
jriker1
9th December 2014, 15:20
I have been encoding some VHS content into digital and doing some cleanup, first with AVISynth, and second with NeatVideo in Premiere. I have modified my process to do the NeatVideo cleanup in AVISynth using the VirtualDub NeatVideo filter. Content is now progressive so reason for the way I formulated the first line now:
ConverttoRGB32(matrix="rec601",interlaced=false)
LoadVirtualDubPlugin("Z:\virtualdub\plugins32\NeatVideo3.vdf", "NeatVideo", 1)
NeatVideo("D:\Conversion\Cat\neatvideo.dnp", "D:\Conversion\Cat\neatvideo.nfp", "0.0","1","0","0")
I use the Trim(0,64322) like command to break the avi into multiple segments so I can encode multiple parts at a time. I find the MT version of AVISynth is buggy so use separate AVS files to emulate a similar process. When I add the above neatvideo command in, the first frame of each resulting AVI file is black. Not sure if I pull that black frame out on each one if everything will line up and audio will be good or not. Does anyone know why neatvideo is adding a black frame into every output I do when running thru Virtualdub?
Thanks.
JR
StainlessS
9th December 2014, 15:35
No idea about NeatVideo, but,
# MakeMultiPartScripts.avs
#######
PARTS=4 # Edit as appropriate
#######
myName="MakeMultiPartScripts: "
Assert(PARTS>1,RT_String("MakeMultiPartScripts.avs: PARTS MUST be greater than 1 (%d)",PARTS))
IsAvsPlus=(FindStr(VersionString, "AviSynth+")>0 || FindStr(VersionString, " Neo")>0)
HasGScript=RT_FunctionExist("GScript")
Assert(IsAvsPlus || HasGScript,RT_String("%sNeed either GScript or AVS+",myName))
#######
FSEL_TITLE="Select AVS files"
FSEL_DIR="."
FSEL_FILT="AVS files|*.AVS"
FSEL_MULTI=True
FILE_LIST = RT_FSelOpen(title=FSEL_TITLE,dir=FSEL_DIR,filt=FSEL_FILT,multi=FSEL_MULTI)
Assert(!(FILE_LIST.IsInt && FILE_LIST==0),RT_String("%sUser Cancelled in FileSelector - No action taken",myName))
Assert(FILE_LIST.IsString,RT_String("%sRT_FSelOpen Error=%s",myName,String(FILE_LIST)))
SCRIPT_TMPT = """
PART = %d
PARTS = %d
Import("%s")
FC = FrameCount
Start = ((part==0 ) ? -1 : part * (FC-1) / PARTS) + 1
End = ((part==PARTS-1) ? FC-1 : (part+1) * (FC-1) / PARTS)
End = (End == Start) ? -1 : End
Trim(Start,End)
# Subtitle("Trim("+String(Start)+","+String(End)+")")
Return Last
"""
GS="""
NLINES = RT_TxtQueryLines(FILE_LIST)
for(i=0,NLINES-1) {
PARTSNAME = RT_TxtGetLine(FILE_LIST,i)
for(part=0,PARTS-1) {
PartName = RT_String("%s_PART_%d.avs",PARTSNAME,part+1)
ScriptInst=RT_String(SCRIPT_TMPT,part,PARTS,PARTSNAME)
RT_WriteFile(PartName,"%s",ScriptInst)
}
}
"""
HasGScript ? GScript(GS) : Eval(GS) # Use GSCript if installed (loaded plugs override builtin)
MessageClip(RT_String("ALL DONE, Processed %d avs files of %d parts each",NLINES,PARTS))
EDITED:
above will remove your problem. Think I actually wrote above for you not so long ago.
EDIT: Run above script and select your avs file, will generate 4 (user configured) resultant scripts.
There should only be a single black frame at start which you can remove in the original source script.
Requires RT_Stats
http://forum.doom9.org/showthread.php?t=165479&highlight=rt_Stats
EDIT: and GScript: http://forum.doom9.org/showthread.php?t=147846&highlight=gscript
EDIT: eg
Avisource(...)
ConverttoRGB32(matrix="rec601",interlaced=false)
LoadVirtualDubPlugin("Z:\virtualdub\plugins32\NeatVideo3.vdf", "NeatVideo", 1)
NeatVideo("D:\Conversion\Cat\neatvideo.dnp", "D:\Conversion\Cat\neatvideo.nfp", "0.0","1","0","0")
Trim(1,0) # Remove BLACK frame
EDIT: DONT do above in AVSPMod (MakeMultiPartScripts.avs), it messes with the file selector (the only reason I will not use AVSPMod)
and screws up the script. Use any media player (that will play avs, ie not VLC) or VDub (right click, 'Open With').
EDIT: For the last part #4 of 4 parts generates this:- Test.avs_PART_4.avs
PART = 3 # This is zero relative ie 4th part
PARTS = 4
Import("D:\MakeMultiPartScripts\Test.avs")
FC = FrameCount
Start = ((part==0 ) ? -1 : part * (FC-1) / PARTS) + 1
End = ((part==PARTS-1) ? FC-1 : (part+1) * (FC-1) / PARTS)
End = (End == Start) ? -1 : End
Trim(Start,End)
# Subtitle("Trim("+String(Start)+","+String(End)+")")
Return Last
jriker1
9th December 2014, 16:06
Thanks StainlessS, let me take a look at that again for the script creation part. Not sure how to trim it off in the script as I don't think it's happening until Virtualdub opens the file and interprets the output. First thing I'm trying to understand mathematically is it adding extra frames or am I loosing something?
So my statement is: Trim(0,64322)
I guess if frame 0 counts? That would be 64323 frames.
My deinterlacer is double framing so is now 59.97 so would have 128646 frames
According to MediaInfo the resulting file is 128646 frames. So looks like all the frames are there but for some reason the first one in every resulting AVI file is black. So if Frame 0 doesn't count then I seem to have two extra resulting frames at the beginning as if you don't count frame 0 then should have 128644 frames in the final output.
I guess another example of the count would be if you trim like: Trim(64323,128645)
Is that 64322 frames or 64323 or 64324? In the 64323,128645 example above my resulting avi is 128646 frames(doubled)
So if NeatVideo is somehow adding an extra frame at the beginning not sure how to remove it if it technically doesn't exist.
JR
StainlessS
9th December 2014, 16:10
I've done it for you, see edits (Assuming you want to trim off only the black frame, Trim(1,0) trims off only 1st frame).
Just run the MakeMultiPartScripts.avs.
poisondeathray
9th December 2014, 16:18
Why are you getting black frames in the first place ?
What video formats, and compression are you using?
How are you loading into avisynth (source filter) ?
How is content now "progressive" ? Did you deinterlace, if so how ?
StainlessS
9th December 2014, 16:20
How are you loading into avisynth (source filter) ?
All good questions, especially the 2nd from last one :)
jriker1, you need to add the Trim(1,0) to the FULL source script (@ the very END).
jriker1
9th December 2014, 16:28
Thanks. Saw the trim statement and seems to work, I'm as curious as poisondeathray what's going on here in the first place. The source file is AVI and YUY2 Lagarith encoded. The resulting file after AVISynth/Virtualdub is also Lagarith YUY2 encoded in the end. I'm using QTGMC to deinterlace as this footage will end up an MP4 on my computer and WMP doesn't deal with interlaced material. Here is the script:
AVISource("Cat.avi")
Trim(0,64322)
Cnr2("xoo",4,2,64)
DePulse(h=100, l=0, d=15, debug=false)
DePulse(h=100, l=0, d=10, debug=false)
DePulse(h=70, l=0, d=15, debug=false)
DePulse(h=0, l=255, d=5, debug=false)
AssumeTFF()
QTGMC(Preset="Slower", SourceMatch=3, Lossless=2, MatchEnhance=0.75, TR2=1, Sharpness=0.1)
ConvertToYV12 # script below this line requires YV12
MergeChroma(aWarpSharp(depth=10), aWarpSharp(depth=20))
Overlay(last, ColorYUV(off_y=-8, off_u=9, off_v=-2), 0, 0, GreyScale(last).ColorYUV(cont_y=30))
Stab()
Levels(0,1.000,250,2,255,true)
Crop(0,0,-4,-4) # use both lines
ConverttoRGB32(matrix="rec601",interlaced=false)
LoadVirtualDubPlugin("Z:\virtualdub\plugins32\NeatVideo3.vdf", "NeatVideo", 1)
NeatVideo("D:\Conversion\Cat\neatvideo.dnp", "D:\Conversion\Cat\neatvideo.nfp", "0.0","1","0","0")
ConvertToYUY2
I load this into VirtualDub, set full processing mode, set Compression to Lagarith YUY2 and set output color depth to YUY2 as it defaults to 24 bit RGB. AVS file is in the same folder as the source video. So is the NeatVideo profiles but I fully qualify those anyway.
If I remove the NeatVideo piece the blank frame goes away.
JR
poisondeathray
9th December 2014, 16:31
Ok thanks, I was just going to say remove NeatVideo and check the frame count . I don't know what's going on , sorry . Carry on with StainlessS :)
jriker1
9th December 2014, 16:56
Ok thanks, I was just going to say remove NeatVideo and check the frame count . I don't know what's going on , sorry . Carry on with StainlessS :)
Are there any tools like MediaInfo that will give you a frame count based on an AVS file? Guessing no, tried MediaInfo and GSpot.
Here's the part that concerns me. If I leave NeatVideo in, and open the avs in VDub I show a timeline from frame 0 thru 128646. First frame is blank. If I take the entire RGB thru NeatVideo block out, I see the first frame, but VDub still says frame 0 thru 128646. I did restart VDub between mods to the script.
JR
StainlessS
9th December 2014, 17:10
@ end of Script,
Info
but will likely not show on your 1st frame if your first frame aint there.
lansing
9th December 2014, 17:28
I used Neatvideo too, iirc that has to do with your temporal threshold, if you set it to 1, then it will offset by one frame, 2 by two frames etc.
Just simply trim it off will do.
jriker1
9th December 2014, 18:08
I used Neatvideo too, iirc that has to do with your temporal threshold, if you set it to 1, then it will offset by one frame, 2 by two frames etc.
Just simply trim it off will do.
What concerns me about that is if I break my AVI into 6 separate segments and run them individually thru, I think the first frame will be removed on each file and have a slight hiccup when merged back together. I could be wrong, but doesn't seem like it's adding an extra frame in, but actually blanking out the frame for some reason. So what you suggest is probably fine if I encode the entire file from start to finish, but if I do as I'm doing thinking there will be slight gaps in those spliced areas.
Depending on what nets out here, I may have to run my script in it's entirety minus the NeatVideo part, merge the segments together, and then run the resulting AVI file thru a second time just with the NeatVideo part. If I do this all with Lagarith shouldn't be any loss for multi passes. Just want to utilize as much of my CPU as possible so I'm not encoding for a week. Right now a 3 hour video takes about 14 hours to run thru 6 separate segments at the same time.
JR
StainlessS
9th December 2014, 18:46
A very good way to find out would be to try it, I think you will find that you are worrying too much. :)
EDIT: Pick one of the output _PART_x.avs scripts and just look at the first frame in VDub.
jriker1
9th December 2014, 22:58
I think in testing it's OK but since it doesn't make sense still unsure. Rather just create a noise profile in vdub and use the filter thru there. I did email Vlad from NeatVideo but from what I've seen in past responses on the forums he feels it's a bug in avisynth since it works fine thru VirtualDub. Something about AVISynth not honoring the temporal setting.
JR
StainlessS
9th December 2014, 23:11
Then I guess you've given the solution to your own thread.
jriker1
9th December 2014, 23:34
Then I guess you've given the solution to your own thread.
Normally I'd delete the one frame and be done with it, however the fact that the frame count is the same with or without NeatVideo and the first frame is blank is bothering me. And why it wouldn't be noticeable is odd in itself unless removing a single frame has no human visible impact.
JR
StainlessS
9th December 2014, 23:52
Its probably something to do with it trying to access the frame before frame zero although I think Avisynth should/does convert that to an
access to frame zero again. Whatever the problem, it really does not matter for a single frame. The VD filter is being used on the full script only
(no matter which PART.avs is in use), the trim only returns the required frames to the client program/encoder or whatever and the black frame
has already gone, it will not produce further black frames at the beginning of the PART.avs files.
EDIT: It might be interesting to use ShowFrameNumber() before the VD filter and see if frames stay in original position.
jriker1
10th December 2014, 00:31
Looks like the script is having a minor issue. Tried a one line script loading c:\temp\test.avs. Looks like the slashes are being looked at as tab characters. Tried doing a double \\ but didn't find the file that way:
AVISOURCE("c:\temp\scene0001.avi")
Output was:
PART = 0
PARTS = 4
Import("C: emp est.avs")
FC = FrameCount
Start = ((part==0 ) ? -1 : part * (FC-1) / PARTS) + 1
End = ((part==PARTS-1) ? FC-1 : (part+1) * (FC-1) / PARTS)
End = (End == Start) ? -1 : End
Trim(Start,End)
# Subtitle("Trim("+String(Start)+","+String(End)+")")
Return Last
Import command looks mangled.
JR
StainlessS
10th December 2014, 00:37
OK, but what was the name of the source script avs ?
(maybe Doom9 made some alterations, perhaps BLUE code did not help)
StainlessS
10th December 2014, 00:46
OK, found the problem, am fixing now.
jriker1
10th December 2014, 00:54
So far heard back from NeatVideo asking if it works fine in VDub so expecting not going to have a resolution there but we shall see as I mentioned that I'd at least like to know what's the impact of this since it is doing it. I guess even though they list the feature in their user manual, doesn't mean it's within their support space.
JR
StainlessS
10th December 2014, 01:08
Sorry for the bother, hope this works OK.
# MakeMultiPartScripts.avs
#######
PARTS=4 # Edit as appropriate
#######
myName="MakeMultiPartScripts: "
Assert(PARTS>1,RT_String("MakeMultiPartScripts.avs: PARTS MUST be greater than 1 (%d)",PARTS))
IsAvsPlus=(FindStr(VersionString, "AviSynth+")>0 || FindStr(VersionString, " Neo")>0)
HasGScript=RT_FunctionExist("GScript")
Assert(IsAvsPlus || HasGScript,RT_String("%sNeed either GScript or AVS+",myName))
#######
FSEL_TITLE="Select AVS files"
FSEL_DIR="."
FSEL_FILT="AVS files|*.AVS"
FSEL_MULTI=True
FILE_LIST = RT_FSelOpen(title=FSEL_TITLE,dir=FSEL_DIR,filt=FSEL_FILT,multi=FSEL_MULTI)
Assert(!(FILE_LIST.IsInt && FILE_LIST==0),RT_String("%sUser Cancelled in FileSelector - No action taken",myName))
Assert(FILE_LIST.IsString,RT_String("%sRT_FSelOpen Error=%s",myName,String(FILE_LIST)))
SCRIPT_TMPT = """
PART = %d
PARTS = %d
Import("%s")
FC = FrameCount
Start = ((part==0 ) ? -1 : part * (FC-1) / PARTS) + 1
End = ((part==PARTS-1) ? FC-1 : (part+1) * (FC-1) / PARTS)
End = (End == Start) ? -1 : End
Trim(Start,End)
# Subtitle("Trim("+String(Start)+","+String(End)+")")
Return Last
"""
GS="""
NLINES = RT_TxtQueryLines(FILE_LIST)
for(i=0,NLINES-1) {
PARTSNAME = RT_TxtGetLine(FILE_LIST,i)
for(part=0,PARTS-1) {
PartName = RT_String("%s_PART_%d.avs",PARTSNAME,part+1)
ScriptInst=RT_String(SCRIPT_TMPT,part,PARTS,PARTSNAME)
RT_WriteFile(PartName,"%s",ScriptInst)
}
}
"""
HasGScript ? GScript(GS) : Eval(GS) # Use GSCript if installed (loaded plugs override builtin)
MessageClip(RT_String("ALL DONE, Processed %d avs files of %d parts each",NLINES,PARTS))
EDIT: Problem was I had missed out the format string "%s" below and it was treating ScriptInst as format string ie '\' interpreted as escape
characters rather than pure data without escapes, so eg '\t' interpreted as TAB.
RT_WriteFile(PartName,"%s",ScriptInst) # was equivalent to RT_WriteFile(PartName,ScriptInst)
fvisagie
10th December 2014, 08:00
Normally I'd delete the one frame and be done with it, however the fact that the frame count is the same with or without NeatVideo and the first frame is blank is bothering me.
If you want to stick with NeatVideo in Avisynth and find no way to prevent the initial black frame, perhaps you could see whether adding a duplicate of the first frame to the start of each input clip helps. It will presumably turn black, and trimming that off afterwards should leave you with the original starting frame and original frame count (assuming everything that's been said about NeatVideo not changing the frame count being correct).
StainlessS
10th December 2014, 20:35
Arh good, a bit of common sense, sounds good to me :)
johnmeyer
11th December 2014, 05:06
Nice workaround, fvisagie.
StainlessS
11th December 2014, 17:43
@jriker1
I thought I had a problem (bug) with RT_FSelOpen due to the previous MakeMultiPartScript.avs but turns out not a bug.
I was using Media Player Classic - Home Cinema to open, and if I clicked Cancel then it would immediately bring up another File Selector.
Thought was bug in RT_FSelOpen but seems that MPC-HC will immediately retry because of Assert() alert (due to user Cancel) without any
frames being delivered from script. Does not happen with other players and seems that MPC-HC is just trying to be helpful in re-starting what
it thinks is glitch in the system. Anyway, just pointing it out if you use MPC-HC (just updated to latest stable and still does it), but does not
happen in other players that I've tried.
jriker1
18th December 2014, 22:29
If you want to stick with NeatVideo in Avisynth and find no way to prevent the initial black frame, perhaps you could see whether adding a duplicate of the first frame to the start of each input clip helps. It will presumably turn black, and trimming that off afterwards should leave you with the original starting frame and original frame count (assuming everything that's been said about NeatVideo not changing the frame count being correct).
Thanks fvisagie. Agree it's a good workaround. Been talking with Vlad about this at neatvideo but he keeps waiting for someone (presuming on the AVISynth side), to get back to him. Not sure I'll ever get an understanding of the cause. How would that work? Something like this?
AVISource("Video.avi")
clipOne = Trim(0, 1)
clipTwo = Trim(0, 0)
AlignedSplice(clipOne, clipTwo)
OR
AVISource("Video.avi")
edited_video = Trim(0,1) ++ Trim(0,0)
Right now I have been adding in NeatVideo straight thru Virtualdub. Which brings up a question. NeatVideo in AVISynth, can fast recompress. With NeatVideo loaded as a plugin in Virtualdub, have to select full processing mode. Do we think one way is faster than another?
Thanks.
JR
StainlessS
18th December 2014, 22:55
Trim(0,1) would trim two frames, frame 0 and frame 1.
To trim only a single frame use Trim(0,-1), the -1 means 1 frame, starting at frame 0. Trim(0,0) would not work (for 1 frame) as it means
from frame 0 to end of clip.
What you want is something like this
AVISource("Video.avi")
Trim(0,-1) ++ last
or better
AVISource("Video.avi")
Trim(0,-1) ++ Trim(0,0) # here trim(0,0) ensures that the Last clip has audio trimmed exactly to each end,
# padding with silence if necessary.
EDIT: ++ same as AlignedSplice.
jriker1
18th December 2014, 23:07
Got it thanks.
Is it documented somewhere how the negative logic works on Trim? I've seen references to Trim(0,-10000). What is that compared to Trim(0,10000)
JR
StainlessS
18th December 2014, 23:20
Trim(0,10000) # trim frames 0 to frame 10,000 # 10,001 frames, 0 and 10,000 inclusive
Trim(0,-10000) # trim frames 0 to frame 9,999 # ie 10,000 frames
http://avisynth.nl/index.php/Trim
EDIT: Avisynth does come with Docs, but perhaps more convenient as a CHM (compressed html help file).
See MediaFire in sig below this post, in DATA directory for the Avisynth Docs as CHM file together with
the developer SDK docs. Can eg copy into Avisynth folder, and create a shortcut to it in your Program
shortcuts directory. On XP, right click START button, Select "Explore All Users", navigate to Programs/Avisynth/
or wherever on your system and create a short cut and point it at the chm file. Right Click Properties and give it a Hot-Key
combination, I use CTRL-ALT-H. Quite convenient especially if on a laptop. Is also searchable.
EDIT: There are two versions, with SDK docs for v2.6 and without for v2.58. The v2.6 one is better choice even for v2.58.
EDIT: Hot-Key may not work until reboot.
EDIT: And here the thread: http://forum.doom9.org/showthread.php?t=152781&highlight=chm+file
fvisagie
19th December 2014, 09:42
NeatVideo in AVISynth, can fast recompress. With NeatVideo loaded as a plugin in Virtualdub, have to select full processing mode. Do we think one way is faster than another?
If you're using the Virtualdub definition of fast recompress, that is something that cannot be done with Avisynth involved. Fast recompress refers to direct decompressor-compressor linking. It transports video in actual compressed format such as H.264, HuffYUV, Lagarith etc., and excludes raw video (processed by Windows colourspace 'codecs' such as Intel Indeo or Helix). Avisynth always fully decodes video to raw format, which in concept is similar to VirtualDub's full processing mode.
Most people report that a given plugin executes slower in Avisynth than in VirtualDub, presumably due to the interface translation needed in Avisynth.
In theory, therefore, the equivalent process may very well be slower in Avisynth than in VirtualDub. However, you can choose to ignore all this and see for yourself :).
StainlessS
19th December 2014, 14:14
JR, if you have to convert to RGB, then would be better to do RGB particular processing together to avoid degradation with each accompanying
colorspace change. It probably does not matter much if colorspace change from RGB to YUV is done in Avisynth (with Fast Recompress to VD)
or Vdub compression, so long as both done without additional colorspace changes.
fvisagie, I think you misinterpret what JR was meaning.
EDIT: And what you described was actually Direct Stream Copy not Fast Re-compress which enters into negotiation with codec
to decide upon which colorspace conversions if any, are necessary. So eg YUV to HuffYUV YUY2 mode can skip conversion to RGB
and additional conversion to YUY2.
fvisagie
19th December 2014, 19:16
EDIT: And what you described was actually Direct Stream Copy not Fast Re-compress which enters into negotiation with codec
to decide upon which colorspace conversions if any, are necessary. So eg YUV to HuffYUV YUY2 mode can skip conversion to RGB
and additional conversion to YUY2.
Correct, my description applies to Direct stream copy, apologies.
However, as I see it the problem statement remains, due to the fact that NeatVideo - being a VirtualDub plugin - would still require conversion to RGB32 (unless input already happens to be in RGB32). In other words, NeatVideo's processing would likely necessitate a colourspace conversion, which even when done in Avisynth effectively translates to VirtualDub's Full processing mode.
StainlessS
19th December 2014, 22:21
Yes, absolutely. Jr though does some kind of analogue rgb processing, I was just saying that it might best be done together if possible.
(EDIT: I still dont know what Neat Video actually does, but does not really matter).
No apologies for anything are warranted, we all make mistakes and hope that you don't mind too much if they may be pointed out.
I would expect no less from from you if situation was reversed.
Have a nice one and try not to get stuck in all of that snow that you probably have in SA.
(EDIT: OK, maybe not so much snow usually, but by god what monster hail stones you can have)
fvisagie
20th December 2014, 09:08
try not to get stuck in all of that snow that you probably have in SA.
(EDIT: OK, maybe not so much snow usually
Was just wondering whatever could have given you that idea. Any snow at this time of year must have been carefully imported at great personal risk.
StainlessS
20th December 2014, 09:43
OK, I perhaps should have added a Smiley.
fvisagie
20th December 2014, 10:01
My smiley was also implied, hope you spotted it.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.