On Mon, 09 Jun 2008 13:57:45 -0400, Konstantin Gorskov  
<[EMAIL PROTECTED]> wrote:
> Hi! I can not understand this part of code:
>     for(int y=0; y<240; y++)
>     //fwrite(pFrame->data[0]+y*pFrameRGB->linesize[0], 1, 320*3, bufptr);
>
> I know, it outputs image file with frame. But, for sample, what  
> linesize[0] is there for?

Imagine this: you have an image which is 11 pixels wide and 5 pixels tall,  
1 byte per pixel.  In order to copy the frame using SSE2 instructions, the  
row length must be a multiple of 16.  So for this example, libraries like  
ffmpeg would allocate 16x5 bytes.

PPPPPPPPPPP.....
PPPPPPPPPPP.....
PPPPPPPPPPP.....
PPPPPPPPPPP.....
PPPPPPPPPPP.....

So:
   frame->w == 11
   frame->h == 5
   frame->linesize[0] == 16

But, when saving to disk, you don't want to waste space, so you get rid of  
the padding:
PPPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPP

> Can I, for sample, access pixel number 32 in a row?

So, to access pixel (column,row) in a packed image which was saved to  
disk, you use
   pixel= data[ row * width + column ];
but for image frames with padding, you need
   pixel= frame->data[0][ row * frame->linesize[0] + column ];

> And why there is only 240 output steps? Not 240*320?

fwrite copies a block of data, not just one pixel.  Also, the *only*  
reason fwrite was called more than once was to skip the padding.  **If  
there was no padding**, the entire frame could be copied with
   fwrite(frame->data[0], 1, 320*240*3, file)

> If I understand correct, all pixel data are stored here, at data[0]?

Yes.  For RGB, all data is in plane 0.  In some formats, however, the  
colors are in separate "planes"  ("planar RGB", "planar YUV", etc).  For  
these, plane N is data[N] with a width of linesize[N].

Hope that helps ;-)
-Mike
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to