【发布时间】:2014-10-15 19:51:18
【问题描述】:
我的代码的主要目的是改变 FFMPEG 中 AVPicture 的 RGB 值。
我已经可以通过以下文章获取图像数据“data[0]”:http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/
我想知道如何访问 RGB 格式的 pic.data[0] 的 3 个字节。我一直在尝试通过 for-loop 以 2D 矩阵方式访问 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 还很陌生,因此任何指导和帮助都将非常重要。
非常感谢
【问题讨论】:
-
为什么不使用 swscale 进行颜色转换,而不是自己做呢?
-
我打算把这个函数并行移植到CUDA上。
-
嗯,然后也许检查一下 - stackoverflow.com/questions/16223315/…。但是,如果您正在解码 H.264 或 MPEG-4,如果您已经计划使用 CUDA,我建议您跳过 FFmpeg 并使用 NVENC 或其他基于 GPU 的解码技术。
-
刚刚发布了答案,希望对其他人也有帮助。