FFmpeg 4.0.2 实现YUV视频帧scale大小变换

int YUVFrameScale(AVFrame *srcYUVFrame, int nSrcW, int nSrcH, AVFrame *dstYUVFrame, int nDstW, int nDstH)
{
    // 目标缓冲区
    int dst_bufferSize = nDstW * nDstH * 3 / 2;
    uint8_t *dst_bufferPtr = (uint8_t *)malloc(dst_bufferSize * 2);
    if (dst_bufferPtr == NULL)
    {
        cout << "error when malloc for dst_bufferPtr" << endl;
        return -1;
    }
    // 分配空间
    av_image_fill_arrays(dstYUVFrame->data, dstYUVFrame->linesize, dst_bufferPtr, AV_PIX_FMT_YUV420P, nDstW, nDstH, 1);
    struct SwsContext* m_pSwsContext = sws_getContext(nSrcW, nSrcH, AV_PIX_FMT_YUV420P, nDstW, nDstH, AV_PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
    if (NULL == m_pSwsContext)
    {
        cout << "ffmpeg get context error!" << endl;
        return -1;
    }
    sws_scale(m_pSwsContext, srcYUVFrame->data, srcYUVFrame->linesize, 0, nSrcH, dstYUVFrame->data, dstYUVFrame->linesize);
    sws_freeContext(m_pSwsContext);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hsq1596753614/article/details/82251647
今日推荐