Vanilagy / mp4-muxer

MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.
https://vanilagy.github.io/mp4-muxer/demo
MIT License
419 stars 32 forks source link

wrong duration & framerate calculation #44

Closed pikilipita closed 5 months ago

pikilipita commented 5 months ago

I am facing an issue with video frames timestamps & framerate calculation.

Let's say I am creating an 1 second video made of 10 frames: one frame every 1/10 seconds.

the encoded timestamps will be encoded as follow: 0 : 0 1 : 100000 2 : 200000 3 : 300000 4 : 400000 5 : 500000 6 : 600000 7 : 700000 8 : 800000 9 : 900000

When opening this video into a video player ( VLC, quicktime... ), the video is seens as an 11.11111 fps framerate with a duration of 0.9 seconds. That must be because video players see it as a 10 frames video with a duration of 0.9 seconds ( the timestamp of the last frame ).

Is there a way to specify the video duration when muxing the mp4 file, so that the video will be seen with 1s length?

I can provide a video file if that helps

weepy commented 5 months ago

maybe just encode an extra fame at the end

pikilipita commented 5 months ago

That would fix the duration issue, but because this is adding one extra frame, the framerate calculation would be wrong

weepy commented 5 months ago

whats it like with 100 frames?

Vanilagy commented 5 months ago

Check out my answer here: https://github.com/Vanilagy/mp4-muxer/issues/31#issuecomment-1910857049

Does this address your issue? This library respects the duration field on the frames you pass into it to determine the duration of the final video.

pikilipita commented 5 months ago

yes, problem solved by adding the duration value, I didn't knew about the videoFrame property. Thank you very much for doing this mp4 muxer, it's been very helpful in my motion design editor: https://pikimov.com

Vanilagy commented 5 months ago

Awesome, glad it fixed it for you. And that project is dope!