Calculate Ogg bitrate without overhead size (#874)

This commit is contained in:
Urs Fleisch
2019-09-02 22:14:41 +02:00
parent 79bc9ccf8e
commit 2f23892182
5 changed files with 23 additions and 6 deletions

View File

@ -163,8 +163,14 @@ void Opus::Properties::read(File *file)
if(frameCount > 0) {
const double length = frameCount * 1000.0 / 48000.0;
long fileLengthWithoutOverhead = file->length();
// Ignore the two mandatory header packets, see "3. Packet Organization"
// in https://tools.ietf.org/html/rfc7845.html
for (unsigned int i = 0; i < 2; ++i) {
fileLengthWithoutOverhead -= file->packet(i).size();
}
d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {

View File

@ -182,8 +182,14 @@ void Speex::Properties::read(File *file)
if(frameCount > 0) {
const double length = frameCount * 1000.0 / d->sampleRate;
long fileLengthWithoutOverhead = file->length();
// Ignore the two header packets, see "Ogg file format" in
// https://www.speex.org/docs/manual/speex-manual/node8.html
for (unsigned int i = 0; i < 2; ++i) {
fileLengthWithoutOverhead -= file->packet(i).size();
}
d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {

View File

@ -186,9 +186,14 @@ void Vorbis::Properties::read(File *file)
if(frameCount > 0) {
const double length = frameCount * 1000.0 / d->sampleRate;
long fileLengthWithoutOverhead = file->length();
// Ignore the three initial header packets, see "1.3.1. Decode Setup" in
// https://xiph.org/vorbis/doc/Vorbis_I_spec.html
for (unsigned int i = 0; i < 3; ++i) {
fileLengthWithoutOverhead -= file->packet(i).size();
}
d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {