Using Sox as a file splitter

Several of my music albums are one file. Mainly flac files. I ve been trying to find a way to split an album into it s individual songs. After trying several gui apps with limmited success I discovered sox; a cli app . It uses the silence gap between each song as a starting/ending point, and it s very fast. It will split an album file in seconds. The command is as simple as this:

for i in *.flac; do sox $i $i -V3 silence 1 0.1 1% 1 1.0 1% : newfile : restart; done

My guess is it uses the for loop iteration and appends it to the original file name which is how the resulting files are named, (filename001, filename002
), so renaming is required after splitting. It doesn t like spaces in the file name, and in my case, it always makes an extra split as the last file which is a few kb in size. Other than that it works great. I was thinking of searching for a way to do the same thing with ffmpeg, but I found this app first. The good thing about it all is it s in the Arch repository.

4 Likes

It looks to be possible, but all the examples given are not pretty. Your current solution is likely more elegant :wink:

I had an old cli program that used to do it I think it was called cuesplit however it does depend on a cue file so this isn’t the exact same.

I was going to start a thread about Has Anyone Tried Flacon?

I have albums on a single mp3 and concerts on a singe mp4
how do these programs work? detect the lull then seperate etc? Or lotta manual intervention required?

Look forward to more replies on this.

ah so it does kinda sniff for a lull
wonder if it can do concerts as well. thanks for the tip. will experiment.

I can t imagine a program that could do it, but if it could listen for only a cheering crowd, and use that as a gap, instead of silence, then a concert seem feasible. I do know the length of silence setting can be tweaked, but not sure about the resolution of noise, or the ability to single out specific noise. There is probably an ai app that can do it.

Edit: Hahaha. As soon as I thought that I looked it up.

You know what would be interesting is if you could remove/split out the audience in a live album.

1 Like

The same command should work for mp3 files. I m not sure about mp4 unless the same silence gaps are present. Just change the extension in the command.

For .mp3:

for i in *.mp3; do sox $i $i -V3 silence 1 0.1 1% 1 1.0 1% : newfile : restart; done
1 Like

You were right asking exactly this! I’ve been using Flacon for ever and a while to cut FLAC “whole disc” RIPs (i.e., live), works great. You do need the correct .cue file, though. No problem if you ripped it yourself.

N.B.: Using silence detection can horribly fail, depending on the type of music. Learned that the hard way when writing Autocue to automatically cue songs for broadcasting, much like a Radio DJ would.

1 Like

question to both: what’s cue file and is this a separate element from the program? etc? thanks

A cue file basically tells where on the CD (or in the programme) which title plays/played, and contains title and performer info. Programs like whipper ode (on Windoze) EAC can generate such a file when ripping. It looks like so (this one taken from a 2019 broadcast, not from a CD):

TITLE "Velvet Viper Special (Wdh. v. 01.11.2019)"
PERFORMER "PapaBear"
FILE "aufzeichnung.2019-11-01.200024.mp3" MP3
  TRACK 01 AUDIO
    TITLE "FOX Sports Theme"
    PERFORMER "Opener"
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    TITLE "Confuse and Satisfy"
    PERFORMER "Velvet Viper"
    REM ALBUM "The Pale Man Is Holding A Broken Heart"
    INDEX 01 01:33:23
  TRACK 03 AUDIO
    TITLE "Rebirth by Fire"
    PERFORMER "Zodiac"
    REM ALBUM "Grain of Soul"
    INDEX 01 07:32:72
  TRACK 04 AUDIO
    TITLE "Build Me Up, Break Me Down"
    PERFORMER "Dream Theater"
    REM ALBUM "A Dramatic Turn of Events"
    INDEX 01 10:53:16
  TRACK 05 AUDIO
    TITLE "The Pale Man"
    PERFORMER "Zed Yago"
    REM ALBUM "Pilgrimage"
    INDEX 01 18:37:37
  TRACK 06 AUDIO
    TITLE "Teil 1"
    PERFORMER "Interview"
    INDEX 01 23:30:67
  TRACK 07 AUDIO
    TITLE "Samson and Delilah"
    PERFORMER "Velvet Viper"
    REM ALBUM "The Pale Man Is Holding A Broken Heart"
    INDEX 01 27:09:00
  TRACK 08 AUDIO
    TITLE "Father Time"
    PERFORMER "Oliva"
    REM ALBUM "Raise the Curtain"
    INDEX 01 33:00:60
  TRACK 09 AUDIO
    TITLE "Out of Control"
    PERFORMER "Mother Jane"
    REM ALBUM "Turn the Page"
    INDEX 01 38:09:06
  TRACK 10 AUDIO
    TITLE "Teil 2"
    PERFORMER "Interview"
    INDEX 01 42:54:42
  TRACK 11 AUDIO
    TITLE "Keep Your Head Up"
    PERFORMER "Velvet Viper"
    REM ALBUM "The Pale Man Is Holding A Broken Heart"
    INDEX 01 47:47:70
  TRACK 12 AUDIO
    TITLE "Sharp Dressed Man"
    PERFORMER "ZZ Top"
    REM ALBUM "Eliminator"
    INDEX 01 52:41:04
  TRACK 13 AUDIO
    TITLE "Das kann man ja auch mal so sehen"
    PERFORMER "Jutta Weinhold"
    REM ALBUM "Icebreaker - Best of"
    INDEX 01 57:26:04
  TRACK 14 AUDIO
    TITLE "On With the Show"
    PERFORMER "Y & T"
    REM ALBUM "Facemelter"
    INDEX 01 63:48:47
  TRACK 15 AUDIO
    TITLE "Teil 3"
    PERFORMER "Interview"
    INDEX 01 67:56:69
  TRACK 16 AUDIO
    TITLE "The Wheel Has Come Full Circle"
    PERFORMER "Velvet Viper"
    REM ALBUM "The Pale Man Is Holding A Broken Heart"
    INDEX 01 72:22:28
  TRACK 17 AUDIO
    TITLE "MĂ€dchen"
    PERFORMER "Jutta Weinhold"
    REM ALBUM "Icebreaker - Best of"
    INDEX 01 78:16:52
  TRACK 18 AUDIO
    TITLE "Chicks = Trouble"
    PERFORMER "Mötley CrĂŒe"
    REM ALBUM "Saints of Los Angeles"
    INDEX 01 82:44:66
  TRACK 19 AUDIO
    TITLE "Teil 4"
    PERFORMER "Interview"
    INDEX 01 85:59:27
  TRACK 20 AUDIO
    TITLE "Something Is Rotten"
    PERFORMER "Velvet Viper"
    REM ALBUM "The Pale Man Is Holding A Broken Heart"
    INDEX 01 90:31:50
  TRACK 21 AUDIO
    TITLE "Ghost"
    PERFORMER "Slash feat. Ian Astbury"
    REM ALBUM "Slash"
    INDEX 01 96:19:06
  TRACK 22 AUDIO
    TITLE "Still of the Night"
    PERFORMER "Whitesnake"
    REM ALBUM "30th Anniversary Collection"
    INDEX 01 100:36:39
  TRACK 23 AUDIO
    TITLE "Respice Finem"
    PERFORMER "Velvet Viper"
    REM ALBUM "Respice Finem"
    INDEX 01 107:39:62
  TRACK 24 AUDIO
    TITLE "Thanks for the Night"
    PERFORMER "Big Daddy Wilson & Doc Fozz"
    REM ALBUM "...doin' it right"
    INDEX 01 118:57:28

