How to Split Audio File into Smaller Chunks on Your Mac
How to easily split audio files into smaller chunks on your Mac with our step-by-step guide, using simple bash script.
Have you ever had a long audio file that you wanted to break down into smaller, more manageable pieces? If so, you’re in luck because it’s actually a pretty easy task!
In this article, I’m going to show you how to use a simple bash script on your Mac to split your audio file into several smaller files, each around 8-10 minutes long, or basically any length you want. So let’s get started!
Prerequisite
To get this to work, your Mac will need these two components installed, Homebrew and FFmpeg.
How to Install Homebrew
Install Homebrew if you haven’t already; you can do this by opening a Terminal window and entering the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
How to Install FFmpeg
Once Homebrew is installed, run the following command to install FFmpeg:
brew install ffmpeg
Wait for the installation to complete, which it will take a while, and FFmpeg will be ready to use.
Splitting an Audio File into Smaller Chunks
With both Homebrew and FFmpeg installed, we are now ready to split the large audio file into smaller pieces.
Step 1.
Open your favorite code editor, paste the following bash script into it, and save it as ‘splitaudio.sh‘.
#!/bin/bash # Define the path to the input MP3 file input_file="file.mp3" # Define the length of each chunk in seconds (480 seconds = 8 minutes) chunk_length=480 # Create an output directory to store the chunks mkdir -p output # Use ffmpeg to split the MP3 file into chunks ffmpeg -i "$input_file" -f segment -segment_time "$chunk_length" -c copy "output/chunk_%03d.mp3"
Step 2.
Replace file.mp3
in input_file="file.mp3"
with the name of your audio file.
Examples:
Filename is ‘meeting.mp3‘ |
input_file="meeting.mp4" |
Filename is ‘meeting.mp3‘, inside ‘audio‘ folder |
input_file="audio/meeting.mp4" |
Chunk_length
decides how long each output audio file should be, in seconds. If you want them to be 10 minutes each, then your chunk_length
should be 600.
The final line in the code determines where each chunk of the audio file will be saved, and its file naming prefix.
ffmpeg -i "$input_file" -f segment -segment_time "$chunk_length" -c copy "output/chunk_%03d.mp3".
In our code, the output filename pattern output/chunk_%03d.mp3
, which will save each chunk in the ‘output‘ directory with a filename of chunk_001.mp3, chunk_002.mp3, and so on.
Step 3.
Make sure all changes in ‘splitaudio.sh‘ is saved, if you haven’t already. Next, we will need to make it executable.
In Terminal, type in the following command and hit Enter.
chmod +x splitaudio.sh
Step 4.
Finally, run the bash script with the following command:
/splitaudio.sh
That’s it. You should have your audio file split into smaller chunks, and saved inside the output folder.
FAQ:
1. How to uninstall Homebrew?
- Open the Terminal app on your Mac.
- Type the following command and hit Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
- Follow the prompts to uninstall Homebrew. You may be asked to enter your password.
- Once the uninstallation process is complete, you can verify that Homebrew has been uninstalled by typing the following command in the Terminal and hitting Enter:
brew --version
If Homebrew has been uninstalled successfully, you should see a “command not found” error message.
2. How to uninstall FFmpeg?
Open the Terminal app on your Mac and type in the following command.
brew uninstall ffmpeg
Follow the prompt to complete the uninstallation process.