[mythtv] Re: [mythtv-users] MythMusic taking FOREVER!!!!!!

Jim Paris jim at jtan.com
Mon Jun 2 03:56:30 EDT 2003


> You can either:
>  - Contribute a patch to speed up the length calculation for mp3 files.
>  - Switch to oggs.
>  - Wait for it to finish.
> 
> I'd prefer the first option, but no-one else has done this, and I don't use 
> mp3 files. 

I was adding something like 110 gigs over my dorm's crappy 10baseT and
didn't feel like waiting forever, so I used this.  Seemed to work
fine.  If the bitrate stays constant for the first 32 frames, it
assumes CBR and estimates the total time.

(This is from before the CVS crashed last month, so I can't easily
make an up-to-date patch right now)

-jim

--- /home/jim/.em/backup/!home!src!myth!mythmusic-debian-snapshot!mythmusic!maddecoder.cpp.~1.9.~	2003-04-26 23:46:06.000000000 -0400
+++ maddecoder.cpp	2003-05-01 00:16:04.000000000 -0400
@@ -5,6 +5,7 @@
 #include <math.h>
 #include <stdio.h>
 #include <qregexp.h>
+#include <sys/stat.h>
 using namespace std;
 
 #include <mad.h>
@@ -632,6 +633,11 @@
     timer = mad_timer_zero;
 
     FILE *input = fopen(filename.ascii(), "r");
+    struct stat s;
+    fstat(fileno(input),&s);
+
+    unsigned long old_bitrate = 0;
+    int vbr=0, checked=0;
 
     while (1) 
     {
@@ -657,11 +663,25 @@
                     int tagsize = id3_tag_query(stream.this_frame,
                                                 stream.bufend - 
                                                 stream.this_frame);
-                    if (tagsize > 0)
+                    if (tagsize > 0) {
                         mad_stream_skip(&stream, tagsize);
+			s.st_size -= tagsize;
+		    }
                 }
-            }
-            mad_timer_add(&timer, header.duration);
+            } else {
+		    if (checked == 0)
+			old_bitrate = header.bitrate;
+		    else if (header.bitrate != old_bitrate) 
+			vbr = 1;
+		    if (checked == 32 && vbr == 0) // Assume CBR
+		    {
+			length = (s.st_size * 8) / (old_bitrate / 1000);
+			goto gotlength;
+		    }
+		    checked++;
+			    
+		    mad_timer_add(&timer, header.duration);
+	    }
         }
         
         if (stream.error != MAD_ERROR_BUFLEN)
@@ -671,13 +691,15 @@
         buflen -= stream.next_frame - &buffer[0];
     }
 
+    length = mad_timer_count(timer, MAD_UNITS_MILLISECONDS);
+
+gotlength:
+
     mad_header_finish(&header);
     mad_stream_finish(&stream);
 
     fclose(input);
 
-    length = mad_timer_count(timer, MAD_UNITS_MILLISECONDS);
-
     Metadata *retdata = new Metadata(filename, artist, album, title, genre,
                                      year, tracknum, length);
 


More information about the mythtv-dev mailing list