Log in

View Full Version : AVS filter for jumpy VHS capture ?


djidjo
9th April 2003, 08:46
Hi folks,

I'm converting old VHS tapes to SVCDs. I capture them with a DC10+, I have no problem with the capture. Before encoding with CCE, I build the perfect resizing AVS script with FitCD and add some TemporalSmoother to remove noise. The only thing I can't "restore" is that some frames jump up or down from time to time, because of the old tape and the old recorder.

I know there are many VHS/TV filters, but all deal with color and noise correction but none with jumpy frames. Is there any AVS (or Vdub) filter that can detect jumpy frames and correct them or at least remove them (and replace them with an interpolation of the frames before and after) ?

Thanks for any help !
Djidjo

mustardman
10th April 2003, 03:41
Exactly the problem I was having with some old VHS tapes.

See the threads on "conditionalfilter" ('Conditional execution & image evaluation' and 'Using per frame conditional filtering').

I used this filter to automatically correct bad frames by testing the frame in question, and using the results to choose what to do. My two possible clips were 1=Original, 2=SwapFields (and some other stuff).

This fixed the jittering problem very nicely (and automatically) and is eventually going to save me weeks of manual editing!

This filter is very 'alpha' and has bugs, but they are workable. It is only available from sh0dans' site, but should make it to the next beta. If you are interested, I will post the script (about 50 lines)

djidjo
10th April 2003, 12:38
Yes I'm interested, it seems it can solve my problem. I'd be glad if you post the script.
Thanks !
Djidjo

mustardman
10th April 2003, 23:12
@ djidjo

No worries, I will post the script tonight (home computer). It works because every camera image I have seen leaves the first part of the first line black (although the length does vary from about 1/3 to 2/3 of the first line).

The script looks at this first line, if it is black, the picture is good -> no processing is done to the frame.

If the line is not black, the image has jumped, the sync signal was bad or somthing else -> the script shifts & feildswaps the image.

I have also discovered that sometimes the opposite can occur, when the picture is bad, the *field* has slipped down by one line (the current script fixes it when the field is shifted up). I will be doing up a script for this problem this weekend.

It seems as though these image shifts (down/up) do not occur in the same sequence, meaning that I only have to decide how a sequence is bad (manually) and then run the script on it to fix it.

NB: I convert my capture to HuffYUV and resize to 720x576 (PAL DV) and process as HuffYUV. I had problems with AVIsynth decoding MJPG properly. Lots of disk space, but the output is excellent! The last step I do is convert to DV...
Capture(MJPG) -> Resize(Huff) -> Process(Huff) -> Re-encode(DV)

Here is script...
#
# Script for automatically fixing captured Analog source with randomly missing first line.
#
# This is possible because the first line is black for approximately half its' length. This script
# looks at this area of the first line, and decides if it is black or not, and hence decide if
# the frame contains a bad field
#
# Current bugs : Test area has to be blown back up to the full size of the image (720x576)
# Resize dosen't work in AVISynth 2.51alpha - use VirtualDub
#
#
# Procedure :
# Capture analog source at 768x576 (Full PAL size) at least 5MBps with VirtualDub multisegment capture
# Select in and out points
# Audio : Convert to 48KHz and save WAV
# Video : resize to 720x576 (Precise bicubic), save as HuffYUV.
#
# Process audio with CoolEditPro
#
# Reopen video through this script with VirtualDub, select WAV audio
# This script will ...
# Compensate for a corrupt sync (that results in randomly jittering image)
# Illustrate OK/bad frames with a Green/Orange block (located top right)
# Increase the video image size to 720x577 (Due to quirk in Adobe Premiere DV conversion)
# Add small border marks
# Save as HuffYUV
#
# Import files into Adobe Premiere
# Save new files as DV with section durations of 6:45
#
# Quirks with Adobe Premiere conversion to DV
# Input video size must be 720x577
# First line of video image is lost (line 0)
#


SetWorkingDir("f:\VD capture")

Orange = ResetMask(BlankClip(1,32,4, color=$E8B557)) # 4x32 orange block with opaque ALPHA channel
Green = ResetMask(BlankClip(1,32,4, color=$5AE495)) # Green block

