On 04/11/2010, at 2:03 AM, [email protected] wrote:
Mark
thank you for a great email. It makes a bit more sense. I am using
YUV_420, so I think I will be ok in terms of subsampling. I also
understand that pixels are stored in data[0] followed by UV with 2x2
format. One thing i am unclear is how do I build a new frame. Do i
just allocate and then assign pixel from data[0] of original frame
to data[0] of a new frame which i will transpose according to y'=-x,
and x'=y formulas to rotate the image? What do i do with UV or
data[1] and data[2]? will it be the same translation?
I've never done any development for encoding with libav. Just decoding
and working with lots of raw YUV data.
Your rotation formula should be more like:
y'=w-x
x'=y
Memory arrays can't handle negative numbers.
Think of a YUV444 bitmap is pretty much like an RGB bitmap. (except
is in a different colour space)
What you do to a pixel in one colour channel you must do to the other 2.
With YUV420, one U or V pixel refers to 4 Y pixels. I won't go into
it here as there are some good web pages around explaining how this
works.
So what you do to one pixel in the Y channel you also must do the
corresponding U and V pixels.
for example:
int num;
uint8_t *buffer;
AVFrame *newframe;
newframe = avcodec_alloc_frame();
if (newframe == NULL)
return;
num = avpicture_get_size(PIX_FMT_UYV420P, width, height);
buffer = (uint8_t *) av_malloc(num * sizeof(uint8_t));
avpicture_fill((AVPicture *) newframe, buffer, PIX_FMT_YUV420P,
width, height);
shouldn't this be
avpicture_fill((AVPicture *) newframe, buffer, PIX_FMT_YUV420P,
height, width);
for (h=0;h<height;h++)
for (w=0;w<width;w++)
newh = w*(-1);
newh = width - w;
neww=h;
(newframe->data[0]+((newh * newframe->linesiz[0])+neww)=origFrame-
>data[0]+((h*->linesize[0])+w);
Once the transpose is complete, i would pass a new frame to encoder.
One thing i am not so sure is if my formula for pixel transpose is
correct. can you provide corrections?
This does appear correct, in theory.
I did remember another gotcha, is for non square pixels. If your
video is from an analog video source, then it will contain non square
pixels and will also require scaling.
Hope this helps
Mark
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user