[PATCH] opus: Estimate the bitrate if possible

Michael Pyne mpyne at kde.org
Sun Mar 9 05:15:30 UTC 2014


Hi all,

While testing some git-clone stuff I'd discovered that I have a patch hanging 
out on my local git clone of taglib. It estimates the bitrate for Ogg Opus 
files instead of simply returning 0. It's based around the same style of 
bitrate rounding as in the code for Speex and Vorbis.

I offer it up here for inclusion (or not), don't want to create a Github 
account just for a single pull request. Thanks!

Regards,
 - Michael Pyne

---
 taglib/ogg/opus/opusproperties.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/taglib/ogg/opus/opusproperties.cpp 
b/taglib/ogg/opus/opusproperties.cpp
index 7bdcd39..6df8093 100644
--- a/taglib/ogg/opus/opusproperties.cpp
+++ b/taglib/ogg/opus/opusproperties.cpp
@@ -45,6 +45,7 @@ public:
     file(f),
     style(s),
     length(0),
+    bitrate(0),
     inputSampleRate(0),
     channels(0),
     opusVersion(0) {}
@@ -52,6 +53,7 @@ public:
   File *file;
   ReadStyle style;
   int length;
+  int bitrate;
   int inputSampleRate;
   int channels;
   int opusVersion;
@@ -79,7 +81,7 @@ int Opus::Properties::length() const
 
 int Opus::Properties::bitrate() const
 {
-  return 0;
+  return d->bitrate;
 }
 
 int Opus::Properties::sampleRate() const
@@ -149,8 +151,10 @@ void Opus::Properties::read()
     long long start = first->absoluteGranularPosition();
     long long end = last->absoluteGranularPosition();
 
-    if(start >= 0 && end >= 0)
+    if(start >= 0 && end >= 0) {
       d->length = (int) ((end - start - preSkip) / 48000);
+      d->bitrate = (int) (d->file->length() * 8.0 / (1000.0 * d->length) + 
0.5);
+    }
     else {
       debug("Opus::Properties::read() -- The PCM values for the start or "
             "end of this file was incorrect.");
-- 
1.9.0


More information about the taglib-devel mailing list