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.

Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 27th October 2011, 00:20   #81  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
Also to point out that Border Detection 0.3 needs some more work; it seems it should be scaled wider to show more of the correlation surface (it's for testing only).
jmac698 is offline   Reply With Quote
Old 27th October 2011, 11:15   #82  |  Link
sven_x
Registered User
 
Join Date: Oct 2011
Location: Germany
Posts: 39
I found that the input for Corr2D CCF should have a least an area of 100 px height and 200 px width (better 400 px). Then we could cut the line with the right half of the CCF from the resulting output area. With smaller resolutions the output pixels of ccf are scaled down which results in avaraging with their black neighbor pixels.
It is better to use the right side because the left side is terminated at (width/4) px.

When using the output of CCF it better has to be
  • blurred (perhaps - please look at the last example in my Part 2 image with strong noise superimposed on input - this gives some noise on the ccf output)
  • converted to black/white using a thresh to get a sharp length of CCF
  • subtracting the number of pixels that the auto correlation of the border model produces, because in the case when the real border is exactly at the same position as the border model (i.e. offset = 0) the output reduces to the autocorrelation function of the border (and not to zero)
    (To acchieve a similar effect perhaps the left side of the CCF could be automaticly subtracted from the right side using a kind of mirroring at x=width/4.)
  • set the border model to a minal number of pixels (say 2 px) to get offset values in one direction only

When the input is scaled up enough we do not need convert exactly the number of pixels of the output function to get an offset value, because 11 and 14 px give the same result (3) when 5 pixels in CCF correspond to 1 px input (before it was inflated).
sven_x is offline   Reply With Quote
Old 27th October 2011, 13:34   #83  |  Link
ronnylov
Registered User
 
Join Date: Feb 2002
Location: Borås, Sweden
Posts: 492
Quote:
Originally Posted by jmac698 View Post
How to get the capture
The capture section has moved to "How to Capture with HSYNC" in the capture forum. That topic is unrelated to script usage.
http://forum.doom9.org/showthread.php?p=153072
[/code]
This link is wrong? They talk about SVCD creation in a 9 year old thread.

Should be: http://forum.doom9.org/showthread.php?t=162832
__________________
Ronny
ronnylov is offline   Reply With Quote
Old 27th October 2011, 13:58   #84  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
thanks, fixed
jmac698 is offline   Reply With Quote
Old 27th October 2011, 19:21   #85  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
First test of my "perfect TBC" test signal, I have a number which is proportional to the shift in high accuracy. This was a test of an actual VHS. It's just the detection value, no dejitter yet. I also have to scale the number into actual pixels first. At least it looks like it's going to work. Oh, and that 'head switching noise' that everyone crops? No need to, I can recover quite a bit of it.
jmac698 is offline   Reply With Quote
Old 28th October 2011, 23:24   #86  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
Results of my jitter analysis. Good and bad. My test shows jitter is +-.25 in left border and +-.5 in right border. This is with a modern card which probably has an Ultralock type feature. I hardly need TBC for this tape.
The samples of jitter I've provided before were from an older capture card, and a worn VHS which possibly had macrovision, that could explain why it's so much worse.
I need to prepare more tests with a VHS in LP mode, with a stretched tape, or with a copy of a copy to get some real jitter.
jmac698 is offline   Reply With Quote
Old 30th October 2011, 13:28   #87  |  Link
Perepandel
Registered User
 
Join Date: Sep 2011
Posts: 37
Hi! I finally tried to take a look at this. Have a hardware TBCd capture that, even that, has a couple of seconds with jitter that it seem it wasn't able to recover (or maybe it came from a previous generetion or whatever). I've haven't been able to make virtualdub vhsrest2.vdf plugin work (it makes it crash, nor through avisynth's LoadVirtualDubPlugin), and with DeJitter.dll I get far more jitter than in the original file.

The problem is I am not able to run this script. I've been upgraded to Avisynth 2.6 alpha, downloaded and included the required plugins with the following lines:
LoadPlugin("mt_masktools-26.dll")
LoadPlugin("GRunT.dll")
LoadPlugin("minmax.dll")
and loaded the video file, but I always get an "I don't know what 'thresh' means ([ScriptClip], line 4)" error.

