locked
Windows Media foundation: IMFSinkWriter WriteSample API returning error sampleduration is not set RRS feed

  • Question

  • I have a requirement of receiving RTP stream(H264) and exporting them to a MP4 file. We are using media foundation to export frames received in RTP stream to mp4 file. So we extract H264 frames(from RTP packets) and provide it to sinkwriter through WriteSample API(sample time, sample duration etc are set). This seems to work and I get playable mp4.
    But when I don't set sample duration(using SetSampleDuration API), writeSample throws error (MF_E_NO_SAMPLE_DURATION) . The error is not thrown for first few frames but only after certain time(frame after 1.48 seconds)a
    Questions:
    1. Why SetSampleDuration is needed?I assumed that we don't need sample duration if we are providing sample time for every sample. Sink writer can calculate difference between the current frame and last frame as sample duration 
    2. Why the error is not thrown for first few frames by writeSample API .WriteSample throws error  only after certain time(frame after 1.48 seconds). Is it specific to certain frames.
    3. How to do we ideally set the sample duration when duration between frames is not uniform. In my case the average fps is 15 but time between 2 frames is not uniform. (Timestamp of frames in ms: 0, 83,133, 200, 283,333,400,...)
    3.1 To set sample duration of a frame, Wait for next frame and subtract current frame timestamp from next frame timestamp. Should application hold back till next frame is available
    3.2 Setting sample duration based on average fps is fine(even though time difference between frames is not uniform). 
    (Note: I tried 3.2 and it works. I can't visually see any issue. This might be because time difference between frames is not uniform but not varying much. But I am not sure if this is ok. Should I go for approach 3.1)
    • Moved by Dave PatrickMVP Thursday, January 30, 2020 1:41 PM looking for forum
    Thursday, January 30, 2020 11:25 AM

Answers

All replies

  • I'd try asking for help over here.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=mediafoundationdevelopment

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    • Proposed as answer by Guido Franzke Thursday, January 30, 2020 1:46 PM
    • Marked as answer by karthik1990 Thursday, January 30, 2020 2:06 PM
    Thursday, January 30, 2020 1:40 PM
  • Thanks, I requested in the link you shared.  Should I delete this post
    Thursday, January 30, 2020 1:45 PM
  • Thanks, I requested in the link you shared.  Should I delete this post

    No, this is Where-Is-Forum. Only mark Dave's respond as answer.

    Regards, Guido

    Thursday, January 30, 2020 1:48 PM