spek icon indicating copy to clipboard operation
spek copied to clipboard

Command Line Interface (cli) for automation purposes?

Open RudeySH opened this issue 6 years ago • 9 comments

I'm looking for a tool that can help me automate things like bitrate detection for multiple songs. Could spek provide such features?

RudeySH avatar Oct 30 '18 16:10 RudeySH

For a simple bitrate detection you can use exiftool.

yssmcl avatar Oct 30 '18 19:10 yssmcl

@RudeySH shameless plug: you can use get-video-properties:

$ pip3 install get-video-properties
$ audioprops '.\Anna Yvette & AFK – Clouds.mp3' | grep bit_rate
  "bit_rate": "320000",

It's in Python 3, wraps ffprobe to provide all sorts of useful info about an audio stream, and bundles an ffprobe executable for mac and windows (64-bit), so pretty much self-contained.

The CLI prints JSON to the standard output, but if you want batch processing the programmatic interface is better suited. Something along the lines of:

from videoprops import get_audio_properties

props = get_video_properties('track.mp3')

print(props['bit_rate'])  # see also: 'sample_rate', 'duration'...

mvasilkov avatar Oct 31 '18 22:10 mvasilkov

Thanks for the replies so far, but it's not quite what I'm looking for. I haven't clarified this properly before, but I'm not looking to calculate the "normal" bitrate, but instead I want to calculate the "true" bitrate. Any low quality song can be re-encoded to 320 kbps, and my understanding was that spek shows you the difference between real 320 kbps and fake 320 kbps.

However after reading more about true bitrates I've come to the understanding that an acoustic spectrum can only broadly indicate the quality of a song, but you can't really use it to calculate the original bitrate of re-encoded songs.

Perhaps I'll have to close this issue because I'm starting to think what I'm asking for is impossible.

RudeySH avatar Nov 01 '18 20:11 RudeySH

@RudeySH yeah it's a hard problem. When going lossless to MP3, you can usually see some distinct features on a spectrogram, such as a lowpass filter on 18 or 20 kHz, a shelf on some 16 kHz, but that's not guaranteed at all — I could encode you an MP3 with ultrasound in it. Also AAC (most iTunes songs) degrades in quality differently.

I think we can try and measure the signal's entropy or something to determine the amount of information factually encoded in the file, as opposed to the file size / nominal bitrate. But then again, very low quality MP3 introduces audible ringing, which is also kind of audio data, just not the audio data we want.

Also this approach is going to yield the lowest bitrate sufficient to encode the signal, so there will be funny results on tracks with a small spectrum (audiobooks and such) — you'll feed it a lossless file and see some 128 kbps just because it's actually can be perfectly encoded in 128 kbps.

I will gladly work with you on a solution to this if you have any ideas.

mvasilkov avatar Nov 01 '18 21:11 mvasilkov

is there a way to use spek to generate spectrograms from the command line? for example:

spek some.mp3 -o some.png

i currently do this with the sox tool, to generate spectrograms for a whole bunch of audio files at the command line:

sox some.mp3 -n spectrogram -o some.png

beemill avatar Dec 26 '18 13:12 beemill

I implemented it somewhat hackily here: https://github.com/withmorten/spek-alternative/issues/1

But it's not "true" commandline (it wouldn't be possible the way Spek currently works under Windows anyway), a GUI window still opens, but closes and saves the PNG automatically.

withmorten avatar Dec 28 '18 17:12 withmorten

Just to be sure, Is this also not possible with FLAC files? For example, detect a 16bits/44kHz CD extracted file that was upscaled to look like a "true" 24bits/96kHz file.

paulosmatos avatar Oct 25 '20 16:10 paulosmatos

hey any leads about this? it's a bit surprising there aren't many posts about this subject or explanations in blogs. basically, we are looking for a way to sift through a large set of audio files (in my case mp3) and we want to detect the ones that have a low true bit-rate.

doing it with spek and examining by eye is too much, but i'm sure it can be automated, perhaps with machine learning. is it not the case?

GonyRosenman avatar May 07 '22 17:05 GonyRosenman

https://pypi.org/project/ffmpeg-bitrate-stats may be helpful for automation

jdstregz avatar Sep 10 '23 21:09 jdstregz