M4A <-> MP3 Audio Converter
Overview
Bidirectional audio format converter between M4A and MP3 using ffmpeg as the backend engine. The script auto-detects the input format from the file extension and converts to the opposite format — .m4a files become .mp3 (using libmp3lame encoder), .mp3 files become .m4a (using AAC encoder). Supports single-file and batch directory conversion with configurable bitrate, sample rate, and output paths. The conversion script auto-resolves the ffmpeg binary — if system ffmpeg is not installed, it automatically falls back to the imageio-ffmpeg package which bundles a static ffmpeg binary.
When to Use
Trigger this skill when the user:
- Asks to convert M4A files to MP3 format
- Asks to convert MP3 files to M4A format
- Has audio files in M4A/AAC format that need MP3 compatibility
- Has MP3 files that need to be converted to M4A/AAC format
- Wants to batch convert a folder of audio recordings between formats
- Needs to change audio bitrate or sample rate during conversion
- Mentions keywords: M4A转MP3, MP3转M4A, 音频转换, 格式转换, convert m4a to mp3, convert mp3 to m4a, audio conversion
Prerequisites
The script auto-resolves ffmpeg in this order:
- System ffmpeg — if
ffmpegis available in PATH, use it directly. - imageio-ffmpeg — if system ffmpeg is missing, the script auto-installs the
imageio-ffmpegpip package, which bundles a static ffmpeg binary. No manual installation required.
No user action is needed — the script handles everything automatically.
Conversion Direction (Auto-Detected)
| Input Format | Output Format | Encoder | Container |
|---|---|---|---|
| .m4a / .aac | .mp3 | libmp3lame | MP3 |
| .mp3 | .m4a | aac | MP4 (ipod) |
The direction is automatically determined from the input file extension. No flag needed.
Conversion Script
The core conversion logic is in scripts/m4a_to_mp3.py. Execute it with Python:
python scripts/m4a_to_mp3.py <input> [options]
Key Options
| Option | Flag | Default | Description |
|---|---|---|---|
| Input | (positional) | — | Audio file (.m4a or .mp3) or directory path |
| Output | -o |
Same name, target ext | Output file or directory |
| Bitrate | -b |
192 | Bitrate in kbps (64/96/128/160/192/256/320) |
| Sample rate | -s |
Original | Audio sample rate in Hz (22050/32000/44100/48000/96000) |
| Recursive | -r |
Off | Recursively scan subdirectories |
| Overwrite | -f |
Off | Overwrite existing files |
| Quiet | -q |
Off | Suppress detailed output |
| Output dir | -d |
— | Batch output directory (preserves structure) |
| Input format | --input-format |
Both | Filter batch by input format (mp3 or m4a) |
Workflow
Step 1: Identify Input and Direction
Determine what the user wants to convert:
- Single file: User provides a specific audio file path. Direction is auto-detected from extension.
- Batch: User provides a directory path. By default, both .m4a and .mp3 files are converted to the opposite format. Use
--input-format mp3or--input-format m4ato filter. - Ask whether to scan subdirectories recursively if not specified.
Step 2: Determine Output Settings
Confirm or infer these settings based on user requirements:
- Output location: Same directory as source, or a custom output directory
- Bitrate: Default 192kbps is good for most use cases. Use 320kbps for high quality, 128kbps for smaller files
- Sample rate: Default preserves original. Specify if the user needs a specific rate
- Overwrite: Ask the user if existing files should be overwritten
Step 3: Execute Conversion
Run the conversion script with the appropriate arguments:
# Single M4A -> MP3 (auto-detected)
python scripts/m4a_to_mp3.py "/path/to/audio.m4a" -o "/path/to/output.mp3" -b 192
# Single MP3 -> M4A (auto-detected)
python scripts/m4a_to_mp3.py "/path/to/audio.mp3" -o "/path/to/output.m4a" -b 256
# Batch M4A -> MP3 (recursive, to custom output directory)
python scripts/m4a_to_mp3.py "/path/to/m4a_folder/" -r -d "/path/to/mp3_output/" -b 320 -f
# Batch MP3 -> M4A only
python scripts/m4a_to_mp3.py "/path/to/folder/" -r --input-format mp3 -d "/path/to/m4a_output/"
# Batch both directions (default), same directory, overwrite
python scripts/m4a_to_mp3.py "/path/to/folder/" -r -f
Step 4: Report Results
After conversion, report to the user:
- Number of files successfully converted
- Number of files that failed (if any)
- Output file locations
- Conversion direction (which format to which format)
- Any errors encountered
Common Use Cases
Convert a single M4A file to MP3
python scripts/m4a_to_mp3.py "C:/Users/me/recording.m4a"
Output: C:/Users/me/recording.mp3 (same directory, 192kbps, libmp3lame)
Convert a single MP3 file to M4A
python scripts/m4a_to_mp3.py "C:/Users/me/song.mp3"
Output: C:/Users/me/song.m4a (same directory, 192kbps, AAC)
Batch convert M4A folder to MP3
python scripts/m4a_to_mp3.py "C:/Users/me/Music/" -r -d "C:/Users/me/Music_MP3/" -b 320
Recursively converts all .m4a files, outputs to Music_MP3/ preserving folder structure, at 320kbps.
Batch convert MP3 folder to M4A
python scripts/m4a_to_mp3.py "C:/Users/me/Music/" -r --input-format mp3 -d "C:/Users/me/Music_M4A/" -b 256
Recursively converts only .mp3 files to .m4a, outputs to Music_M4A/.
Quick conversion with overwrite
python scripts/m4a_to_mp3.py "C:/recordings/" -r -f -q
Converts all audio files in recordings/ and subfolders, overwrites existing files, quiet mode.
Error Handling
The script handles common errors gracefully:
- ffmpeg not found: Auto-installs
imageio-ffmpegpackage as fallback - Unsupported input format: Reports error and skips to next file in batch mode
- Input file not found: Reports error and skips to next file in batch mode
- Conversion timeout: 10-minute timeout per file, reports the failed file
- Output file exists: Skips by default, use
-fto overwrite - Permission errors: Reports the specific error for diagnosis
Technical Notes
- M4A to MP3: Uses
libmp3lameencoder, the standard high-quality MP3 encoder - MP3 to M4A: Uses
aacencoder with MP4 (ipod) container format - .aac files: Treated as M4A-compatible input (same AAC codec, converted to MP3)
- Metadata (ID3 tags) from the source file is preserved during conversion
- The script works on Windows, macOS, and Linux
- For very large batch jobs, the script processes files sequentially to avoid memory issues