1

I am using below code to convert from VAAPI to YUV420 format.

     AVFrame* src, * dst;
     SwsContext* conversion_context_ = sws_getContext(videoDecoder_->width(),     videoDecoder_->height(), AV_PIX_FMT_VAAPI,scaler_->getWidth(), scaler_->getHeight(), AV_PIX_FMT_YUV420P,(int)SWS_BICUBIC,
 nullptr, nullptr, nullptr); <------------- This function is returning NULL value.
     sws_scale(conversion_context_,
                (uint8_t const * const *)src->data, src->linesize, 0, (int)height,
                dst->data, dst->linesize);

Can some one tell me why I am getting NULL value of SwsContext's pointer?

Harshil Makwana
  • 155
  • 2
  • 13

1 Answers1

2

Fixed this issue by using below code,

SwsContext* conversion_context_ = sws_getContext(videoDecoder_->width(),     videoDecoder_->height(), AV_PIX_FMT_NV12 ,scaler_->getWidth(), scaler_->getHeight(), AV_PIX_FMT_YUV420P,(int)SWS_BICUBIC,
 nullptr, nullptr, nullptr);

So instead of AV_PIX_FMT_VAAPI option, I used AV_PIX_FMT_NV12.

Harshil Makwana
  • 155
  • 2
  • 13
  • I get garbage to the dst->linesize when doing this (it should be 1280,640,640 for 1280x720 image but I get 1280,1280,0). How about you? – El Sampsa Jul 25 '23 at 12:12