Simple shell script to convert audio files under a directory to MP3 at specified bitrate (default 16k) and sampling rate (default 24kHz) using ffmpeg.
curl -s https://raw.githubusercontent.com/rramesh/mp3converter/main/installer.sh | bashThis will:
- Download the converter script to ~/.mp3c
- Make it executable
- Add to PATH (detects shell automatically)
- Show usage instructions
- Create directory and copy script:
mkdir -p ~/.mp3c
cp mp3converter ~/.mp3c/
chmod +x ~/.mp3c/mp3converter- Open
~/.zshrcand add: export PATH="$HOME/.mp3c:$PATH" - Reload: source ~/.zshrc
- Open appropriate RC file:
- Linux:
~/.bashrc - macOS:
~/.bash_profile
- Linux:
- Add: export PATH="$HOME/.mp3c:$PATH"
- Reload: source ~/.bashrc # or ~/.bash_profile on macOS
- ffmpeg must be installed and available on PATH.
- Recommended ffmpeg: any recent stable release; the script uses ffmpeg (and optionally ffprobe if available) to detect and convert audio.
Install ffmpeg:
-
macOS (Homebrew): brew install ffmpeg
-
Debian / Ubuntu: sudo apt update sudo apt install ffmpeg
-
RPM-based systems (Fedora / CentOS / RHEL):
- Fedora: sudo dnf install ffmpeg
- CentOS / RHEL (may require EPEL or RPMFusion): sudo yum install epel-release sudo yum install ffmpeg If packages are not available in default repos, enable the appropriate third-party repo (EPEL/RPMFusion) for your distribution.
mp3converter [OPTIONS] PATH
-b, --bitrate BITRATE Set audio bitrate (e.g. 16k, 64k). Default: 16k
-s, --sampling-rate RATE Set sampling rate. Accepts formats like 24k, 24khz, or 24000. Default: 24kHz (24000)
-r, --replace-original Delete original files/directories and rename converted output to original names
-d, --dry-run Show operations without executing (no files/dirs created)
-h, --help Show help
Notes:
- The script converts audio to MP3 with one audio channel (mono) by default; it uses ffmpeg parameters to set sampling rate (
-ar) and bitrate (-b:a) and forces mono (-ac 1). - Default values: bitrate = 16k, sampling rate = 24000 Hz (24kHz), mono.
- By default, original files and directories are preserved. Use -r to replace them with converted versions.
-
mp3converter /tmp/ddvCreates:
/tmp/ddv_16k/(original/tmp/ddvremains unchanged) -
mp3converter -r /tmp/ddvConverts to
/tmp/ddv_16k/, then deletes/tmp/ddvand renames/tmp/ddv_16kto/tmp/ddv -
mp3converter ~/music/song.m4aCreates:
~/music/song_16k.mp3(original.m4aremains unchanged) -
mp3converter -r ~/music/song.mp3Creates temporary
song_16k.mp3, then replaces originalsong.mp3 -
mp3converter -b 64k ~/music/Creates:
~/music_64k/with converted files -
mp3converter -b 32k -s 48k -r ~/music/Converts to
~/music_32k/then replaces~/music/ -
mp3converter --dry-run -b 32k -r ~/music/
- By default, creates converted files/directories alongside originals:
- Directories: creates sibling directory with _ suffix
- Single files: creates new file with _ suffix
- Original files/directories are preserved
- With -r flag:
- Directories: creates _ directory, then replaces original
- Single files: creates suffixed file, then replaces original
- Original files/directories are removed
- Script will create a sibling directory named
<dirname>_<bitrate>(e.g.ddv_16k), replicate the directory structure, convert audio files to.mp3, copy non-audio files as-is, then delete the original directory and rename the new one back to the original name. - On macOS the script uses
caffeinate(if available) to prevent sleep while processing. - The script requires
ffmpeg. If missing it prints install hints (Homebrew / apt / yum). - In dry-run mode no new directories or files are created; logs indicate what would happen.