Using IMFSinkWriter and IMFSourceReader, how to store custom timestamp or tag with each frame as metadata? RRS feed

  • Question

  • Hello,

    I need to store a custom timestamp per frame when encoding frames using IMFSinkWriter, to be later read in as attributes from the sample using IMFSourceReader. This is using the H264 encoder and Windows 8.

    If not possible is there a sample ID, or any unique value that exists during encoding that can be read in later when decoding?

    If this isn't possible, seems like an obvious way to extend the API in Windows 9, after all APIs is the reason why Windows still matters.


    Friday, January 10, 2014 6:41 AM

All replies

  • Hello.

    You can define a custom attribute with a custom CLSID to handle custom timestamp.

    See SetUINT64 and GetUINT64. The first parameter will be your custom GUID and the second your timestamp.

    Of course your sample that holds this attribute, needs to be in the same process, to be used by the IMFSourceReader and the IMFSinkWriter.

    • Edited by Miaou77 Wednesday, January 15, 2014 9:49 PM
    Wednesday, January 15, 2014 9:46 PM
  • Thanks for the info. But how do I persist this as metadata in the encoded stream?

    I've tried this using SetUint32 with a custom CLSID.

    On sink writer I do :

    sample.SetUINT64(new Guid("012BA09D-3F70-40EA-85E3-70A9C7BA315D"), 1234);

    This works and I can retrieve the value on the same sample instance, however when later decoding the file using source reader:

    ulong val;
    sample.MfSample.GetUINT64(new Guid("012BA09D-3F70-40EA-85E3-70A9C7BA315D"), out val);

    This fails with {"The requested attribute was not found. (Exception from HRESULT: 0xC00D36E6)"}

    So it seems that the H.264 Media Foundation encoder doesn't actually persist these properties to disk? Any ideas? If there is no workaround, it would mean we can't continue using Media Foundation for our solution.

    Monday, May 12, 2014 9:06 PM
  • Hello.

    Ok. So try SetSampleTime : SetSampleTime

    Tuesday, May 13, 2014 9:36 PM
  • Already have, this sets the time to actually display the frame during playback. I want to store per frame metadata, something that should be opaque to the encoder/decoder.

    Any way to ask the team that works on Media Foundation for guidance? It's really blocking our app development.


    • Edited by _mms_ Friday, May 16, 2014 1:46 AM
    Friday, May 16, 2014 1:36 AM
  • Hello.

    You can try to setup the SinkWriter with this media type : MFMediaType_Binary

    If it is accepted, you should write custom timestamp. Mp4 provide private Stream, but i don't know if the mp4 MediaFoundation muxer can do this.

    • Edited by Miaou77 Friday, May 16, 2014 10:45 AM
    Friday, May 16, 2014 10:42 AM
  • I will try that, and let you know.
    Friday, May 16, 2014 9:55 PM
  • Any luck on solving this? For my project I intent to do almost the exact same thing, storing data for each frame and encoding...
    Wednesday, December 13, 2017 11:56 AM