1
votes

I'm encoding video using Windows Media Foundation, but i've had an issue with hardware encoding using AMDh264Enc. The video comes out all washed out, so there is obviously an issue with the color range. The video source is screen capture from Desktop Duplication, which is in R8G8B8A8 (32 bit ARGB) format. I'm setting up the media types like this:

 // Set the output video type.
MFCreateMediaType(&pVideoMediaTypeOut));
pVideoMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);   
pVideoMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);           
pVideoMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, m_VideoBitrate);   
pVideoMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
pVideoMediaTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH264VProfile_High)); 
MFSetAttributeSize(pVideoMediaTypeOut, MF_MT_FRAME_SIZE, destWidth, destHeight); 
MFSetAttributeRatio(pVideoMediaTypeOut, MF_MT_FRAME_RATE, m_VideoFps, 1);  
MFSetAttributeRatio(pVideoMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);

// Set the input video type.
MFCreateMediaType(&pVideoMediaTypeIn));
pVideoMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
pVideoMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_ARGB32);
pVideoMediaTypeIn->SetUINT32(MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_Normal);
pVideoMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
MFSetAttributeSize(pVideoMediaTypeIn, MF_MT_FRAME_SIZE, sourceWidth, sourceHeight);
MFSetAttributeRatio(pVideoMediaTypeIn, MF_MT_FRAME_RATE, m_VideoFps, 1);
MFSetAttributeRatio(pVideoMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);

Videos encoded with Microsoft Media Foundation H.264 video encoder have no issue. I've linked to two sample videos. 1.mp4 is encoded with AMDh264Enc, 2.mp4 with Microsoft Media Foundation H.264 encoder (software).

Does anyone know what causes this issue?

Sample videos

1
Maybe there are some color range related settings for video encoding in your AMD control panelVuVirt

1 Answers

2
votes

I managed to fix the issue by setting the YUV conversion matrix to bt.601 (see MFVideoTransferMatrix_BT601) like this:

pVideoMediaTypeOut->SetUINT32(MF_MT_YUV_MATRIX, MFVideoTransferMatrix_BT601);