使用ffmpeg sws_scale NV12转YUV420P,自己创建linesize和地址参数
我的整个工程Gitee源码目录:qt_gui_simple2complex/ source / 007_Embeded_Player
#include "libswscale/swscale.h"
#define MDATA_LEN (2 * 1024 * 1024)
static unsigned char mdata[MDATA_LEN];
static unsigned char yuv420_mdata[MDATA_LEN];
static int ySize = 0;
static int width = 1280;
static int height = 720;
static struct SwsContext *m_pSwsCtx = NULL;
int nv12_to_yuv420p()
{
int ret;
ySize = width * height;
m_pSwsCtx = sws_getContext(width,
height,
AV_PIX_FMT_NV12,
width,
height,
AV_PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL);
char *indata = mdata;
char *outdata = yuv420_mdata;
int nv12_linesize[3];
int yuv420_linesize[3];
yuv420_linesize[0] = width;
yuv420_linesize[1] = width / 2;
yuv420_linesize[2] = width / 2;
nv12_linesize[0] = width;
nv12_linesize[1] = width;
nv12_linesize[2] = 0;
unsigned char *inaddr[3] = {indata, indata + ySize, 0};
unsigned char *outaddr[3] = {outdata, outdata + ySize, outdata + ySize + ySize / 4};
do {
ret = sws_scale(m_pSwsCtx, inaddr, nv12_linesize, 0, pCodecCtx->height,
outaddr, yuv420_linesize);
} while (0);
sws_freeContext(m_pSwsCtx);
return 0;
}
|