29

I have some .flac albums I ripped as one big file to save some space (Lossless CD rips are roughly 500MB each). Now that I have more storage I would like to split them back to their original files.

Is there a native .flac/.cue splitter for Debian-based systems?

I found some information but it is either old, just for mp3 or using Wine, and this is not what I want.

Also I found a Nautilus script, but I don't think this will be lossless, also it only performs a very specific task and I'd like some customization options.

Can anyone provide a lossless FLAC .cue splitter with native support, and a lot of conversion options?

Please no Wine.

8 Answers 8

42

First you need to install cuetools and shntool. From the terminal type:

sudo apt install cuetools shntool flac

To split a flac file back to the original files using a .cue file:

cuebreakpoints '<cue file>' | shnsplit -o flac '<audio flac file>'  

You can drag the cue file and the audio flac file from the file manager into the terminal in order to autocomplete the paths for '<cue file>' and '<audio flac file>'. When you run the command, the terminal will show you the results of each new flac file as it is created, one new flac file at a time ("split-track01.flac" "split-track02.flac" ...), and then stop after all of the new flac files have been created. It only takes a few seconds to create each new flac file. If your .cue file is accurate, the results will be more accurate and less time-consuming than if you split the flac file manually in Audacity.

6
  • 2
    Thanks Karel this worked great, very fast and accurate, just what I need. There was a small bug that I encountered. THIS IS JUST FOR ANYONE WHO HAS THE SAME ERROR - shnsplit: error: m:ss.ff format can only be used with CD-quality files - USE THIS MODIFIED CODE - cuebreakpoints '<cue file>' | sed s/$/0/ | shnsplit -o flac '<audio flac file>'
    – Mark Kirby
    Sep 8, 2014 at 6:51
  • 1
    How To Install Flacon 1.0.1 On Ubuntu 14.10, Ubuntu 14.04, Ubuntu 12.04 And Derivative Systems. Flacon is a GUI front-end to shnsplit that can be installed from a PPA. I haven't used it myself, because flacon in essence requires adding a PPA to software sources in order to replace running one line of bash from the terminal and I prefer to copy and paste that line of code over adding the PPA for flacon to my software sources.
    – karel
    Apr 11, 2015 at 7:34
  • 4
    After splitting, you may want to run cuetag CUE_FILE split-track*.flac to add tags from the cue file to the splitted tracks.
    – mivk
    Apr 26, 2015 at 13:08
  • I also needed sudo apt-get install flac
    – a06e
    Mar 28, 2016 at 10:14
  • 11
    I'd rather suggest shnsplit -o flac '<audio flac file>' -f '<cue file>' -t '%n.%t' to get sensible file names.
    – gluk47
    Aug 13, 2016 at 6:23
18

There is an app called Flacon which does exactly this.

To install:

sudo add-apt-repository ppa:flacon
sudo apt-get update
sudo apt-get install flacon

enter image description here

5
  • hey thanks... for the edits, i should have point out the install commands indeed Jan 24, 2017 at 12:33
  • flacon works 100% is amazing thank you!
    – user56673
    Mar 6, 2017 at 19:26
  • 2
    Works very well on linux mint as well! Donated some $ to author! Oct 25, 2017 at 7:32
  • I guess this is the standard solution and not the accepted answer, at least i think that the question was referring to a GUI program (hence the wine mention) Oct 25, 2017 at 13:51
  • Glad I looked beyond the accepted answer. This seems like a winner! Apr 3, 2021 at 4:03
7

I needed to split large flac and set file name and tag from the cue file, and this worked best for me:

  1. cd to a folder with one pair of cue and flac
  2. type this: shnsplit -f *.cue -t "%n - %p - %t" -o "flac flac -s -8 -o %f -" *.flac
  3. delete the original flac file
  4. tag the files using: cuetag *.cue *.flac

Example of output:

Splitting [Edvard Grieg - Complete Songs Vol.III.flac] (76:03.40) --> [25 - Edvard Grieg - Sighs, EG 134.flac] (2:43.08) : 100% OK

reference: CUE_Splitting

UPDATE

I wrote the following script for my convenience. To use it - cd to a directory with one pair of matching ape and cue files.

