首页 > 代码库 > QImage下 rgb32 转为 yuv420
QImage下 rgb32 转为 yuv420
//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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。