mp3-duration | Replaced usage of failure with thiserror for error
kandi X-RAY | mp3-duration Summary
kandi X-RAY | mp3-duration Summary
mp3-duration
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of mp3-duration
mp3-duration Key Features
mp3-duration Examples and Code Snippets
Community Discussions
Trending Discussions on mp3-duration
QUESTION
In a node.js script I need to get the duration of a remote MP3 file.
Currently I use download and mp3-duration modules to download the file and then compute the duration. It works but the download phase is very long.
I noticed that media players can display the duration almost instantly. Would it be somehow possible to get the duration without downloading the entire file first ?
...ANSWER
Answered 2018-May-30 at 16:19mp3 files comes (optionnaly) with metadata called "ID3 tags" :
ID3 is a de facto standard for metadata in MP3 files
- The ID3v1 tag occupies 128 bytes, beginning with the string TAG 128 bytes from the end of the file.
- The Enhanced tag is 227 bytes long, and placed before the ID3v1 tag.
The enhanced tag contains the start-time
and end-time
fields as the last 6 + 6 bytes of the tag formated like mmm:ss. So it gives you the duration of the song.
The solution would be to download the 355 last bytes of the file and check if the enhanced tag (TAG+
) is present, then look for the last 12 bytes of the enhanced tag.
Nowdays, we're mostly using ID3v2 which allows us to embed up to 256MB of informations :
ID3v2 tag is composed of frames. Each frame represents an information. Max frame size is 16MB. Max tag size is 256MB.
The frame you're interested in is the TLEN
frame, which represent the length of the song.
But there is no guarantee that any mp3 file will have an ID3v2 tag or that the TLEN
frame will be stored in its ID3v2 tag.
/!\ /!\ /!\
If the mp3 file does not contains metadata, the only solution is the one you already came up with : estimating the duration with the mp3-duration module.
If the server accepts Range Request, then we just have to tell him the bytes we want !
ID3v1
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install mp3-duration
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page