HLine = ResetMask(BlankClip(1,8,1, color=$808080)) # Horizontal grey line 8 pixels long
VLine = ResetMask(BlankClip(1,1,8, color=$808080)) # Vertical grey line 8 pixels long

Frame = ConvertToRGB32(SegmentedAVISource("CAM01 SEQ03 HUFF 720 48KHz.avi")) # Internal MJPG decoder gives bad results, use an RGB or HUFF file

#Frame = BicubicResize(Frame,720,576,b=0,c=0.75)

FrameDown = Crop(AddBorders(Frame,0,1,0,0),0,0,0,-1) # Shift frame down by one line
FrameDblDn = Crop(Addborders(Frame,0,2,0,0),0,0,0,-2) # Shift frame down by two lines

FrameOK = FrameDown # OK frame is shifted down by one line
FrameFix = SwapFields(FrameDblDn) # Bad frame has image shifted by two
# lines and the fields swapped

FrameOK = Crop(AddBorders(FrameOK,0,1,0,0),0,0,0,-1) # For output to DV shift down one
FrameFix = Crop(AddBorders(FrameFix,0,1,0,0),0,0,0,-1) # extra line to get BOTTOM field first
# Output to analog MJPG does not require this
# as TOP field is first

FrameOK = AddBorders(Crop(FrameOK,4,5,-12,-11),8,8,8,8) # Remove outer edges & center in 8x8 frame
FrameFix = AddBorders(Crop(FrameFix,4,5,-12,-11),8,8,8,8)

TestArea = Crop(Frame,0,0,180,1) # Quarter of a single line
FullLine = StackHorizontal(TestArea,TestArea,TestArea,TestArea) # Blow test area out into a full line (720 pixels)
Line4 = StackVertical(FullLine,FullLine,FullLine,FullLine) # Now area is 720x4
Line8 = StackVertical(Line4,Line4) # 720x8
Line32 = StackVertical(Line8,Line8,Line8,Line8) # 720x32
Line128 = StackVertical(Line32,Line32,Line32,Line32) # 720x128
FullRes = StackVertical(Line128,Line128,Line128,Line128,Line32,Line32) # 720x576


YVFullRes = ConvertToYV12(FullRes)
YVFrameOK = ConvertToYV12(Layer(FrameOK,Green,"add",level=255,x=680,y=1)) # Green block in the corner if frame is OK
YVFrameFix = ConvertToYV12(Layer(FrameFix,Orange,"add",level=255,x=648,y=1)) # Orange block if frame is bad

FixVid = ConditionalFilter(YVFullRes,YVFrameOK \
,YVFrameFix,"AverageLuma()","<","50") # Final

#FixVid = ConditionalFilter(YVFullRes,Subtitle(YVFrameOK,"OK") \
# ,Subtitle(YVFrameFix," Repaired") \
# ,"AverageLuma()","<","50",true) # Shows status on screen

# True : Use 1st clip (Frame is OK)
# False : Use 2nd clip (Frame is bad - fields have been swapped)

FixVid = ConvertToRGB32(FixVid) # YV12 can't handle odd line numbers (RGB can)
FixVid = AddBorders(FixVid,0,1,0,0) # One extra line at the top

FixVid = Layer(FixVid,HLine,"add",level=255,x=0,y=1) # Top left
FixVid = Layer(FixVid,VLine,"add",level=255,x=0,y=1)

FixVid = Layer(FixVid,HLine,"add",level=255,x=711,y=1) # Top right
FixVid = Layer(FixVid,VLine,"add",level=255,x=718,y=1)

FixVid = Layer(FixVid,HLine,"add",level=255,x=0,y=576) # Bottom left
FixVid = Layer(FixVid,VLine,"add",level=255,x=0,y=569) # Last line is no 576 (0 to 576 = 577 lines)

FixVid = Layer(FixVid,HLine,"add",level=255,x=711,y=576) # Bottom right
FixVid = Layer(FixVid,VLine,"add",level=255,x=718,y=569)


Return(FixVid)