Log in

View Full Version : New Script: Read v210 uncompressed 10bit YUV Quicktime/mov files


jmac698
9th January 2011, 13:07
This just blew me away - a quick guess and it worked!
Here's how to read v210 mov files with rawreader (sashimi):

fn="G:\project001a\deepcolor\v210.mov"
RawReader (fn, format="y8", width=5120, height=1080, numframes=0, filehead=21192, framehead=0)
In this case, my file is 1920x1080. Each 5120 bytes represents one row. A group of 6 pixels is stored in 4 bytes. 6 Y samples with 3 each of (cb, cr). There's 2 extra bits per byte, btw.
You can easily see an outline of your picture and step through the frames to see motion, even in encoded form, some of the luma looks like picture.

Some work with masktools and this can be decoded completely in script.

My file had no audio, so how do you guess the filehead for your file? It's easy, for HD just use 5120x1080 size per frame, multiply by number of frames, and whatever is leftover is all header! Example, my sample had 3 frames, 16588800, filesize was 16609992, so 16609992-16588800=21192. This was from a Blackmagic declink capture.

Gavino
9th January 2011, 13:29
A group of 6 pixels is stored in 4 bytes. 6 Y samples with 3 each of (cb, cr). There's 2 extra bits per byte, btw.
Instead of byte, I think you mean (32-bit) word.

jmac698
9th January 2011, 14:35
Yes that's right.
So here it is:
Update: Ver 0.4 now reads the complete image in greyscale. Only tested on 1080p, 10bit images. 720p will not work.

#v210 Reader Ver 0.4 by jmac698
#Read v210 quicktime files with rawreader, by jmac698
#Requires Sashimi 0.74 http://sites.google.com/site/ourenthusiasmsasham/contributions/open-source-software#TOC-Sashimi
#also http://forum.doom9.org/showthread.php?p=1403600
#Masktools 2a48 http://manao4.free.fr/masktools-v2.0a48.zip
#Ver 0.4 - reads full image in 8bit greyscale, with 10bit easily accessible
#Ver 0.3 - reads fully to 8bit greyscale, now requires masktools 2a48
#Ver 0.2 - fixed wrapping bug. 83 pixels *8=664, that would be the trailing bytes
#Ver 0.1 - reads only greyscale, can only read 1/3 of the size, only reads upper 6 bits, wrapped by 83 pixels
fn="G:\project001a\deepcolor\v210.mov"
readv210(fn)

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 readv210(string fn) {#reads 1/3 size, greyscale v210 file
base=RawReader (fn, format="y8", width=5120, height=1080, numframes=0, filehead=21192-664, framehead=0)#21192 header, 664 trailer
high6=base.every(4,3).every(2,1)
low4=base.every(4,2).every(2,1)
mt_lutxy(low4,high6,yexpr="x 6 >> y 2 << +")
o1=last
high4=base.every(4,2).every(2,0)
low6=base.every(4,1).every(2,0)
mt_lutxy(low6,high4,yexpr="y 15 &u 4 << x 4 >> +")#x 4 >> y 4 << +
o0=last
high2=base.every(4,1).every(2,1)
low8=base.every(4,0).every(2,1)
mt_lutxy(low8,high2,yexpr="y 3 &u 6 << x 2 >> +")#x 4 >> y 4 << +
o2=last
weave3h(o0,o1,o2)
}

function weave3h(clip a, clip b, clip c) {#horizontally weave 3 clips
a=a.turnright
b=b.turnright
c=c.turnright
interleave(a,b,a,c)#0 1 2 3->01 23->0213->213 or abc
assumefieldbased
assumetff
weave
assumefieldbased
assumetff
weave
pointresize(width,height*3/4)#deletes every 4th line offset 0
turnleft
}


In case you didn't see some other threads, ffvideosource(fn) and qtinput(fn) also work but they are only 8bit, in the case of qtinput you can fudge 9bit with a trick. With this script you can access the full 10bits in script, though it's not used here yet.