emms-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emms-info-native and track duration


From: Petteri Hintsanen
Subject: Re: emms-info-native and track duration
Date: Tue, 29 Aug 2023 00:19:08 +0300

Yoni Rabkin <yoni@rabkins.net> writes:

> Petteri Hintsanen <petterih@iki.fi> writes:
>
>> On Mon, Dec 05, 2022 at 01:14:07PM -0500, Yoni Rabkin wrote:
>>
>>> Do you have any input or insight regarding implementation of track
>>> duration for emms-info-native?
>>
>> Do you mean populating 'info-playing-time for a particular file (track)?  
>> It can be done, but it will require scanning the whole file to get the
>> information.  There is no duration information in the metadata.  So decoding
>> will become somewhat slower.
>>
>> I can try to hack a prototype if there is a need for that.
>
> That would be welcome. If you already have the infrastructure to read
> frames then a lot of the work is already done. But I realize that since
> a lot of files are not constant bitrate, there is a good amount of
> calculation to do.

It took quite a while to get something working, but I have now
resurrected info-native branch with code for decoding stream durations
from ogg/opus/flac and mp3 files.  For those who are interested, please
go ahead and test it.

For ogg and flac files the calculated durations should be accurate
within one second or so.  But MP3s are hairier, since they do not have
any standard way to encode stream duration.  Often, one needs to
estimate the duration, which can go off by tens if not hundreds of
seconds.

Nonetheless, for my modestly sized collection of MP3s, emms-info-native
calculates the playing time with ±2 seconds accuracy for almost all
files (compared against TagLib and ffmpeg).  Failing cases are those
where the inputs are somehow garbled.  I'm not planning to fix those
corner cases because there are so few of them.

Here is a piece of elisp which you can use to test with your own files
against emms-info-libtag (obviously it has to work, ie you need to have
emms-print-metadata compiled):


;; first calculate with emms-info-native and copy the results
;; to another hash table
(require 'emms-info-native)
(setopt emms-info-functions '(emms-info-native))
(emms-cache-reset)
(emms-add-directory-tree "~/music")
(setq emms-cache-native (make-hash-table :test 'equal))
(maphash
 (lambda (name bdata)
   (when (eq (alist-get 'type bdata) 'file)
     (puthash name
              (alist-get 'info-playing-time bdata)
              emms-cache-native)))
 emms-cache-db)

;; then calculate the same with emms-info-libtag
(require 'emms-info-libtag)
(setopt emms-info-functions '(emms-info-libtag))
(emms-cache-reset)
(emms-playlist-current-clear)
(emms-add-directory-tree "~/music")

;; finally compare and print files for which there is a difference
;; more than two seconds
(maphash
 (lambda (key bdata)
   (when (eq (alist-get 'type bdata) 'file)
     (let* ((name (alist-get 'name bdata))
            (native-time (or (gethash name emms-cache-native)
                             0))
            (libtag-time (or (alist-get 'info-playing-time bdata) 0))
            (diff (abs (- native-time libtag-time))))
       (when (> diff 2)
         (message "%d\t%d\t%d\t%s" diff
                  native-time libtag-time name)))))
 emms-cache-db)
  



Few more notes still:

- emms-info-native.el has been split into smaller files.  Hopefully they
  are not *too* small.

- There are now few ERT tests in "test" directory.  Their coverage is
  rather limited, but still better than nothing.  "Resource files" (few
  ogg/flac/mp3 test files) come from Mutagen project.  They are licensed
  under GPLv2+.  We probably need to (and definitely should) state this
  somewhere if we want to keep the files in the distribution.

- There is no way (yet) to execute tests in batch mode e.g. by `make
  check'.


Thanks,
Petteri



reply via email to

[Prev in Thread] Current Thread [Next in Thread]