在使用x265编码器(https://x265.readthedocs.org/en/default/api.html)进行编码的过程中,我想在对新图像进行编码后将图像像素值(特别是Y通道的值)写入.txt文件中(这并不重要)。为此,我使用了x265_picture类的'planes'变量:

x265_picture* pic_out; # variable where encoded image is to be stored
... # encoding process
uint8_t *plane = (uint8_t*)pic_out->planes[0];
uint32_t pixelCount = x265_picturePlaneSize(pic_out->colorSpace, m_param->sourceWidth, m_param->sourceHeight, 0);
ofstream out_file("out_file.txt");

for (uint32_t j = 0; j < pixelCount; j++) # loop for all pixels
{
    int pix_val = plane[j];
    out << pix_val;
}

ofstream.close()

但是当我将输出数据重构为图像时,我得到

c&#43;&#43; - x265编码器: &#39;planes&#39;数组中值的顺序-LMLPHP

代替

c&#43;&#43; - x265编码器: &#39;planes&#39;数组中值的顺序-LMLPHP

或另一个例子:

c&#43;&#43; - x265编码器: &#39;planes&#39;数组中值的顺序-LMLPHP

代替

c&#43;&#43; - x265编码器: &#39;planes&#39;数组中值的顺序-LMLPHP

(颜色并不重要,需要关注“条纹”)

在输出文件中,似乎有一些数据间隔(按正确的顺序排列)(例如89,90,102,98,...),后面总是长着等号的长序列(例如235,235,235,235 ...或65,65, 65,65 ...),“创建”条纹。有人可以告诉我我失踪了吗?

最佳答案

谢谢大家,刚刚解决了这个问题...关键是使用'src + = srcStride':

ofstream out_file("out_file.txt");
int srcStride = pic_out->stride[0] / sizeof(pixel);
uint8_t* src = (uint8_t*) pic_out->planes[0];

for (int y = 0; y < m_param->sourceHeight; y++, src += srcStride)
{
    for (int x = 0; x < m_param->sourceWidth; x++)
        out_file << (int)(src[x]) << ",";
}
out_file.close();

关于c++ - x265编码器: 'planes'数组中值的顺序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32885778/

10-11 03:12