2 ms·
This supports macOS only. > Requirements: at the moment, msync supports only macOS. This is because it uses macOS's built-in afinfo tool to determine music fil
by johnisgood 6y ago
This supports macOS only.
> Requirements: at the moment, msync supports only macOS. This is because it uses macOS's built-in afinfo tool to determine music files' bitrates.
You can simply use file[1] to get the bitrate on Linux if you have the metadata (if you lack the metadata, read below). I bet even macOS supports it, it is available on Unix, Unix-like, Plan 9, and IBM i. That, or you can use the MediaInfo[2] program or library, although I am not sure if it works with metadata or not.
Using file:
file foo.mp3 | sed 's/.*, \(.*\)kbps.*/\1/'| tr -d " "
The result is in kbps.
[1] https://en.wikipedia.org/wiki/File_(command) https://en.wikipedia.org/wiki/File_(command)
[2] https://mediaarea.net/en/MediaInfo https://mediaarea.net/en/MediaInfo, https://mediaarea.net/en/MediaInfo/Download https://mediaarea.net/en/MediaInfo/Download
You can download the CLI, GUI, or the library of MediaInfo. You want the CLI or the library.
---
The above solutions may work only if you have the metadata (ID3, for example) set, although I am not sure about MediaInfo.
Another solution would be using ffprobe[3] (requires ffmpeg), which for example returns this for a FLAC file:
Metadata:
Comment : Processed by SoX
Duration: 00:00:26.20, start: 0.000000, bitrate: 527 kb/s
Stream #0:0: Audio: flac, 48000 Hz, stereo, s16
It should not be based on any metadata.
[3] https://ffmpeg.org/ffprobe.html https://ffmpeg.org/ffprobe.html
- krackers 6y agoDidn't work for me. I just get "Audio file with ID3 version 2.4.0, contains: ". I think that `file` will only pick it up if the bitrate is actually present in the ID3 info?
- johnisgood 6y agoWhat about ffprobe (requires ffmpeg)? For a FLAC file, I get: Metadata: Comment : Processed by SoX Duration: 00:00:26.20, start: 0.000000, bitrate: 527 kb/s Stream #0:0: Audio: flac, 48000 Hz, stereo, s16 You could extract 527 kb/s easily from this, too, and it should not be based on metadata. I edited my previous comment.
- minimaul 6y agoffprobe even handily has a -print_format json option, for machine readable output :)
- johnisgood 6y agoOh right! Completely forgot about that. ffprobe -print_format json -show_format -show_streams foo.flac This should be easy to parse.