Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Neil
Bothwick is going to reply to more queries in 2025 than ever before.
Q Bits of music
I ripped all my CDs into 128kb/s MP3s, using Audiograbber on a Windows laptop at the time. I’ve since ripped some of my most listened to albums in 320kb/s and now I’m seeing the benefits of FLAC. I am trying to find out which CDs need to be ripped again in 320 and FLAC. All my ripped CDs are in their respective folders and then in a base folder called Music.
I am looking for a way to write a script that will get the bitrate from the MP3 and echo it to the screen, which I can then echo to a file. Ideally I will run it once and it will recursively go into each folder and check for MP3s and add them to the list.
I have MediaInfo installed and I’m sure I can use it. It has a command-line version and will display the bitrate, but whether or not I can display just the filename or folder name and bitrate is another thing.
I would really only have to read one file in the folder and then I would know if the folder is 128kb/s or 320.
Any suggestions? I am not averse to a bit of programming, and I have used C and Python in the past. I’m sure a Bash script would be a hell of a lot handier to do.
Jacob Foster
A MediaInfo (https://mediaarea.net/en/mediainfo) is what we first thought of when reading this. It does have options to output specific information about a file, rather than just dumping the entire file details to your terminal. Its way of working seems a little odd, as though it was not designed by someone whose main operating system was Linux. There is no man page, and little documentation on the website, but the following is a good starting point:
$ mediainfo --Help
What you need is the --Output option:
$ mediainfo --Output=Audio\;%BitRate% filename
The backslash is needed because the semicolon is a reserved character in Linux shells. It is possible to have MediaInfo also output the filename, but you cannot control the order of items output and, for reasons we will come to, it is better to output the bitrate first. As you want to recurse through your entire music directory, you should use the find command to generate a list of MP3 files: