[FFmpeg-user] Get frame info into an ALIGNED DATA ARRAY. :D

Stefano Sabatini stefano.sabatini-lala at poste.it
Wed Aug 10 16:38:18 CEST 2011


On date Wednesday 2011-08-10 03:53:01 -0700, ja0335 encoded:
> hi you...
> 
> i have a question.. I was reading and AvFrame.data have the structure
> AvFrame.data[0] = RED
> AvFrame.data[1] = GREEN
> AvFrame.data[2] = BLUE
> AvFrame.data[3] = ALPHA
> 

> then if i read from data[4] ( i supouse you was refering data[3]), i will
> have only alpha, no?
>, or am i wrong about the AvFram.data structure?

C language adopts 0-indexing, so data[3] is alpha.

Assuming you're reading from a PIX_FMT_RGBA image, you get:

// first line of data
data[0] = RGBARGBARGBA....LINE_PADDING...RGBARGBARGBA...LINE_PADDING...RGBARGBARGBA...

so for accessing the first byte of pixel x,y you do:
uint8_t v = data[0] + y * linesize[0] + x * linestep

in this case linestep = 4 (how many bytes in a pixel)

Note that:
linesize != width * linestep

since each line data needs to be aligned (the exact amount of
alignment - and thus of padding bytes, depends on architecture).

For other pixel formats the exact layout (components disposition in
data, linestep etc.) may be different, and you need to read/understand
pixfmt.h/pixdesc.h for dealing with them.


More information about the ffmpeg-user mailing list