mkdir -p orig
mv *ape orig/.
shnsplit -f *.cue -t "%n - %p - %t" -o "flac flac -s -8 -o %f -" orig/*.ape
rm -f 00*
cuetag *.cue *.flac
#fix bad file names
find . -exec rename 's/[^\x00-\x7F]//g' "{}" \;

name this script as split_ape, chmod +x it and put in some directory in your path. I made a similar script for flac file as source, just replace every ape with flac in this script.

0
3

The easiest way is using K3B.

1.- Open the CUE file in K3B. 2.- Choose convert tracks to FLAC. 3.- Press Start.

It will not re-convert the tracks but only split them into tracks according to the CUE file. It will keep the original name of each track and it takes second to complete the "convertion/split".

2
  • K3B requires KDE, which is unlikely to be present on a Debian system.
    – user58203
    May 21, 2015 at 19:59
  • 2
    K3B can be installed easily via the Ubuntu Software Center as any other KDE program. They just don't look as good as integrated GNOME apps but they work perfectly. Jun 9, 2015 at 19:22
2

and for flac:

    cat file.cue | shnsplit -o flac -t %n-%t file.flac

split the flac file and add to the resulting files track number (%n) and title name (%t)

2
  • 2
    Please explain what this command does.
    – Pilot6
    Oct 2, 2015 at 17:16
  • @Pilot6 I add an explanation to my answer, I hope is helpful. For more details you can "man shnsplit".
    – mdneagu
    Oct 3, 2015 at 8:14
2

You can split CUE file into separate FLAC tracks using fmedia (http://fmedia.firmdev.com) with a single command:

fmedia YOUR_FILE.cue --out='$tracknumber. $artist - $title.flac'

With this command you'll split all tracks from one CUE file into separate FLAC files named like "01. ARTIST - TITLE.flac". Note, that the output files will have exactly the same audio quality and track duration precisely as the original.

Or you may copy just one track from the .cue file:

fmedia YOUR_FILE.cue --out='$tracknumber. $artist - $title.flac' --track=7

You can also overwrite meta information during the splitting, e.g.:

fmedia YOUR_FILE.cue --out=mytrack.flac --meta='artist=COOL ARTIST'

fmedia has minimum external dependencies (i.e. cuetools, libFLAC, etc. are NOT needed to be installed on your system), it works on 64-bit Debian-based systems, but it doesn't work on 32-bit systems.

2

Here is a PHP script:

<?php
$s_cue = $argv[1];
$a_cue = file($s_cue);
$n_row = -1;
foreach ($a_cue as $s_row) {
   $s_trim = trim($s_row);
   $a_row = str_getcsv($s_trim, ' ');
   if (preg_match('/^FILE\s/', $s_row) == 1) {
      $s_file = $a_row[1];
   }
   if (preg_match('/^\s+TRACK\s/', $s_row) == 1) {
      $n_row++;
      $a_table[$n_row]['track'] = $a_row[1];
   }
   if (preg_match('/^\s+TITLE\s/', $s_row) == 1) {
      $a_table[$n_row]['title'] = $a_row[1];
   }
   if (preg_match('/^\s+PERFORMER\s/', $s_row) == 1) {
      $a_table[$n_row]['artist'] = $a_row[1];
   }
   if (preg_match('/^\s+INDEX\s/', $s_row) == 1) {
      $s_dur = $a_row[2];
      $a_frame = sscanf($s_dur, '%d:%d:%d', $n_min, $n_sec, $n_fra);
      $n_index = $n_min * 60 + $n_sec + $n_fra / 75;
      $a_table[$n_row]['ss'] = $n_index;
      if ($n_row > 0) {
         $a_table[$n_row - 1]['to'] = $n_index;
      }
   }
}
$a_table[$n_row]['to'] = 10 * 60 * 60;
foreach ($a_table as $m_row) {
   $a_cmd = [
      'ffmpeg',
      '-i', $s_file,
      '-ss', $m_row['ss'],
      '-to', $m_row['to'],
      '-metadata', 'artist=' . $m_row['artist'],
      '-metadata', 'title=' . $m_row['title'],
      '-metadata', 'track=' . $m_row['track'],
      $m_row['track'] . ' ' . $m_row['title'] . '.m4a'
   ];
   $a_esc = array_map('escapeshellarg', $a_cmd);
   $s_esc = implode(' ', $a_esc);
   system($s_esc);
}
1

Install shntool

sudo apt-get install shntool

If you wish to automatically preserve file names, you can simply use:

cat infile.cue | shnsplit -t "%n - %p - %t" infile.wav
1
  • I tried this on flac file, but one 240MB file turned to files with total of 780MB after splitting. probably can be fixed with a -o flag
    – Amir Uval
    May 9, 2016 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .