Using ffplay or ffmpeg how can I get a pixel's

2019-06-10 10:00发布

I would like to extract a pixel's rgb value in every frame that is decoded using ffmpeg. I looked into ffplay source code

get_video_frame
video_refresh
queue_picture

I tried the above three methods to hook on to the frame but I do not understand how to get a pixel's rgb value. Could anyone kindly give some pointer into this

1条回答
Viruses.
2楼-- · 2019-06-10 10:34
http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=15&t=805

Thats the source and this is the conversion source I used and it works as expected. Hope this helps someone

ColorRGB GetRGBPixel(const AVFrame& frame, int x, int y)
{
    // Y component
    const unsigned char y = frame.data[0][frame.linesize[0]*y + x];

    // U, V components 
    x /= 2;
    y /= 2;
    const unsigned char u = frame.data[1][frame.linesize[1]*y + x];
    const unsigned char v = frame.data[2][frame.linesize[2]*y + x];

    // RGB conversion
    const unsigned char r = y + 1.402*(v-128);
    const unsigned char g = y - 0.344*(u-128) - 0.714*(v-128);
    const unsigned char b = y + 1.772*(u-128);

    return ColorRGB(r, g, b);
}
查看更多
登录 后发表回答