Log in

View Full Version : Special resizer for YUY2 to YV12 conversions?


hakko504
9th December 2002, 11:43
I was doing some tests with some captured files, and realized that the conversion from YUY2 to YV12 (AviSynth2.5a) isn't quite done in an optimal way. Right now, to use them in A2.5a I use something like the following scriptAviSource(capture.avi").convertToYV12()
TomsMoComp(1,5,1)# #Don't think TMC can use YUY2 in A2.5a yet?
BicubicResize(704,400,0,0.5) #from 352x576
Convolution3d(preset="movieLQ") #preset may varyThis means that the U&V planes are heavily filtered during the process. To enhance quality I would like to be able todo something like this:AviSource(capture.avi")
TomsMoComp(1,5,1) #processed in YUY2
ResizeYUY2toYV12("bicubic",704,400,0,0.5) #from 352x576, returning output in YV12
Convolution3d(preset="movieLQ") #preset may varyThis new ResizeYUY2toYV12 should first do one resize to 704x400 where it only returns the Y plane from the resulting YUY2 frame. Then it could do a new resize to same width 704 but only to half height, 400/2=200. If this also is done in YUY2 then it is only a matter of constructing the U&V planes in YV12 from the values returned from the later resize.

Part of the idea is that though ConvertToYV12 only averages chroma from nearby lines, this isn't necessarily the most optimal way of going from YUY2toYV12, especially if a resize is involved.

Does this sound like a good idea? The point is really to use as many input pixels as possible for the deinterlace and resize stages where they matter the most, but then get rid of excess data for final filtering to gain speed.

I might give it a try myself to code this, but I'm not a very good coder and even though I would like to take advantage of the existing routines, I'm not sure how to just processing U&V with YUY2 input.

Note: Yes it may sound strange to capture video in 352x576@25fps, but this has proven to be the most optimal solution, given my system speed/size. Also, the theory behind resizing states that as long as the final number of pixels is reduced, it may be redistributed with only the addition of errors from the resizing algo itself. And yes, the number of Y pixels are increased, but the number of U&V pixels are reduced.

sh0dan
9th December 2002, 13:46
I don't get your suggestion at all - maybe it's just because it's monday. The two converttoyv12 in the first script also confuses me.

Is this an interlacing issue?? Couldn't you keep your data as YUY2 during the resize and then convert it afterwards? can pointresize() help?

hakko504
9th December 2002, 14:23
Originally posted by sh0dan
I don't get your suggestion at all - maybe it's just because it's monday. The two converttoyv12 in the first script also confuses me.Me too :rolleyes: No, seriously, the second one is in the script to suggest alternative position for the conversion (and it is commented out also - I removed it completely to avoid more confusion)
Is this an interlacing issue?? Couldn't you keep your data as YUY2 during the resize and then convert it afterwards?Part of it is a deinterlacing issue yes, as I have the data in YUY2 format from the capture, I want to keep it that way for the crucial parts of the script, i.e. deinterlacing and resizing. But after the resizing there is no point in keeping YUY2 format, so I though that it would be nice to convert the data from YUY2 to YV12 during the resize. It would be better and faster than using BicubicResize(x,y).ConvertToYV12 and much better quality than ConvertToYV12.BicubicResize(x,y). The later throws away half the chroma before the resize, while the first, calculates chroma for two nearby pixels, and then averages them. If instead the chroma could be computed directly for the final YV12 pixels instead of being mixed up in two steps, neither completely correct, it would produce a better result. It should also result in a small speed gain, if only by the fact that there is only one filter involved instead of two.

I want to use all available chroma for input to the resizer, but only return the correct amount needed for YV12.

Marc FD
9th December 2002, 15:48
@ sh0dan & hakko

what about a extractUplane / extractVplane pair of functions (YUY2 to YV12 without downsampling, resulting in doubled heigth).
then resize the original, the two extracted planes, and mix them together (for that, i think sh0dan already implemented YV12 merge)

to speedup this, and to generally speedup selective plane filtering, it could be a good idea to add some tags in VideoInfo so each filter could know what planes need to be filtered. what about this idea ??

you could do fast bicublin this way. (bicublin is a cool YV12 feature)

MarcFD

PS : something like TransferUVtoYV12 could be cool too.

hakko504
9th December 2002, 15:51
@Marc FD

Sounds more or less exactly like what I was requesting.