Skip to content

Instantly share code, notes, and snippets.

@SAPikachu
Created September 14, 2011 09:48
Show Gist options
  • Save SAPikachu/1216216 to your computer and use it in GitHub Desktop.
Save SAPikachu/1216216 to your computer and use it in GitHub Desktop.
read and dither v210 in avisynth
# modified from http://forum.doom9.org/showthread.php?p=1469679#post1469679
function readv210(string fn, int file_head, int frame_width, int frame_height, bool "flip") {
line_size = (frame_width * 16 / 6 + 127) / 128 * 128 # all lines are padded to 128 bytes boundary
base=RawReader (fn, format="y8", width=line_size, height=frame_height, numframes=0, filehead=file_head, framehead=0, flip=default(flip,false))
p0=base.every(4,0)
p1=base.every(4,1)
p2=base.every(4,2)
p3=base.every(4,3)
lsb0=mt_lut(p0,yexpr="x 6 <<u 255 &u")
msb0=mt_lutxy(p0,p1,yexpr="x 2 >>u y 6 <<u |u 255 &u")
out0=StackVertical(msb0, lsb0)
lsb1=mt_lut(p1,yexpr="x 2 >>u 6 <<u 255 &u")
msb1=mt_lutxy(p1,p2,yexpr="x 4 >>u y 4 <<u |u 255 &u")
out1=StackVertical(msb1, lsb1)
lsb2=mt_lut(p2,yexpr="x 4 >>u 6 <<u 255 &u")
msb2=mt_lutxy(p2,p3,"x 6 >>u y 2 <<u |u 255 &u")
out2=StackVertical(msb2,lsb2)
weave3h(out0,out1,out2)
y=last.every(2,1)
u=last.every(4,0)
v=last.every(4,2)
# return last
YToUV(u, v, y)
Crop(0,0,frame_width,0)
f3kdb_dither(stacked=true)
}
function every(clip v, int n, int offset) {#select every n bytes horizontally with offset, works on yv12 only
v
w=width
h=height
pointresize(v,w*2,h)
crop(offset*2,0,0,0).addborders(0,0,offset*2,0)#shift left offset pixels
pointresize(w/n,h)
}
function weave3h(clip a, clip b, clip c) {#horizontally weave 3 clips
a=a.turnright
b=b.turnright
c=c.turnright
interleave(a,c,b,c) # a c b c -> ac bc -> abcc
assumefieldbased
assumetff
weave
assumefieldbased
assumetff
weave
# From http://avisynth.org/mediawiki/Advanced_Scripting_Tips:
# In RGB, PointResize deletes the first of each group of 4 lines.
# However, in YUV modes, it deletes the last of each group of 4 lines.
pointresize(width,height*3/4)
turnleft
}
LoadPlugin("D:\My Dropbox\Projects\flash3kyuu_deband\Release\flash3kyuu_deband.dll")
# readv210("output.mov", 36, 640, 480, flip=true)
readv210("coff3.mov", 1103, 176, 144)
readv210("v210_720p.mov", 36, 1280, 720)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment