Calculating the length of MP3 Frames in milliseconds [closed]

試著忘記壹切 提交于 2019-12-09 03:04:22

问题


Lets say one MP3 Frame length in bytes is 104: how to get that in milliseconds? Is there any formula or something to do that?


回答1:


Hmm, it's strange but no one answer the question properly. I've been investigating, here's the formula:

Frame length (in ms) = (samples per frame / sample rate (in hz)) * 1000

The typical MP3 (an MPEG Layer III, version 1) has 1152 samples per frame and the sample rate is (commonly) 44100 hz. So (1152 / 44100) * 1000 = 26,122449 ms per frame.

Notice the frame length (time) does not depend on the bitrate.

More info: http://www.mp3-converter.com/mp3codec/frames.htm




回答2:


You need to parse the MP3 frame header to get the MP3 version and layer number (see this document for the frame header format). Once you have those, you can use the following lookup table to get the number of samples in the frame.

    private static readonly int[,] samplesPerFrame = new int[,] {
        {   // MPEG Version 1
            384,    // Layer1
            1152,   // Layer2
            1152    // Layer3
        },
        {   // MPEG Version 2 & 2.5
            384,    // Layer1
            1152,   // Layer2
            576     // Layer3
        }
    };



回答3:


I used different approach to calculate the time of every frame in the mp3 file.. assuming that all frames have same size in the file.. so I just get the total time of the mp3 file in milliseconds.. then calculate total frames in the file and finally divide the total time by total frames.. so the formula would look like:

float frameTime = totalTimeMillisec / totalFrames;

you will get the total time of every frame in the track in milliseconds.. after I done that I got around 52 milliseconds... and that was similar to what Mark Heath said..

anyway thanks everybody for the solutions..




回答4:


Frame is not the same as time. BUT if you know the total size you can do something like this overhead+Frame*time=total size.




回答5:


http://en.wikipedia.org/wiki/MP3 has an entry on MP3 file structure but you should try to find one with more details.

The frame header contains a field called bit rate. Given this bit rate and the frame data size you can determine how much actual music time is in that frame data. I expect the formula to be: DataSize = BitRate * TimeInterval.

See http://www.mp3-tech.org/programmer/frame_header.html for details on the bit rate encoding.




回答6:


Since the data is encrypted you cant know the played bit rate until the data has been decrypted. No one talks how to encrypt (compress) and decompress the data. All i know is the Lame program will take a wave file then filter/resample it then somehow compress the data before placing it within the frames. I dont know if these mp3 players are using 8 or 16 bit words to play in each channel. But the bit rate and all are related to the size of the channel byte and the sample rate played. Not the same as the data first imput to the encoder. How to see the final results which is played by the player is the trick here. CBR makes a good reference from which to later learn VBR.

How does one take 16 bits (WORD per sample) of one sample one channel and compress ot for the MP3 data ? Is the results 12 bits or less ? Whats the compression routine called ?



来源:https://stackoverflow.com/questions/6220660/calculating-the-length-of-mp3-frames-in-milliseconds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!