Log in

View Full Version : Delay chroma by 1 frame


check
10th September 2006, 12:44
Hi, quick question, is it possible to delay the chroma of a video by one frame, or advance the luma by one? I can't see any way to do this with inbuilt functions, but am in the dark in terms of external fuctions to do something like this. A quick and dirty solution is fine as I'm just hoping for nice playback rather than a re-encode.
I've been thinking a little and I figure because there are conversions between YUV and RGB you could do it with some ShowRed/Green/Blue and merging, but I've been unable to get very far before my heat starts steaming :).

What I'm thinking so far:
o use the Show* to pull out the three channels to three variables
o merge the channels into three new variables as per these eqtns:
Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
o trim the first frame from the Y variable and copy into three new variables as per these equations:
B = 1.164(Y - 16) + 2.018(U - 128)
G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
R = 1.164(Y - 16) + 1.596(V - 128)
o merge the final three channels and enjoy!

Which leads to an avs script like so:
Ri = last.ShowRed
Gi = last.ShowGreen
Bi = last.ShowBlue

Y = (0.257 * Ri) + (0.504 * Gi) + (0.098 * Bi) + 16
U = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
V = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128

Y = trim(1,0)

Ro = 1.164(Y - 16) + 1.596(V - 128)
Go = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
Bo = 1.164(Y - 16) + 2.018(U - 128)

The part I'm stuck on is of course blending the clips together. Can anyone enlighten me and/or correct mistakes in my thinking?

GodofaGap
10th September 2006, 13:43
It would be much easier to do with MergeChroma (read doc for more info).


clip1=avisource()
clip2=trim(clip1,1,0)

mergechroma(clip1,clip2,1.0)

drcl
10th September 2006, 13:47
wow. you are trying too hard!

simple way to do it is to create a copy of the video, trim the first frame off, then mergechroma()


ie:

c=avisource("example.avi")
l=trim(c,1,0)
mergechroma(l,c)

check
10th September 2006, 13:59
d'oh! Thanks for the tips guys :D

Mug Funky
11th September 2006, 10:22
alternate solution (with the same outcome):

mergechroma(last,last.selectevery(1,-1))

i like selectevery(1,x) rather than trim for "shifting" a clip in time, but it's just a preference thing (it makes more sense to me).