码迷,mamicode.com
首页 > 其他好文 > 详细

QImage下 rgb32 转为 yuv420

时间:2014-10-20 21:20:49      阅读:1961      评论:0      收藏:0      [点我收藏+]

标签:ffmpeg   qt   

    //qWarning() << "update";
    QPixmap pixmap = this->grab();
    QImage image = pixmap.toImage();
    //qWarning() << "byteCount " << image.byteCount();
//    BYTE * rgb = new BYTE[bufsize];
//    BYTE * yuv = new BYTE[bufsize * 3 / 2];
//    RGB2YUV(&pStream, &yuv, 4, 640, 480)
    int w = image.width();
    int h = image.height();
   // image.invertPixels(QImage::InvertRgb);
    //==============================================================
    AVFrame *pFrameRGB = avcodec_alloc_frame();
    // Determine required buffer size and allocate buffer
    int numBytes1 = avpicture_get_size(PIX_FMT_RGB32, w, h);
    uint8_t *buffer1 = (uint8_t *)av_malloc(numBytes1*sizeof(uint8_t));
    avpicture_fill((AVPicture *)pFrameRGB, buffer1, PIX_FMT_RGB32, w, h);
    pFrameRGB->data[0] = image.bits();
    qWarning() << "numBytes1 " << numBytes1;
    AVFrame *pFrameYUV = avcodec_alloc_frame();
    // Determine required buffer size and allocate buffer
    int numBytes2 = avpicture_get_size(AV_PIX_FMT_YUV420P, w, h);
    uint8_t *buffer2 = (uint8_t *)av_malloc(numBytes2*sizeof(uint8_t));
    avpicture_fill((AVPicture *)pFrameYUV, buffer2, AV_PIX_FMT_YUV420P, w, h);
    qWarning() << "numBytes2 " << numBytes2;
    SwsContext *  rgb_to_yuv_ctx = sws_getContext(w,h, PIX_FMT_RGB32,
                                  w,h, AV_PIX_FMT_YUV420P,
                                  SWS_BICUBIC, NULL,NULL,NULL);
//    sws_scale(rgb_to_yuv_ctx, pFrameRGB->data, pFrameRGB->linesize, 0,
//            pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);
    sws_scale(rgb_to_yuv_ctx, pFrameRGB->data, pFrameRGB->linesize, 0,
                h, pFrameYUV->data, pFrameYUV->linesize);
    ////
    int rc = LE_ESVideoData(instance, buffer2, numBytes2);
    //qWarning() << rc << endl;
    sws_freeContext(rgb_to_yuv_ctx);
    av_free(buffer1);
    av_free(buffer2);
    av_free(pFrameRGB);
    av_free(pFrameYUV);


QImage下 rgb32 转为 yuv420

标签:ffmpeg   qt   

原文地址:http://blog.csdn.net/ahyswang/article/details/40318511

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!