question

karthikvr-7960 avatar image
0 Votes"
karthikvr-7960 asked ·

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

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)

not-supported
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DSPatrick avatar image
0 Votes"
DSPatrick answered ·

QnA currently only supports the products listed in right-hand pane (more to be added). Your post is off topic here. Better to reach out to subject matter experts in dedicated forums over here.

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


· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.