使用ffplay或ffmpeg如何在一个帧中获取像素的rgb值 [英] Using ffplay or ffmpeg how can I get a pixel's rgb value in a frame
本文介绍了使用ffplay或ffmpeg如何在一个帧中获取像素的rgb值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在使用ffmpeg解码的每个帧中提取像素的rgb值。我查看了ffplay源代码
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
我尝试了上面三种方法来挂接帧,但我不明白如何获取像素的rgb值。任何人都可以指点这个
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
推荐答案
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);
}
这篇关于使用ffplay或ffmpeg如何在一个帧中获取像素的rgb值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文