How can I use ffmpeg's swscale to convert from

2019-08-12 01:05发布

Say I have an NV12 frame in memory as an array of bytes. I know:

  • its Width and Height
  • its Stride (total width of a line including padding), which is the same for Y and UV components as per NV12 specification
  • I know where Y begins, U begins at Y + (Stride * Height), and V begins at U + 1 (interleaved with U).

Now this is what I have so far:

SwsContext* context = sws_getContext(frameWidth, frameHeight, AV_PIX_FMT_NV12, frameWidth, frameHeight, AV_PIX_FMT_RGB32, 0, nullptr, nullptr, nullptr);
sws_scale(context, 

So I don't know what the parameters to sws_scale should be:

  • srcSlice : a pointer to the array of bytes? It should apparently be a pointer to a pointer, but what I have is just a single-dimensional array of bytes.
  • srcStride : apparently expects an array of strides, but I have just one stride for the entire file. Should I pass an array with just one element?
  • srcSliceY : an offset to the first byte I guess? Should be 0 then.
  • srcSliceH : the frame height I guess
  • dst : once again, pointer to a pointer, but my destination output is actually just another array of bytes...
  • dstStride : Width * 4 I guess?

Any help appreciated.

标签: c++ video ffmpeg
1条回答
Rolldiameter
2楼-- · 2019-08-12 01:43
/// uint8_t * Y;
/// uint8_t * out;

// 2 planes for NV12: Y and interleaved UV
uint8_t * data[2] = {Y, Y + Stride * Height}; 

// Strides for Y and UV
// U and V have Stride/2 bytes per line; 
// Thus, we have 2 * Stride/2 bytes per line in UV plane
int linesize[2] = {Stride, Stride}; 

uint8_t * outData[1] = {out}; // RGB have one plane 
int outLinesize[1] = {frameWidth*4}; // RGB32 Stride

sws_scale(context, data, linesize, 0, Height, outData, outLinesize);
查看更多
登录 后发表回答