Why RGB frames converted from YUV data decoded out by Nano have many snowflakes ?

Hi NVidia team,

We use VLC to play the video from an IPC camera in network, the video is OK,
but when we use JetsonNano to decode out the YUV420 data of the video from an IPC camera, then convert the YUV420 data into BGR data with opencv’s cv::cvtColor(yuvImg, rgbImg, CV_YUV2BGR_I420) or libyuv’s libyuv::I420ToRGB24(), the color picture of each frame has many snowflakes (very small white dots or very small white flaws), do you know what the root cause is ?

I paste the major code snippets here for helping you understand what and how we do:

m_ffmpegMedia = std::make_shared<FFMpegMedia>();
if(0 != m_ffmpegMedia->Open(m_playStr, false, 25)) {
    m_isOpened = false;
    LOG_ERROR << "m_ffmpegMedia.Open failed, play url: " << m_playStr;
    return false;
} 
m_ffmpegMedia->SetStreamDataProc(std::bind(&VideoChannel::StreamFrameProc, this, std::placeholders::_1));

void VideoChannel::StreamFrameProc(StreamFrame &frame) {
StreamType st = ST_H264;
this->RtspClientCallBackInner(st, frame.data, frame.length, 0);
}

void VideoChannel::RtspClientCallBackInner(StreamType st, unsigned char *buffer, long size, void *param) {
if (st != ST_H264 && st != ST_H265)
return;

if(m_decoder == 0) {
    SStaticParamsDecode stStaticParamsDecode = DEFAULT_DECODE_STATIC_PARAMS;
    stStaticParamsDecode.dataType = DataTYPE_ID_H264;
    
    m_decoder = MEDIA_DecoderOpenChannel(stStaticParamsDecode, DecodeCallBack, this);
    if(m_decoder == 0) {
        LOG_ERROR << "DecoderOpenChannel failed"; 
        return ;
    }
    MEDIA_DecoderStart(m_decoder);
}

void VideoChannel::DecodeCallBackInner(HDECODER decoder, SVideoStreamFrame *frame) {

m_frameLock.lock();
m_frames.push_back(*frame);
m_frameLock.unlock();

bool copyYuv(StNanoYuvData pYuvData, unsigned char mem) {
for (int i=0; inHeight[0]; ++i)
{
memcpy(mem, pYuvData->pData[0]+ipYuvData->nPitch[0], pYuvData->nWidth[0]);
mem += pYuvData->nWidth[0];
}
for (int i=0; inHeight[1]; ++i)
{
memcpy(mem, pYuvData->pData[1]+i
pYuvData->nPitch[1], pYuvData->nWidth[1]);
mem += pYuvData->nWidth[1];
}
for (int i=0; inHeight[1]; ++i)
{
memcpy(mem, pYuvData->pData[2]+i*pYuvData->nPitch[2], pYuvData->nWidth[2]);
mem += pYuvData->nWidth[2];
}
return true;
}

bool VideoChannel::read(cv::Mat& image) {
    
    while(m_frames.empty()) {
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
        if(sec++ > 4000) {
            return false;
        }
    }
    m_frameLock.lock();
    SVideoStreamFrame fr = m_frames.front();
    m_frames.pop_front();
    m_frameLock.unlock();
    StNanoYuvData *pYuvData = (StNanoYuvData *)fr.pFrame;
    image.create(pYuvData->nHeight[0], pYuvData->nWidth[0], CV_8UC3);
    Mat yuvMat;
    yuvMat.create(pYuvData->nHeight[0] * 3 / 2, pYuvData->nWidth[0], CV_8UC1);
    copyYuv(pYuvData,yuvMat.data);
    cv::cvtColor(yuvMat, image, CV_YUV2BGR_I420);
    cv::imshow("image",image);
    cv::waitKey(0)

Here we find each image shown does always have many snowflakes, why ? what might cause the snowflakes in the pictures ?

Thanks,
Arnold Chen