c++ - x265 编码器 : order of values in 'planes' array

标签 c++ encoding h.265 libx265

在 x265 编码器 ( https://x265.readthedocs.org/en/default/api.html ) 的编码过程中,我想在新图像编码后将图像像素值(特别是 Y channel 的值)写入 .txt 文件(不重要为什么)。为此,我使用 x265_picture 类的“平面”变量:

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()

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

enter image description here

代替

enter image description here

或另一个例子:

enter image description here

代替

enter image description here

(颜色不重要,“条纹”才是重点)

在输出文件中,数据间隔似乎(显然)是正确的顺序(比方说 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 编码器 : order of values in 'planes' array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32885778/

相关文章:

c++ - 使用/clr 或 clr :pure (cpprestsdk aka casablanca) 编译时不支持互斥锁

c++ - 如何从已编译的 c/c++ dll 中找出调用了哪些 Win API 函数

php - UTF-8 字符串在某处错误编码

c - 在 C 中使用 Fread

node.js - 使用 ffmpeg 抓取 hevc h265 流

Android 中 HEVC(H.265) 的 Android Media Recorder 视频编码

c++ - 这是 C++ 中带有指针的数组的良好使用/代码吗?

c++ - 访问另一个子类中基类的 protected 成员

ruby-on-rails - Ruby 1.8.7(或 Rails 2.x)中的 String.force_encoding()

hevc - 解析hevc比特流