How to use IMFMediaSource to get the byte data from the capture source? RRS feed

  • Question

  • Hi

      I use Media Session to preview the video from camera. I want to know how many byte data dragged from media source to decoder, an how to get the bit rate of the data from media source.

    Thank you.

    Thursday, November 22, 2012 8:51 AM

All replies

  • There's an easy way and a hard way. The easiest way to is make an IMFSourceReader from the IMFMediaSource then get the Native Media Type from the IMFSourceReader. Since you are using a session, it's more long-winded. You need to do the following:

    • Call IMFMediaSource::CreatePresentationDescriptor to get a copy of the media source PD
    • Call IMFPresentationDescriptor::GetStreamDescriptorByIndex to get a copy of the IMFStreamDescriptor for your video stream
    • Call IMFStreamDescriptor::GetMediaTypeHandler to get a copy of the Media Type Handler
    • Call IMFMediaTypeHandler::GetCurrentMediaType to get the IMFMediaType object for the video stream
    • Finally, call IMFMediaType::GetUINT32(MF_MT_AVG_BITRATE,&bitrate) to store the average bitrate of the video into the variable 'bitrate'

    The Media Type may or may not have this attribute defined, for various reasons. Even if it does, it might have a different meaning depending on the bitrate mode of your camera. It might be CBR, VBR, peak-constrained VBR etc which you can only determine through the ICodecAPI interface and I'm not sure how to query that interface through a media source.

    • Proposed as answer by Nobby_ Sunday, November 25, 2012 1:16 AM
    Sunday, November 25, 2012 1:15 AM
  • Dear Nobby:

                Thank you for you reply.

                I have succeeded to get the sample from media source using another way.

    Tuesday, November 27, 2012 7:10 AM