1. Overview

In this article, we’ll learn how to split an MP3 track in Linux losslessly. We’ll use FFmpeg to extract a portion of the audio based on timestamps. Next, we’ll cover the SoX utility for the same purpose.

Finally, we’ll cover the powerful mp3splt utility to split an MP3 track into many individual tracks.

2. FFmpeg

FFmpeg is a powerful tool that converts and manipulates multimedia files. It allows us to cut or split MP3 files without re-encoding the audio. Thereby, the audio quality remains intact without degradation.

In addition, the cutting process is almost instant because no re-encoding is involved. In the next section, we’ll use several ways to cut MP3 files with FFmpeg.

2.1. Time Range

We can split the file by specifying the start and end timestamps:

$ ffmpeg -i demo.mp3 -vn -acodec -ss 00:00:10 -to 00:00:30 demo-cut.mp3

Let’s break this down:

  • -i specifies the path to the input file
  • -vn stands for “no video”, which implies that we’re working with audio only
  • -acodec copy copies the source audio codec to the output file
  •  -ss sets the timestamp to cut the audio from
  • -to specifies the ending timestamp
  • demo-cut.mp3 is the output name

Notably, the duration for the output file will be 20 seconds. Besides, the timestamp is in the hh:mm:ss format. We can also specify the milliseconds like hh:mm:ss.mmm.

2.2. Duration

We can also specify the duration of the cut from the start timestamp:

$ ffmpeg -i demo.mp3 -vn -acodec copy -ss 00:00:00 -t 00:01:50 demo-cut.mp3

The -t option specifies the duration. In this case, the cut will be a minute and 50 seconds long. In addition, if the cut duration is higher than the audio duration, then FFmpeg will cut the audio till the end of the track.

2.3. Omission of End Time

By omitting the ending timestamp and duration, FFmpeg will effectively cut the audio till the end:

$ ffmpeg -i demo.mp3 -vn -acodec copy -to 00:01:00 demo-cut.mp3

As we can see, it’s a relatively straightforward approach to specifying a long, arbitrary duration.

2.4. Omission of Start Time

In contrast, we can also omit the start time:

$ ffmpeg -i demo.mp3 -vn -acodec copy -to 00:01:00 demo-cut.mp3

Omitting the start time implies the timestamp to be 00:00:00.

3. SoX

SoX is an audio processing utility that can manipulate and convert audio files. Besides, it’s also capable of trimming audio files.

Let’s create a 20 seconds audio out of demo.mp3:

$ sox demo.mp3 demo-cut.mp3 trim 10 20

Let’s examine closely:

  • demo.mp3 is the input
  • demo-cut.mp3 is the output
  • trim is an action that cuts an audio track
  • 10 is the start time in seconds
  • 20 is the duration in seconds

It efficiently cuts the audio without re-encoding. Therefore, we get a lossless cut of the source. Moreover, we can also apply audio effects like adding a volume boost to the cut track:

$ sox demo.mp3 demo-cut.mp3 vol 2.0 trim 10 20

In the command, vol 2.0 will increase the audio volume by a factor of 2.

4. mp3splt

mp3splt is a special utility that splits MP3 audio into multiple tracks. It has a lot of options for splitting MP3 files.

4.1. Splitting a Track Into Many

mp3splt is magical. Not only can it trim the audio, but it can also automate the cutting process. It means that if we have a long MP3 file, we can specify criteria for splitting the file into many individual tracks.

For instance, we can specify a silence threshold to split an MP3 file:

$ mp3splt -o @f_@n -f -p silence -t 0.5 -c demo.mp3

Let’s dig into this:

  • -o specifies a template for output files:
    • @f is the filename without an extension
    • @n is the track number
  • -f overwrites existing files with the same name without prompts
  • -p silence sets the criteria for splitting the audio based on a period of silence
  • -t 0.5 specifies the period of silence, which is 500 milliseconds
  • demo.mp3 is the input file

The tracks will be named demo_n.mp3, which is the number of tracks we can quickly burn to a CD. Furthermore, the process does not affect the quality of the tracks because the tracks aren’t re-encoded.

4.2. Bisecting a Track

We can split down an MP3 into two equal parts that will have the same duration:

$ mp3splt -o @n -f -S +2 demo.mp3

-S +2 effectively splits the file into two equal parts in terms of duration: 1.mp3 and 2.mp3. Let’s verify this:

$ mediainfo --Inform="General;%FileName%.%FileExtension%: %Duration/String2%\n" 1.mp3 2.mp3
1.mp3: 1 min 6 s
2.mp3: 1 min 6 s

4.3. Time Range

mp3splt is also capable of splitting audio based on given timestamps:

$ mp3splt -o demo-cut 00.30 00.50 demo.mp3

We gave the timestamps in the form of mm.ss for the cut. Therefore, the resulting audio will be 20 seconds long.

5. Conclusion

In this article, we explored the various possibilities to cut audio files. We used FFmpeg as well as SoX to trim an MP3 track. Lastly, we covered mp3splt to create many tracks from an MP3 file using specific criteria.

Comments are closed on this article!