Skip to main content
Topic: FLAC (Read 3436 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

FLAC

I didn't find bitrate information in the flac stream header, can someone tell me how to calculate the file duration for a given flac stream? can we calcuate it?

FLAC

Reply #1
I calculated the bitrate once in a bash script, here's the part of calculating it:

Code: [Select]
number_samples=$(metaflac --show-total-samples "$file")
sample_rate=$(metaflac --show-sample-rate "$file")
seconds=$(($number_samples / $sample_rate))
file_size=$(du -b "$file" | awk '{ print $1 }')
bitrate=$(( (($file_size / $seconds) * 8) / 1000 ))

FLAC

Reply #2
Thank you very much, it is working fine.

FLAC

Reply #3
Can a FLAC stream exists without streaminfo metadata block?
Can we calcuate the file duration in case of absence of streaminfo metadata block without parsing the entire stream?

 

FLAC

Reply #4
Can a FLAC stream exists without streaminfo metadata block?
Can we calcuate the file duration in case of absence of streaminfo metadata block without parsing the entire stream?

If the stream is Subset compliant, you don't necessarily need the STREAMINFO.

You could calculate the duration by just parsing the first and last frames in your stream.  If the variable block size flag is set, the frame count in each header is actually the starting sample number.  If it is not set, it is the frame number.

for normal:  ((last frame number - first frame number + 1) * blocksize) / sample rate
for variable:  (last frame sample number + last frame size - first frame sample number) / sample rate

 
SimplePortal 1.0.0 RC1 © 2008-2018