[FFmpeg-soc] [RFC] Frame rotation by 90 degree

Tilak Adhya tilakadhya at rediffmail.com
Mon Dec 3 08:18:11 CET 2007


  
Hi All,

I am new to this mailing list. My problem is to rotate a frame by 90, 180 and 270 degrees by adding/changing in FFMPEG code. For 180 degree rotation, I got the vf_vflip.c file under the libavfilter folder, which does the flipping, that means 180 degree rotation. But for 90 and 270 degree rotation we need to add in the ffmpeg code base.
For this purpose, I thought that vf_vflip.c would be the starting point to proceed. And I got that, the fliping part is done inside the start_frame() function of the vf_Vflip.c (am I wrong...?).

static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
{
    FlipContext *flip = link->dst->priv;
    AVFilterPicRef *ref2 = avfilter_ref_pic(picref, ~0);
    int i;

    ref2->data[0] += (ref2->h-1) * ref2->linesize[0];
    ref2->linesize[0] = -ref2->linesize[0];
    for(i = 1; i < 4; i ++) {
        if(ref2->data[i]) {
            ref2->data[i] += ((ref2->h >> flip->vsub)-1) * ref2->linesize[i];
            ref2->linesize[i] = -ref2->linesize[i];
        }
    }

    avfilter_start_frame(link->dst->outputs[0], ref2);
}

In the above code width becomes the negative of of the existing width, but what's the use of the two lines below ...

if(ref2->data[i]) {
            ref2->data[i] += ((ref2->h >> flip->vsub)-1) * ref2->linesize[i];
            ref2->linesize[i] = -ref2->linesize[i];
        }

This algorithm is not clear to me.

So my understanding for implementing rotation, is to add code in the start_frame() function. I need to rotate the frame in Y,U and V plane separately. But I saw that linesize[1] and linesize[2] does not represent the width of the frame exactly and I am confused about the exact rotation algorithm. For rotation in the Y plane, according to my understanding the rotation algorithm will be as follows ---

void rotatePicture(AVFrame *fPicture, int w, int h, AVCodecContext *enc){
  int i = 0, index, ai = 0, wi, hi ;
  uint8_t *arr = av_malloc(w*h * sizeof(uint8_t));
  uint8_t *arr1 = NULL;
  uint8_t *arr2 = NULL;
  memset(arr, 0, w*h*sizeof(uint8_t));
 
  // this is ONLY for the Y component
  for(wi = 0; wi <= w-1; wi++){
    for(hi = h - 1; hi >= 0; hi--){
      //arr[ai++] = fPicture->data[0][hi*w + wi];
      arr[ai++] = 0;
    }
  }

What do you think - is it correct... ? And then what will be for U and V plane...? 

Please suggest...

Thanks in Advance...

Thanks and Regards
Tilak




*--
tilak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-soc/attachments/20071203/f9f44404/attachment.htm>


More information about the FFmpeg-soc mailing list