Stochastic Nonsense

Put something smart here.

Splitting Audio With Ffmpeg

Here’s a quick utility to use a set list and ffmpeg to split single audio files into multiple tracks. It splits audio files via a setlist then sets the song name, artist, album id3 tags. The script is crude, but it’s a quick start.

I used this to split a couple concerts by two of my favorite artists: James McMurtry in Concert July 14 2013 and Ray Wylie Hubbard in Nashville, TN performing tracks from A. Enlightenment B. Endarkenment (Hint: There is no C). You can find the set lists below.

(splitter.py) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# use ffmpeg to split an mp3 according to a set list
from __future__ import print_function
import subprocess as sp

# NB: add -copy if from mp3 -> mp3; else no -copy
setfile = './Ray Wylie Hubbard in Concert -  December 17, 2010 at Tennessee State Museum.set'
mp3file = './Ray Wylie Hubbard full concert - DASH.m4a'
outdir = './Ray Wylie Hubbard in Concert -  December 17, 2010 at Tennessee State Museum'
meta_src = 'https://www.youtube.com/watch?v=y9_xBIuV9nE'
do_copy = False
print('splitting \'%s\' according to sets in \'%s\' into directory \'%s\'' % (mp3file, setfile, outdir))

metas = {'artist':'Ray Wylie Hubbard', 'album':'Acoustic Live in Concert December 17 2010 at Tennessee State Museum / Hippie Jacks'}
metastring = ' '.join([ '-metadata %s="%s"' % (k,v) for k,v in metas.iteritems()])

songs = []
with open(setfile) as f:
  for line in f:
    start, title = line.strip().split(' ', 1)
    songs.append((start, title))

print('read %d lines' % len(songs))

# set id3 tags ala http://jonhall.info/how_to/create_id3_tags_using_ffmpeg
cmds = []
for i in range(len(songs) - 1):
  cmd = (songs[i][0], songs[i+1][0], songs[i][1])
  cmds.append(cmd)

  run = 'ffmpeg -i \"%s\" -acodec %s -ss %s -to %s ' % (mp3file, 'copy' if do_copy else 'libmp3lame -qscale:a 2', cmd[0], cmd[1])
  run += '%s -metadata title="%s" -metadata track="%d/%d" -metadata publisher="%s" ' % (metastring, cmd[2], i+1, len(songs) - 1, meta_src)
  run += '"%s/%02d.mp3"' % (outdir, i + 1)
  # print("\tcmd: %s" % run)
  sp.call(run, shell=True)

You’ll have to adjust params at the top of splitter.py:

  • setfile is the set file
  • mp3file is the audio file
  • outdir is the output directory (you should probably mkdir this beforehand)
  • meta_src is the source
  • do_copy should be True if your source is an mp3 file and False if you want to transcode to mp3
  • replace artist and album in metas

Then just run it: python splitter.py.

(James_McMurtry_in_Concert_-__July_14,_2013.set) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
00:00:00 chirping
00:00:48 Bayou Tortous
00:05:04 Red Dress
00:11:00 talking / tuning
00:11:52 What's the Matter Now
00:16:09 talking / real sensitive little love ballads and baptists
00:17:18 How'm I Gonna Find You Now
00:21:28 talking / buy cds
00:22:09 Just Us Kids
00:27:00 applause
00:27:27 You'd A' Thought (Leonard Cohen Must Die)
00:33:34 clapping and get ready to dance
00:33:47 Choctaw Bingo (with new verse) (introduction)
00:34:30 Choctaw Bingo (with new verse)
00:46:22 applause / belly rubbing dances
00:46:49 These things i've come to know
00:50:26 talking / introduction to the band / unfortunately song still relevant
00:51:44 We Can't Make it Here Anymore
00:58:37 talking about ice fishing and Tim Holt
00:59:37 Copper Canteen
01:04:22 talking / back to stompin' songs
01:04:41 Freeway View
01:08:03 talking / feral hogs in michigan
01:08:33 Lobo Town
01:14:00 applause
01:14:07 Restless
01:19:17 talking / goes out to memory of max crawford
01:20:02 Levelland
01:26:40 talking / thanks crowd / reminds crowd to bring whiskey / be nice to the nice officer
01:28:21 Too Long in the Wasteland
01:35:36 applause
01:35:50 Lights of Cheyenne (acoustic)
01:41:51 thanks and watch for deer (god bless wisconsin)
01:42:42 finit
(Ray_Wylie_Hubbard_in_Concert_-__December_17,_2010_at_Tennessee_State_Museum.set) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
00:00:00 hippie jacks intro
00:03:03 talking / rwh enters
00:03:18 Count My Blessings
00:06:43 talking / glad to be here / band on weekend work release
00:07:09 Rabbit
00:10:02 talking / get what you pay for
00:10:23 Snake Farm
00:14:14 talking / Hayes Carll / smell
00:16:18 Drunken Poet's Dream
00:20:00 talking / get more attention burning down a barn
00:21:29 Down Home Country Blues
00:24:18 talking / hardly strictly bluegrass / commitment
00:26:25 The Ballad of the Crimson Kings
00:30:57 talking / Without Love banter
00:32:40 Without Love
00:36:28 tuning
00:36:43 Dust of the Chase
00:40:50 applause / talking / tuning / remembering Mambo John Traynor
00:43:30 Name Droppin'
00:46:44 talking / ain't no rock and roll roosters
00:47:30 Rooster
00:50:12 talking / gambler and a drinker's gold bullet
00:52:35 Mississippi Flush
00:56:39 talking / no name dropping / slaid cleaves / turned it over to the da
00:59:34 Conversation With the Devil
01:03:30 talking / hard core serious hillbilly redneck country bar
01:05:37 Redneck Mother
01:09:26 talking / ralph stanley and bill monroe
01:11:00 Wanna Rock and Roll
01:14:03 talking / band should get instruments and learn to play 'em
01:15:03 The Messenger
01:19:38 talking / thank you
01:20:43 Mother Hubbard's Blues
01:27:13 thanks / post show
01:29:05 finit