简体   繁体   English

使用FFMPEG将NV12原始数据转换为H264时出现颜色不匹配

[英]Getting color mismatch while converting from NV12 raw data to H264 using FFMPEG

I am trying to convert NV12 raw data to H264 using hw encoder of FFMPEG. 我正在尝试使用FFMPEG的硬件编码器将NV12原始数据转换为H264。

to pass raw data to encoder I am passing AVFrame struct using below logic: 将原始数据传递到编码器我正在使用以下逻辑传递AVFrame结构:

    uint8_t * buf;
    buf = (uint8_t *)dequeue();
    frame->data[0] = buf;
    frame->data[1] = buf + size;
    frame->data[2] = buf + size;
    frame->pts = frameCount;
    frameCount++;

but using this logic, I am getting, color mismatched H264 data, 但是使用这种逻辑,我得到的是颜色不匹配的H264数据,

Can someone tell me , How to pass buffer to AVFrame data? 有人可以告诉我,如何将缓冲区传递给AVFrame数据吗?

Thanks in Advance, Harshil 在此先感谢,Harshil

I solved color mismatch issue by passing correct linesize and data value of AVFrame struct. 我通过传递正确的行大小和AVFrame结构的数据值解决了颜色不匹配的问题。

Let's say NV12 has YYYYUVUV plane for 4x4 image, then in ffmpeg, we need to pass 假设NV12具有用于4x4图像的YYYYUVUV平面,那么在ffmpeg中,我们需要通过

linesize[0] = start location of y linesize [0] = y的起始位置

linesize[1] = 4 because location of u started at 4 and we dont need to specify linesize[2] because uv are packed. linesize [1] = 4,因为u的位置从4开始,并且由于uv被打包,我们不需要指定linesize [2]。

and also in case of data 还有数据

data[0] = start location of y 数据[0] = y的起始位置

data[1] = 4 数据[1] = 4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM