从AVPicture中获取RGB值,并在FFMPEG中更改为灰度
Get RGB values from AVPicture and change to grey-scale in FFMPEG
我的代码的主要动机是更改FFMPEG中AVPicture的RGB值。
我已经能够通过以下文章获得图像数据"data[0]":http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/
我想知道如何访问RGB格式的3字节pic.data[0]。我一直试图以2D矩阵的方式通过for循环访问pic.data[I][j],但第j个元素>3。
这方面的任何指导都将是有益的。
代码在这里:
AVPicture pic;
avpicture_alloc(&pic, PIX_FMT_RGB24, mpAVFrameInput->width,mpAVFrameInput->height);
auto ctxt = sws_getContext(mpAVFrameInput->width,mpAVFrameInput->height,static_cast<PixelFormat>(mpAVFrameInput->format),
mpAVFrameInput->width, mpAVFrameInput->height, PIX_FMT_RGB24, SWS_BILINEAR, nullptr, nullptr, nullptr);
if (ctxt == nullptr)
throw std::runtime_error("Error while calling sws_getContext");
sws_scale(ctxt, mpAVFrameInput->data, mpAVFrameInput->linesize, 0, mpAVFrameInput->height, pic.data,
pic.linesize);
for (int i = 0; i < (mpAVFrameInput->height-1); i++) {
for (int j = 0; j < (mpAVFrameInput->width-1); j++) {
printf("n value: %d",pic.data[0][j]);
}
}
我脑海中的伪代码是:
For each pixel in image {
Red = pic.data[i][j].pixel.RED;
Green = pic.data[i][j].pixel.GREEN;
Blue = pic.data[i][j].pixel.BLUE;
GRAY = (Red+Green+Blue)/3;
Red = GRAY;
Green = GRAY;
Blue = GRAY;
Save Frame;}
我是FFMPEG的新手,因此任何指导和帮助都将是非常可观的。
非常感谢
首先逐行提取每帧的行数据;迭代循环以查看框架的高度。
这是样品:
int FrameHeight = FrameInput->height;
int FrameWidth = FrameInput->width;
for(int Counter=0; Counter<FrameHeight; Counter++)
{
int RowSize = FrameWidth*sizeof(uint8_t)*3;
uint8_t* RowData = (uint8_t*) malloc(RowSize);
memset(RowData, 0, RowSize);
memcpy(RowData, AVFrameInput->data[0]+Counter*AVFrameInput->linesize[0], RowSize);
for(int k=0;k<AVFrameInput->linesize[0];++k)
{
if(RowData[k]> 200)
{
RowData[k] = RowData[k]/3;
}
else
{
if(RowData[k] > 150)
{
RowData[k] = RowData[k]/3;
}
else
{
RowData[k] = RowData[k]/3;
}
}
}
memcpy(AVFrameInput->data[0]+Counter*AVFrameInput->linesize[0], RowData, RowSize);
}
相关文章:
- 在 C++ 中将 RGB 更改为灰度
- OpenCV - 如何在灰度图像上应用 Kmeans?
- OpenCV - 如何将灰度转换为彩色(CV_8UC3)?
- C++灰度图像处理
- 如何显示具有 opengl 纹理的灰度图像
- C++ Gdi+将图像转换为灰度
- 将 BMP 图像转换为灰度
- 如何使用Canny到32位灰度
- 颜色到灰度转换
- (C++)(Visual Studio) 将高斯模糊滤镜应用于 RGB 中的灰度图像
- 使用 SSE 以最快的速度缩小 8 位灰度图像
- 使用 OpenCV 和 C++将 16 位灰度图像更改为彩色图像
- 有没有办法使用 glDrawPixel 渲染单通道灰度图像?
- goodFeaturesToTrack() 只适用于灰度?
- 如何在OpenCV中减去两个不同尺寸的图像和灰度图像
- 使用 ImageMagick 从像素强度数组创建灰度图像时遇到问题
- 如何将图像转换为灰度 opengl c++
- 将高斯模糊应用于灰度图像
- C++:灰度位图标题和实时绘画+opencv图像处理
- 从AVPicture中获取RGB值,并在FFMPEG中更改为灰度