【问题标题】:libav: Filling AVFrame with RGB24 sample data?libav:用 RGB24 样本数据填充 AVFrame?
【发布时间】:2012-06-05 07:20:07
【问题描述】:

我正在尝试为使用 RGB24 格式初始化的 AVFrame 填充示例数据。 我使用以下代码 sn-p 填充 RGB 数据。 但是在编码的视频中,我只能看到仅覆盖视频帧 1/3 的灰度条。 此代码 sn-p 假设仅填充红色。 任何提示我在这里做错了什么?

AVFrame *targetFrame=.....
int height=imageHeight();
int width=imageWidth();


  for(y=0;y<encoder.getVideoParams().height ;y++){   
       for(x=0;x< encoder.getVideoParams().width;x++){


   targetFrame->data[0][(y* width)+x]=(x%255); //R  
   targetFrame->data[0][(y* width)+x+1]=0;     //G
   targetFrame->data[0][(y* width)+x+2]=0;     //B


  }
   }

【问题讨论】:

    标签: c image-processing ffmpeg libavcodec libav


    【解决方案1】:

    如果您使用的是 RGB24,则需要在索引到数据缓冲区之前缩放坐标。这是您的内部循环的一个版本,可以正确执行:

    int offset = 3 * (x + y * width);
    targetFrame->data[0][offset + 0] = x % 255; // R
    targetFrame->data[0][offset + 1] = 0; // G
    targetFrame->data[0][offset + 2] = 0; // B
    

    还有一个更简单的方法:

    uint8_t *p = targetFrame->data[0];
    for(y = 0; y < encoder.getVideoParams().height; y++) {  
        for(x = 0; x < encoder.getVideoParams().width; x++) {
            *p++ = x % 255; // R
            *p++ = 0; // G
            *p++ = 0; // B
        }
    }
    

    【讨论】:

    • 感谢您的提示,我计算错了偏移量。但我仍然得到一个仅覆盖 1/3 视频帧的垂直灰色条带。
    猜你喜欢
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 2019-03-18
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多