How to Split Audio File into Smaller Chunks on Your Mac

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!

split large audio file

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.

final result

Frequently Asked Questions:

How to change the length of each audio chunk?

Modify the chunk_length value in the script. For example, to make 5-minute chunks, set it to chunk_length=300 (5 minutes × 60 seconds). For 15-minute chunks, use chunk_length=900.

Can I split audio files in different formats?

Yes, FFmpeg supports various audio formats including WAV, M4A, AAC, and FLAC. Just change the input filename extension (e.g., input_file="audio.wav") and output format in the last line (e.g., "output/chunk_%03d.wav").

Where can I find the split audio files?

The script creates an ‘output’ folder in the same directory where your script is located. All split audio chunks will be saved there with names like chunk_001.mp3, chunk_002.mp3, etc.

How to uninstall Homebrew?

  1. Open the Terminal app on your Mac.
  2. Run this command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)".
  3. Follow the prompts and enter your password when asked.
  4. To verify the uninstallation, run brew --version – you should see a “command not found” error if successful.

How to uninstall FFmpeg?

Open the Terminal app on your Mac and run brew uninstall ffmpeg. Follow the prompts to complete the uninstallation process.

WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail