Need a script for automation the convert a lot number audio files to another format

I have a lot number audio files in the MP3 proprietary format, I want to convert them to 'opus' the free and higher quality format, with keep metadata also.

My selection command-line programs are SoX (Sound eXchange) for convert MP3 files to 'AIFF' format in order to keep quality and metadata* and 'opusenc'1 the official encoder for convert 'AIFF' files to 'opus' format. Most important part of the work is use of 'mediainfo' program for exporting metadata tags of MP3 files and giving them to 'opusenc' program for importing metadata tags to encoding opus files, also giving the bit-rate value of original MP3 files to 'opusenc' for encoding large size AIFF files in order to achieve the opus files with same bit-rate of original MP3 files, so I need a script for automation listed below operations:

  1. Use sox for convert MP3 files in a directory with many sub-directory to the files with AIFF format with same name.

  2. Use 'mediainfo' for exporting metadata tags (Album, Performer, Track name, Recorded date, Genre) and bit-rate value of original MP3 files.

  3. Giving the previous step information to 'opusenc' (artist, title, album, date YYYY-MM-DD, genre)1 and run it.

  4. Delete MP3 and AIFF files after encode successfully done.

I want mentioned operations run consecutive on directories one by one.

My goal of this work is achieve to more freedom. Thank you very much for help and time that you devote to this work.

*: I choose AIFF format because it supports ID3v2 tags but when for test I convert a MP3 file contains metadata to 'AIFF' format with 'SoX' program and convert it to 'opus' with 'opusenc', result was the output opus file lacks metadata (don't known what is the problem exactly) also there was need to specify bit-rate value of MP3 file, so use of 'mediainfo' is necessary.

Hi,

For just the encoding of many files, i had written VHS (Video Handler Script).
But it does much more, as it uses ffmpeg as backend.

I dont know how the aiff codec is named in this matter, so i'll give you an example with ogg.
Assuming you have these files in homedir in subdir audio/mp3.

cd ~/audio/mp3
vhs -e ogg */*/*

Obviously it requires ffmpeg and the related codecs on your system.
sri-arjuna/vhs

Then to install:

./configure --prefix=$HOME/local
./make-install

Hope this helps