aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
752 stars 128 forks source link

Incorrect audio duration #130

Closed jessuni closed 4 years ago

jessuni commented 4 years ago

Scenario: include a script with source: https://cdnjs.cloudflare.com/ajax/libs/jsmediatags/3.9.3/jsmediatags.min.js, and trying to read the duration of an audio

Problem: the audio duration read from TLEN.data is not the same as HTMLMediaElement API's audio.duration

Version: v3.9.3

Reproduction:

  1. import jsmediatags from CDN
  2. call jsmediatags.read read with the source: https://github.com/jessuni/shikwasa/blob/next/dist/assets/STS-133_FD11_Mission_Status_Briefing.mp3 (due to CORS, you can download it to reproduce)
  3. TLEN.data would be 666000
  4. add the same audio using HTMLMediaElement:
    
    const audio = new Audio()
    audio.src = 'https://github.com/jessuni/shikwasa/blob/next/dist/assets/STS-133_FD11_Mission_Status_Briefing.mp3'
    audio.preload = 'metadata' // load duration

console.log(audio.duration) // 666.592878, which is closed to 666593ms // does not equals to TLEN.data!



Solution: Do not round `TLEN.data` to seconds but to milliseconds.
aadsm commented 4 years ago

The TLEN tag is a string (like all tags that start with T) so the library is really just reading whatever characters are in there, there is no special processing done after. I guess however (NASA it seems?) wrote that tag rounded it down to seconds.