Skip to content

rramesh/mp3converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mp3converter

Simple shell script to convert audio files under a directory to MP3 at specified bitrate (default 16k) and sampling rate (default 24kHz) using ffmpeg.

Quick Install

curl -s https://raw.githubusercontent.com/rramesh/mp3converter/main/installer.sh | bash

This will:

  • Download the converter script to ~/.mp3c
  • Make it executable
  • Add to PATH (detects shell automatically)
  • Show usage instructions

Manual Installation

Install and make executable:

  1. Create directory and copy script:
mkdir -p ~/.mp3c
cp mp3converter ~/.mp3c/
chmod +x ~/.mp3c/mp3converter

Add to PATH:

For macOS (using zsh - default):

  1. Open ~/.zshrc and add: export PATH="$HOME/.mp3c:$PATH"
  2. Reload: source ~/.zshrc

For bash users (Linux or macOS):

  1. Open appropriate RC file:
    • Linux: ~/.bashrc
    • macOS: ~/.bash_profile
  2. Add: export PATH="$HOME/.mp3c:$PATH"
  3. Reload: source ~/.bashrc # or ~/.bash_profile on macOS

Requirements

  • 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.

Usage:

mp3converter [OPTIONS] PATH

Options:

-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.

Examples:

  • Convert directory /tmp/ddv to default settings (keeps original):

    mp3converter /tmp/ddv
    

    Creates: /tmp/ddv_16k/ (original /tmp/ddv remains unchanged)

  • Convert and replace original directory:

    mp3converter -r /tmp/ddv
    

    Converts to /tmp/ddv_16k/, then deletes /tmp/ddv and renames /tmp/ddv_16k to /tmp/ddv

  • Convert single file (keeps original):

    mp3converter ~/music/song.m4a
    

    Creates: ~/music/song_16k.mp3 (original .m4a remains unchanged)

  • Convert and replace original file:

    mp3converter -r ~/music/song.mp3
    

    Creates temporary song_16k.mp3, then replaces original song.mp3

  • Convert using different bitrate (keeps original):

    mp3converter -b 64k ~/music/
    

    Creates: ~/music_64k/ with converted files

  • Convert with custom settings and replace:

    mp3converter -b 32k -s 48k -r ~/music/
    

    Converts to ~/music_32k/ then replaces ~/music/

  • Dry-run to preview operations:

    mp3converter --dry-run -b 32k -r ~/music/
    

Behavior summary

  • 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

Notes:

  • 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.

About

Convert a directory containing audio files to mp3

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages