2012-08-05 91 views
0

對不起,我仍然不能發佈圖像我的問題,因爲低信譽。ffmpeg YUV到RGB偏遠的顏色和位置

我使用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); 

回答

0

如果我改變轉換爲ARGB,結果是罰款@@。

+0

因爲ARGB使用32位。 – UmNyobe 2012-08-29 11:18:37

0

也許你不小心選擇了PIX_FMT_BGR24當你的意思是PIX_FMT_RGB24

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);