I'm suspecting something is not getting loaded. Any hints??
Perepandel is offline   Reply With Quote
Old 30th October 2011, 14:31   #88  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,442
Quote:
Originally Posted by Perepandel View Post
I always get an "I don't know what 'thresh' means ([ScriptClip], line 4)" error.
Perhaps you are running an older version of the script.
Check your script is the same as in the first post.
Before the call to ScriptClip, there should be this line:
thresh=int(findthresh(src))+3
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 30th October 2011, 15:19   #89  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
It's true, an "auto" thresh feature was added in the last .52 version.
jmac698 is offline   Reply With Quote
Old 30th October 2011, 17:58   #90  |  Link
sven_x
Registered User
 
Join Date: Oct 2011
Location: Germany
Posts: 39
Cross correlation between a real video border and an edge model

This is part 3 of posting 69 and 82.

Basing on Border Detection 0.3 by jmac698 (same thread, here) I have modified the script that calculates cross correlation between the border of a real video and an edge model, whose parameters can be adjusted (edge blur, white level and number of black pixels of the edge).

You are welcome to do your own tests.

PHP Code:
#AvsP script

#loadplugin("J:\plugins\Gscript.dll")  # For y=0 ... loop
loadplugin("J:\plugins\GRunT.dll")  # For use of Runtime functions inside user functions
loadplugin("J:\plugins\Corr2D.dll")  
loadplugin("J:\plugins\VariableBlur.dll")   
loadplugin("J:\plugins\NNEDI3.dll")  

#Border Detection Sven_X Corr2D version basing on 0.3 by jmac698 
# see http://forum.doom9.org/showthread.php?p=1533363#post1533363
# A function to show cross correlation between the left border of a video and an edge model that can be tweaked
# Requirements:  corr2d  http://avisynth.org/vcmohan/Corr2D/Corr2D.html
# infact we do neet a Corr1D only, which would be much faster, but we have none...
# GRunT (NNEDI3, Variablelbur in some cases for the edge model)

SetMemoryMax(800)  #set this to 1/3 of the available memory  

[<separator="Clamping">]
clamp2=[<"Input clamping"1625543>]
global 
clamp=[<"cff out clamping"1625527>]
mag2 = [<"Magnification"181>]

[<
separator="Edge model">]
bwidth=[<"Black px"2162>]
bblur=[<"Edge blur (0)"051>]
bgrey=[<"Edge white (255)"1625543>]

Directshowsource("J:\test\test.avi")
converttoyuy2
#nnedi3(-2) #deinterlace, double frame rate, to view a non interlaced version 
#return last #view input video

