yusitnikov / fix-webm-duration

navigator.mediaDevices.getUserMedia + MediaRecorder create WEBM files without duration metadata. This library appends missing metadata section right to the file blob.
MIT License
248 stars 48 forks source link

can i use this to get fps value from .webm files #20

Closed giannik closed 1 month ago

giannik commented 4 months ago

Hello, My use case is i want to to have a screen recordered .webm file and extract the duration and fps value to do some processing. Up till now i had to convert to mp4 to get fps which was time consuming.

  1. Can i use this library to extract fps value from webm and avoid the conversion process to mp4 ?
  2. Why do you need to pass the duration parameter as an inout paramter to the function. What is the reasoning for it ?
yusitnikov commented 4 months ago

Hi! The reason for passing duration as argument is because of the way browser records a webm file. The duration of the video supposed to be in the start of the file, but browser cannot know the duration in advance, so it just doesn't include the duration in the file. So we need to measure it manually and add it to the file manually. That's exactly the issue that the current repo fixes. The library can't be used to retrieve the FPS, but you probably can know it in advance (approximately) by accessing the properties of the media stream you use to record the video.

giannik commented 4 months ago

thank you for your response. can you elaborate on how to get the fps value from a webm file ?. im struggling with this.

yusitnikov commented 4 months ago

Looks like there's a "FrameRate" header in the file format, according to the spec. But I don't know if it's the FPS or not, and I don't know if browser actually adds it or not when recording. I don't even know if FPS is constant or dynamic for webm files... You can try adding a breakpoint after file = new WebmFile and inspecting the contents of the file in the debugger to check if the file contains what you need. Again, getting the FPS is not the purpose of the library, but you could use the code as a basis for breaking the webm structure apart and create your own package for that. But it would be much easier to just know the approximate FPS in advance by accessing the stream's settings, e.g. stream.getVideoTracks()[0].getSettings().frameRate

yusitnikov commented 1 month ago

Just recorded a webm file from a browser, and the header section looked like this:

image

So I don't believe that the file contains any information about the framerate.