[Libav-user] Getting pixel value at each x, y position of a given frame

Simon Brown simon.k.brown at gmail.com
Fri Apr 5 14:19:45 EEST 2019


On Fri, 5 Apr 2019 at 12:08, NDJORE BORIS <ndjoreboris at gmail.com> wrote:

> Hello,
>
> Can someone help me to find the value of each pixel on a given frame,
> please.
> I use frame.data[] and frame.linesize[].
> Then I do this :
>
> for(int i = 0; i< height; i++)
> {
>
>           for(int j=0 ;j<width; j++)
>          {
>                xy = height*stride + width
>                   int pix_i,j = frame.data[xy][frame.linesize[xy]].
>           }
> }
> where width and height are the dimension of the frame.
>
> I don't know if what I do is right
>
> I've done it in an older version of FFMpeg, so not sure if it still
applies, but I used:
for (yy=0 ; yy<frame->height ; yy++) {
memcpy(bufs[0]+720*yy, frame->data[0]+(frame->linesize[0])*yy, 720);
}
for (yy=0 ; yy<frame->height/2 ; yy++) {
memcpy(bufs[1]+360*yy, frame->data[1]+(frame->linesize[1])*yy, 360);
memcpy(bufs[2]+360*yy, frame->data[2]+(frame->linesize[2])*yy, 360);
}
I was decoding YUV 422 data, and assuming a width of 720 pixels, copying it
into my own buffers.
The point is that frame->data has arrays for each plane of the decoded
video, and then each plane buffer can get you a pixel value for that plane.
Ultimately you'll probably need more than one value for each pixel, be it
RGB or YUV.

Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190405/96bcd103/attachment.html>


More information about the Libav-user mailing list