Media Foundation incorrectly assigns first frame's timestamp as 0.0333 instead of 0 when creating MP4 files.

ZTS 60 Reputation points
2025-07-22T14:56:33.21+00:00

Short Description

We are encountering an issue while generating MP4 video files using the Media Foundation library. Specifically, the timestamp of the first video frame is incorrectly set to 0.0333 seconds, rather than starting at 0. This value corresponds to the duration of a single frame at a frame rate of 30 fps, and it is typically expected to be the timestamp of the second frame.

This behavior has been consistently observed across both Windows 10 and Windows 11, resulting in MP4 files where frame timestamps are misaligned from the beginning.


Community Engagement

To investigate further, we have raised this issue in the following public forums:

Stack Overflow: MediaFoundation: TimeStamp of first frame is not correctly set to 0. Instead, it is set to 0.0333 (frame duration) [Link to thread]

Microsoft Q&A: MediaFoundation: First frame timestamp is 0.0333 instead of 0 [Link to thread]

Community responses suggest this might be an inherent behavior of the Video Processor MFT component in Media Foundation.


Key Questions

Is Microsoft aware of this timestamp discrepancy in Media Foundation?

If so, is there a fix or update planned in a future release of Windows?

Are there any known workarounds or best practices to ensure that video frames are associated with correct timestamps during encoding?


Reproduction Instructions

A zip file titled "MFWriter" has been prepared to help reproduce the issue. It includes:

A standalone C++ application that reads binary video frames (frame1.bin and frame2.bin), assigns timestamps, and generates an MP4 file (sample.mp4) using the Media Foundation API.

A Python notebook (timestamps_collection.ipynb) and a demo video (Colab_Demo.mp4) illustrating the timestamp issue using OpenCV in Google Colab.

To reproduce:

In MFWriter.cpp:

Set the output video path at line 286.

  Set the paths to the binary frame files at **lines 458 and 461**.
  
  Build and run the project in **Visual Studio** with appropriate permissions.
  
  Open the resulting `sample.mp4` file to observe the first frame's timestamp.
  

The Colab demo shows that:

Frame 1 has a timestamp of 0.03s,

Frame 2 has a timestamp of 0.07s, indicating a shift in all timestamps from the expected start at zero.


Let me know if you'd like a formal email or GitHub issue version of this message.Here is a clearer and more professional version of your statement:


Short Description

We are encountering an issue while generating MP4 video files using the Media Foundation library. Specifically, the timestamp of the first video frame is incorrectly set to 0.0333 seconds, rather than starting at 0. This value corresponds to the duration of a single frame at a frame rate of 30 fps, and it is typically expected to be the timestamp of the second frame.

This behavior has been consistently observed across both Windows 10 and Windows 11, resulting in MP4 files where frame timestamps are misaligned from the beginning.


Community Engagement

To investigate further, we have raised this issue in the following public forums:

Stack Overflow:
MediaFoundation: TimeStamp of first frame is not correctly set to 0. Instead, it is set to 0.0333 (frame duration)
[Link to thread]

Microsoft Q&A:
MediaFoundation: First frame timestamp is 0.0333 instead of 0
[Link to thread]

Community responses suggest this might be an inherent behavior of the Video Processor MFT component in Media Foundation.


Key Questions

Is Microsoft aware of this timestamp discrepancy in Media Foundation?

If so, is there a fix or update planned in a future release of Windows?

Are there any known workarounds or best practices to ensure that video frames are associated with correct timestamps during encoding?


Reproduction Instructions

A zip file titled "MFWriter" has been prepared to help reproduce the issue. It includes:

A standalone C++ application that reads binary video frames (frame1.bin and frame2.bin), assigns timestamps, and generates an MP4 file (sample.mp4) using the Media Foundation API.

A Python notebook (timestamps_collection.ipynb) and a demo video (Colab_Demo.mp4) illustrating the timestamp issue using OpenCV in Google Colab.

To reproduce:

In MFWriter.cpp:

Set the output video path at line 286.

  Set the paths to the binary frame files at **lines 458 and 461**.
  
  Build and run the project in **Visual Studio** with appropriate permissions.
  
  Open the resulting `sample.mp4` file to observe the first frame's timestamp.
  

The Colab demo shows that:

Frame 1 has a timestamp of 0.03s,

Frame 2 has a timestamp of 0.07s,
indicating a shift in all timestamps from the expected start at zero.


Windows development | Windows Driver Kit (WDK)
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.