如何从AVFrame中获取亮度图片
Howto get luminance pictrue from AVFrame?
我正在处理mpeg-4和h264流
首先,我尝试转换为rgb24并使用imagemagic制作灰度,但它不适用于
while(av_read_frame(pFormatCtx, &packet)>=0)
{
// Is this a packet from the video stream?
if(packet.stream_index==videoStream)
{
// Decode video frame
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished,
&packet);
// Did we get a video frame?
if(frameFinished)
{
f++;
//this->fram->Clear();
// if (pFrame->pict_type == AV_PICTURE_TYPE_I) wxMessageBox("I cadr");
// if (pFrame->pict_type != AV_PICTURE_TYPE_I)
// printMVMatrix(f, pFrame, pCodecCtx);
pFrameRGB->linesize[0]= pCodecCtx->width*3; // in case of rgb4 one plane
sws_scale(swsContext, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
Magick::Blob* m_blob = new Magick::Blob(pFrameRGB->data,pCodecCtx->width*pCodecCtx->height*3);
Magick::Image* image =new Magick::Image(*m_blob); // this doesnotwork
image->quantizeColorSpace( Magick::GRAYColorspace );
image->quantizeColors( 256 );
image->quantize( );
但是ffmpeg给了我YUV图片?!所以只需要Y分量,如何得到它?获取Ypicture[x][y]
我假设您已经将swscale配置为YUV420p颜色空间。420P表示4:2:0平面。平面表示颜色通道是独立的。
亮度数据(Y)存储在pFrame->data[0]的缓冲点中(Cb和Cr分别在pFrame->data[1]和pFrame->data[2]中)。在YUV420中,Y平面是每像素1个字节。
因此:
uint8_t getY(int x, int y, AVFrame *f)
{
return f->data[0][(y*f->linesize)+x];
}
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 使用指针从C++中的数组中获取最大值
- 如何获取std::result_of函数的返回类型
- 如何在openssl-ecc中获取十六进制格式的私钥
- 使用Unreal C++获取VR耳机的世界位置/方向
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 从C字符串中获取奇怪的字符串长度
- 为什么我的for循环不能正确获取argv
- 从python中调用C++函数并获取返回值
- 如何获取一个数字的前3位
- 获取字符串的长度并将其分配给数组
- 无法获取菜单选择以运行函数.C++
- 数组长度,为什么从命令行获取时不能使用它?
- Boost Spirit,获取迭代器内部语义动作
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 具有默认值的引用获取函数
- 如何从opencv中获取Mat图像的亮度
- 如何从AVFrame中获取亮度图片