Log in

View Full Version : formula, ac3 file size to length in sec


Squeeto
13th September 2005, 07:26
Is there a formula or command line app. to determine the length in seconds of an ac3 (or m2v) file? I can guess it would be something like:

filesize in bytes/1024 x 8bits_per_byte / 192kbps

I want to try to calculate chapter points for multiple m2v files.
Thanks

tebasuna51
13th September 2005, 10:25
Yes for ac3:
FileLength (ms) = 8 x FileSize (Bytes) / BitRate (kbps)

for a 48 KHz ac3, FileLength mus be multiple of 32 milliseconds,
of course for a correct (fixed) ac3.

Squeeto
13th September 2005, 16:25
I need exact entry points. How do you account for other information like the header in the file size? I mean, not all of the bytes are used for the audio.

tebasuna51
13th September 2005, 18:40
A fixed 48 Khz ac3 is a sequence of 32 ms frames, each with header beginning with bytes 0x0B, 0x77. The framelength in bytes is function of bitrate:
256 kbps -> 1024 bytes
320 kbps -> 1280 bytes
384 kbps -> 1536 bytes
448 kbps -> 1792 bytes
512 kbps -> 2048 bytes
576 kbps -> 2304 bytes
640 kbps -> 2560 bytes

Squeeto
13th September 2005, 20:31
Thank you for the help but I am still a little :confused:

I have a 48kHz ac3 at 192kbps file that Windows Explorer reports as-
size 654,976 bytes
so:
654976*8/192 = 27291 or 27.3 seconds

Windows Media Player reports it as 23 sec. and the actual time I measured it to be is 23 sec.

Would it work if I wrote a program that reads the number of 0x0B, 0x77 sequences and multiply by 32 msecs? Could the audio data ever have a 0x0B, 0x77 sequence in it?

tebasuna51
14th September 2005, 02:33
Sometimes there are ac3 with leading bytes at the beginning of file, or corrupt frames ignored by the players. Is for that I say "fixed".

Use BeSliced (GUI for BeSplit, from DspGuru web) to fix this ac3 and see the new size.
I think this is the problem.

If you want to learn more about the ac3 format see:
http://www.atsc.org/standards/a_52a.pdf

Squeeto
14th September 2005, 04:36
Ok. It now works out to 23.4secs - I'd say perfect. Thanks again.