【问题标题】:ffmpeg YUV to RGB distored color and positionffmpeg YUV 到 RGB 扭曲的颜色和位置
【发布时间】:2012-08-02 15:58:36
【问题描述】:

很抱歉,由于声誉低,我仍然无法为我的问题发布图片。

我使用 ffmpeg 函数将解码后的帧从 YUV 转换为 RGB24,但是颜色和结果图像失真严重。以下是我的代码片段,框架宽度和高度为 (176, 144)

len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
    if (got_picture) {
            //...

    AVFrame *pFrameRGB = avcodec_alloc_frame();
    // Determine required buffer size and allocate buffer
    int numBytes=avpicture_get_size(PIX_FMT_RGB24, c->width, c->height);
    uint8_t *buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
    avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, c->width, c->height);

    struct SwsContext *img_convert_ctx = sws_getContext(c->width, c->height, PIX_FMT_YUV420P, c->width, c->height, PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL);
    sws_scale(img_convert_ctx, picture->data, picture->linesize, 0, picture->height, pFrameRGB->data, pFrameRGB->linesize);
    sws_freeContext(img_convert_ctx);
    // Save the frame to disk
    if(++frame<=5)
        SaveFrame(pFrameRGB, c->width, c->height, frame);

【问题讨论】:

    标签: ffmpeg rgb yuv


    【解决方案1】:

    如果我改为转换为ARGB,结果很好@@。

    【讨论】:

      【解决方案2】:

      您的意思是PIX_FMT_RGB24,也许您不小心选择了PIX_FMT_BGR24

      struct SwsContext *img_convert_ctx = sws_getContext(c->width, c->height, 
          PIX_FMT_YUV420P, c->width, c->height, PIX_FMT_RGB24, SWS_BICUBIC, 
          NULL, NULL, NULL);
      

      【讨论】:

        猜你喜欢
        • 2012-01-19
        • 1970-01-01
        • 1970-01-01
        • 2018-02-19
        • 2017-04-21
        • 1970-01-01
        • 2018-11-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多