border=32#32
crop(0,0,-last.width+border,0)
#crop(0,0,-0,last.height*1/4)  #1/2 for test purposes only, faster, 
levels(0,1,clamp2,0,clamp2)  #clamp bright areas 
edge=makeedge(last,bwidth).converttoYV12.averageblur(bblur).converttoYUY2.levels(0,1,255,0,bgrey
#make an edge model with minium edge at x=2 px
#return edge
corrbyline3(lastedge# input, reference
pointresize(last.width*mag2/2,last.height*mag2/2#Magnify output


function SplitLines2(clip cint n) {#duplicates then crops each copy in a different spot
    
Assert(c.height%== 0"Clip height not a multiple of 'n'")
    
Assert(!(c.IsYV12() && n%2==1), "'n' must be even for YV12 clips")
    
nStrips c.height/n   #= 576 lines PAL
    
c.ChangeFPS(nStrips*Framerate(c)).AssumeFPS(c# Repeat each frame 'nStrips' times
    
BlankClip(cheight=n# template for ScriptClip result
    
GScriptClip("c.Crop(0, (current_frame%nStrips-1)*n, 0, n)"args="c, nStrips, n"#(left, top,width,heigth)
}


function 
MergeLines(clip cint n) {MergeLines2(c,n,n)}

function 
MergeLines2(clip cint n,int i) {
  
i<c.SelectEvery(n) : stackvertical(MergeLines2(c,n,i-1),c.SelectEvery(ni))
}


function 
makeedge(clip vint x){
    
#Based on the properties of v, make an edge of x black + white pixels
    
x=x/2*2
    v
    blk
=blankclip(lastwidth=xcolor_yuv=$108080)
    
wht=blankclip(lastwidth=last.width-xcolor_yuv=$EB8080)
    
stackhorizontal(blkwht)
}

function 
corrbyline3(clip v1clip v2){
    
#Correlate two videos, line by line, and return the horizontal cross correlation. 
    # when input 1 and 2 are edges (a square waveform, then the length of the resulting ccf correponds to offset between both edges
    
scale=2
    v1
    pointresize
(v1.widthv1.height*scale#scale line height, for yv12 a line has to have at least 2 px height
    
h=last.height #PAL 2x576 lines = 1152
    
splitlines2(scale)  #make n frames with one line (height=scale) from a frame
    
v2l=v2.crop(0,0,0,scale)
    
interleave(lastv2l)
    
pointresize(last400100#to enlarge output of CCF, at least 200x100
   
corr=corr2d (last)
   
Crop(corr,10024, -0, -72).pointresize(corr.width,corr.height*4#400x400
   
Crop(0126, -2002#to get the interesting part of CCF (x=0...)  2 px height
   
selectevery(2,1#drop cff output of every odd line
   
mergelines(h/2)   #compose a frame from h/2 frames that contain a single line
   
v2=pointresize(v1,v1.width*2,v1.height*2)
   
stackhorizontal(v2,last,last.levels(clamp-2,1,clamp,0,255)) #clamps grey levels of ccf output above clamp to white
}


function 
corrbyline2(clip v1clip v2){
    
#Correlate one video line by line, and return the cross correlation between two succeeding lines
    
scale=2
    v1
    pointresize
(last.widthlast.height*scale#scale line height, for yv12 a line has to have at least 2 px height
    
h=last.height #PAL 2x576 lines = 1152
   
splitlines2(scale)  #make n frames with one line (height=scale) from a frame
    
pointresize(last400100#to enlarge output of CCF, at least 200x100
   
corr=corr2d (last)
   
Crop(corr,5024, -0, -72).pointresize(corr.width,corr.height*4#400x400
   
Crop(0126, -3002#to get the interesting part of CCF (x=0...)  2 px height
   
mergelines(h/2)   #compose a frame from h/2 frames that contain a single line
   
v2=pointresize(v1,v1.width*2,v1.height*2)
   
stackhorizontal(v2,last,last.levels(clamp-2,1,clamp,0,255)) #clamps grey levels in Cff output above clamp to white



Here are a few first results.







It can be seen that the width of the cross correlation reacts on the luma of the input video. Bright image parts produce a longer CCF output. The effect is smaller when input contrast is lowered (which is done in this version by clamping all luma values above a certain threshold).

By looking at these pictures I am not so convinced anymore that cross correlation can provide a good border detection.

Last edited by sven_x; 31st October 2011 at 12:06.
sven_x is offline   Reply With Quote
Old 30th October 2011, 22:59   #91  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
sven,
Great work and analysis. I have a simple suggestion, just change the 'white' color of the edge model into the averageluma of the video, this would eliminate the 'border bias' you are getting.
If I analyzed the actual correlation calculations, I'm sure I could understand why it's doing this anyhow.
Does your script work on two model edges correctly?
What about using a pure threshold, but then using salt&pepper removal to clear the noise?
It seems your borders are quite good, there just has to be some way to detect them. Did you try the edge masks built into masktools?
jmac698 is offline   Reply With Quote
Old 1st November 2011, 11:58   #92  |  Link
Perepandel
Registered User
 
Join Date: Sep 2011
Posts: 37
Quote:
Originally Posted by Gavino View Post
Perhaps you are running an older version of the script.
Check your script is the same as in the first post.
Before the call to ScriptClip, there should be this line:
thresh=int(findthresh(src))+3
Yeah, I'm using that version, dated 27th october... I also tried to put the "int(findthresh(src))+3" instead of the "thresh" variable inside the ScriptClip part to try to isolate the problem but no luck... I guess I'm using some old/different version of some of the plugins...

By the way, I just wanted to test how the alignment was working with one of my already-captured-without-sync captures...
Perepandel is offline   Reply With Quote
Old 1st November 2011, 13:46   #93  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
Oh, make sure you have gscript installed.
http://forum.doom9.org/showthread.php?t=147846
Can also set thresh manually, thresh=20 (for example) inside the scriptclip.

Gscript is sort of dangerous to have around for development, it silently affects variable scope I believe making me not realize I need it in a script. I mean something will just work for me when a plain avisynth would give an error.
jmac698 is offline   Reply With Quote
Old 1st November 2011, 14:44   #94  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,442
Quote:
Originally Posted by jmac698 View Post
Oh, make sure you have gscript installed.
http://forum.doom9.org/showthread.php?t=147846
You mean GRunT, not GScript (although GScript is also needed later in your script).

Quote:
Gscript is sort of dangerous to have around for development, it silently affects variable scope I believe making me not realize I need it in a script. I mean something will just work for me when a plain avisynth would give an error.
Again I assume you mean GRunT, as GScript does not affect variable scope.
The fact that "something will just work" is what it is intended to achieve, so is for the most part an advantage(!), but I understand what you mean in that it is harder to realise you need it for a given script. This is because once installed it extends the standard run-time environment and will still be used if you call 'ScriptClip' instead of 'GScriptClip' - it has to be this way as all run-time filters must work the same way for it to function properly.

Perepandel, are you saying your script is like this:
Code:
src=AVISource("...")
thresh=int(findthresh(src))+3
ScriptClip(src, """
#Mark video edges
converttoyv12
m=mt_binarize(thresh)
#Line up video
findpos_h(m, searchwidth=22)
alignbyluma(src,last)
""")
...
and you get "I don't know what thresh means" inside ScriptClip?
That should work whether or not you are using GRunT. The only exception would be if you have put this code inside a function (or if you have also configured GRunT to run each run-time script in a separate scope, by calling GRTConfig(local=true)), in which case you would have to add args="src, thresh" to the ScriptClip call (or simply make src and thresh global).
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 1st November 2011 at 15:06. Reason: typos and clarification
Gavino is offline   Reply With Quote
Old 1st November 2011, 20:49   #95  |  Link
Perepandel
Registered User
 
Join Date: Sep 2011
Posts: 37
Quote:
Originally Posted by jmac698 View Post
Oh, make sure you have gscript installed.
http://forum.doom9.org/showthread.php?t=147846
It was GScript! After I installed it, the script worked! Thanks a lot! I need to make further tests now
Perepandel is offline   Reply With Quote
Old 1st November 2011, 22:03   #96  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
I've updated the instructions and requirements.
Also have my perfect TBC working today
jmac698 is offline   Reply With Quote
Old 1st November 2011, 22:04   #97  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,442
Quote:
Originally Posted by Perepandel View Post
It was GScript! After I installed it, the script worked!
Certainly, GScript is required, but without it you should get the error 'there is no function named "GScript"', not a message about 'thresh'. Or is this actually what you did get?
(I need to understand the details just in case there is something strange happening with GRunT.)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 2nd November 2011, 00:15   #98  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
Example of my ideal TBC performance
http://screenshotcomparison.com/comparison/91487
You'll see some aliasing, that's due to a simple resizer to fix the jitter. On VHS you'd never notice.
What this is, a test signal is added to the video, this allows my software to line-up the video and remove the jitter. This is only useful for new VHS recordings. It's use really is just to measure the actual jitter added, not to perfect obsolete VHS
I'm still working on measuring jitter from 2nd generation tapes, etc.
jmac698 is offline   Reply With Quote
Old 2nd November 2011, 23:33   #99  |  Link
mammo1789
Registered User
 
Join Date: Jun 2011
Posts: 9
Excellent result jmac can we download the whole script and what plugins are required to work
Thanks
mammo1789 is offline   Reply With Quote
Old 3rd November 2011, 00:04   #100  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,869
What, my "perfect TBC"? Oh, that's useless to you, you have to make a new recording with an extra test signal on it. It's too late to perfect the obsolete VHS anymore
jmac698 is offline   Reply With Quote
Reply

Tags
tbc

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 03:22.


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