3

Having trouble when setting up the input type. I'm getting this error:

MF_E_INVALIDMEDIATYPE: The data specified for the media type is invalid, inconsistent, or not supported by this object.

Any ideas how to fix it?
The error is returned at SetInputMediaType.
This is the setup code for input and output:

hr = MFCreateMediaType(&mediaTypeIn);
hr = mediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
hr = mediaTypeIn->SetGUID(MF_MT_SUBTYPE,  MFVideoFormat_RGB24);
hr = mediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
hr = MFSetAttributeSize(mediaTypeIn, MF_MT_FRAME_SIZE, width, height);
hr = MFSetAttributeRatio(mediaTypeIn, MF_MT_FRAME_RATE, fps_num, fps_den);
hr = MFSetAttributeRatio(mediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);

hr = MFCreateMediaType(&mediaTypeOut);
hr = mediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); 
hr = mediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_MSS2);
hr = mediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
hr = mediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, bit_rate);
hr = MFSetAttributeSize(mediaTypeOut, MF_MT_FRAME_SIZE, width, height);
hr = MFSetAttributeRatio(mediaTypeOut, MF_MT_FRAME_RATE, fps_num, fps_den);
hr = MFSetAttributeRatio(mediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);

hr = vx->sinkWriter->AddStream(mediaTypeOut, &vx->streamIndex);

// No problems before this point, and the call below returns MF_E_INVALIDMEDIATYPE
hr = vx->sinkWriter->SetInputMediaType(vx->streamIndex, mediaTypeIn, NULL);
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
Bgt
  • 41
  • 3
  • I am not ignoring the return values, I just took out the bits of code that print them out so I can make this question nice clear and easy to understand. The problem is at hr = vx->sinkWriter->SetInputMediaType(vx->streamIndex, mediaTypeIn, NULL); – Bgt Jul 10 '15 at 14:02
  • `hr = ` is just for decoration, clearly. – Jonathan Potter Jul 10 '15 at 14:02
  • @LauraBog Please don't deny us the information that you have. If you can't solve the problem, why would we be able to do so with even less knowledge than you have. Please show your error checking and report full details on the failure and error codes. – David Heffernan Jul 10 '15 at 14:05
  • I mentioned in the question: the error is MF_E_INVALIDMEDIATYPE. The data specified for the media type is invalid, inconsistent, or not supported by this object. I have used almost the same setup function for H264 and Windows Media Video 9 Encoder and it worked fine. I don't see why this codec is not working. – Bgt Jul 10 '15 at 14:07
  • Nowhere in the question can we see which call returns that value. Please do edit the question to make it complete. – David Heffernan Jul 10 '15 at 14:09
  • There must be something particular about windows media video 9 screen encoder that I hope someone who used this before knows about. – Bgt Jul 10 '15 at 14:09
  • Media Foundation makes troubleshooting of this pretty unclear. You should rather instantiate MSS2 encoder itself, initialize its RGB input and then enumerate output media types: you will get an idea what they look like. Supposedly you miss some mandatory value/attribute and hence the rejection. – Roman R. Jul 10 '15 at 14:25
  • MSS2 only has one output type, but I have enumerated the allowed input types and I only got RGB8 and some unknown GUIDs, that are not mentioned here [link](https://msdn.microsoft.com/en-us/library/windows/desktop/dd757532%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396). I set the input type to RGB8 and got the same error, in the same place. Any suggestions from here? – Bgt Jul 13 '15 at 16:49

1 Answers1

1

You don't tell us what is width, height, fps_num, fps_den, and so on. So, for example, if width is zero, you will receive MF_E_INVALIDMEDIATYPE...

EDIT

Here is the answer : Matt Andrews Microsoft (MSFT)

As noted earlier in this thread, the Microsoft screen encoder is not registered by default. The CLSID for the screen encoder is CLSID_CMSSCEncMediaObject2. If you want to use this in an application, you either need to create it manually using CoCreateInstance and then insert it into a topology, or locally register it using MFTRegisterLocalByCLSID.

MFVideoFormat_MSS2 is not present by default on system.

mofo77
  • 1,447
  • 9
  • 17
  • I used the same values for setting up H264, wmv3 and microsoft media video 9 encoder and worked with no problems. Could some values not be appropriate for the screen encoder, but work for other encoders...? – Bgt Jul 13 '15 at 12:43
  • For now, bit_rate = 16000000; fps_num= 30; fps_den = 1; height = 1080; width = 1920; – Bgt Jul 13 '15 at 13:02
  • Ok, did you try to setup others Encoder Properties, like MFPKEY_ASFOVERHEADPERFRAME and so on. – mofo77 Jul 13 '15 at 13:05
  • I am now using everything as default, there are more than 20 properties. I could try and set some of them. However, do you think that the way I am using the sinkwriter could be a problem for this particular encoder? – Bgt Jul 13 '15 at 13:21