This works good even with classical music and live CDs, since it can handle CD track and index information. Which, in turn, Flacon can pick up and do exact cuts. :slight_smile:

Later on, if you have a player that can do “gapless playing” (like Lyrion), you can even listen to a complete album again without any interruptions when the track file changes.

Note you should use FLAC (or WAV) as source material. Cutting MP3s in an inexact thing due to its nature. (But still possible.)

1 Like

thanks for that explanation and demo. I get it better as far as this file. Sounds like a master file you have to keep. Hopefully you don’t have to treat it like a config file.
“A Pale Man is Holding a Broken Heart” is a hell of a title, but I get distracted easy and my mind keeps replacing the word ‘man’ with ‘moon’ it fits better to me.

There’s an easy rule: If you keep the full-length file (CD, concert, broadcast, 
), also keep the .cue file. Because some programs can actually also play directly from the big file + a cue file. Lyrion can, and I believe mpd and beets also, maybe more.

If you only keep the cut single tracks, you don’t need to keep the .cue file. I normally do that, because I use FLAC anyway, and we have gapless playback, so all good.

Btw, sox is of course also a great tool for many things. I use that (with a little script) to quickly produce simple jingles for radio shows.

1 Like

I appreciate you experience in this matter. In my case sox worked perfectly for me. Maybe it was the fact that, in my case, I was working with studio albums, and there were definite silence gaps. You have intrigued me though. I will be researching Flacon now :face_with_monocle:

1 Like

It’s necessary if you want to recreate the audio CD, and many audio/music players can manage long track+cue file.

A cli alternative to Flacon is unflac (in the AUR.), I used it several times and it works great.

4’33’’ from John Cage would be a tough challenge.
Especially if you only want to listen to one of the three parts. :wink:

3 Likes

especially if there is no silence between tracks several albums/songs out there really don’t have silence as the transitioner.

Waiting for the bus/Jesus left chicago by ZZ comes to mind.

excellent observation. lots of avant garde stuff would fail

I got some playing around ahead of me.

1 Like

I got some playing around ahead of me.

Always a good way to learn. :wink:

You can of course also listen to it (or use Audacity to get timings) and write your own .cue file—it’s just a text file after all. I actually did that for a live recording once, where we of course had no cue file.

Read more here: https://en.wikipedia.org/wiki/Cue_sheet_(computing)

1 Like

I ve loved that particular transition every since I first heard it. :+1:

2 Likes

just went back and listened to it. It’s about 1/10th of a second if I had to guess. Probably much less. it’s a pause but oh-so-tiny. Don’t know if Sox would detect it.

U2–back when they were good in the 80’s–did this with An Cat Dubh and Into the Heart but they bled both songs into each other so it would be undetectable.
But I digress.

1 Like

Then again, it’s nice to read a little digression by music lovers! Life is not only about ricing your install
 seeing people use their systems to make life more enjoyable just feels
 right.

:dvd: :musical_keyboard: :musical_note:

1 Like