Using ffplay or ffmpeg how can I get a pixel's rgb value in a frame

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 06:26:51

问题


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:


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);
}


来源:https://stackoverflow.com/questions/23761786/using-ffplay-or-ffmpeg-how-can-i-get-a-pixels-rgb-value-in-a-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!