6

I have a music album, but whole album is in single flac file and tracks are listed in cue file. So I'd like to split it into tracks, but also fill the id3 tags and name files by track name.

9

Install reaquired packages on Debian (Ubuntu):

sudo apt-get install cuetools shntool flac

Split flac file and fill id3 tags:

cuebreakpoints sample.cue | shnsplit -o flac sample.flac
cuetag sample.cue split-track*.flac

Some systems has cuetag.sh instead of cuetag.

| improve this answer | |
  • 5
    Can you explain what these commands do? Not everyone knows what these commands are or how to use them. – bwDraco Mar 31 '12 at 11:31
  • 1
    They're installed with cuetools. Read the man page. – Rob Apr 8 '12 at 17:19
  • shnsplit, which takes a single audio file and provides a mechanism for splitting and transcoding it, can actually read cue files directly. -f specifies the split point source, -o specifies the output format. cuetag on the other hand, automatically runs the appropriate tagging program for a given format based on the content of a cue file. Since id3 tags were specified in the question, one could change -o flac to -o mp3, and use cuetag sample.cue split-track*.mp3 instead. – Jeremy Sturdivant Oct 14 '12 at 15:50
0

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);
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.