IPB

Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
Help with shntool !, need to create a cuesheet file from existing WAV file
krafty
post Aug 18 2011, 00:33
Post #1





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



This is what I want to achieve:

I want shntool to output a cuesheet with automatic placement of tracks of a given length, using an existing WAV file.
I was playing with it and I was able to split the WAV file itself in slices of 1:00 minute each, but it gave me several files. What I want is the same thing but output to a cuesheet. Any help from the non-unix and unix experts will be appreciated!
Go to the top of the page
+Quote Post
DVDdoug
post Aug 18 2011, 01:16
Post #2





Group: Members
Posts: 2534
Joined: 24-August 07
From: Silicon Valley
Member No.: 46454



I don't know how to do that automatically, but if you had started typing into a text editor, you'd be done by now! wink.gif

If you want to do that with a 1000 minute file, I suppose you could use a spreadsheet to increment the times, and save-as a text file (and rename to .CUE).
Go to the top of the page
+Quote Post
krafty
post Aug 18 2011, 01:25
Post #3





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



I'm thinking about a bash script....
Go to the top of the page
+Quote Post
mjb2006
post Aug 18 2011, 03:39
Post #4





Group: Members
Posts: 755
Joined: 12-May 06
From: Colorado, USA
Member No.: 30694



You were on the right track. shntool's cue sheet generator needs separate files as input, so splitting was the right thing to do.
  1. shntool split -q -l 1:00 "audio.wav"
  2. shntool cue split-track*.wav > audio.cue
  3. del split-track*.wav

You could combine the first two commands into one:
  • shntool split -q -l 1:00 "audio.wav" && shntool cue split-track*.wav > audio.cue

I'm not sure if you can do the del after that on the same line. Anyone?

If you needed to do it with an MP3 instead of a lossless source, then this is how I'd do it:
  1. Load the MP3 in mp3DirectCut.
  2. Special > Auto Cue (Shift+Ctrl+A).
  3. Enter 1:00 when prompted.
  4. Special > Save Cue Sheet and edit with Notepad.
  5. In the cue sheet, change MP3 to WAVE and change FILE to point to the .wav (and make whatever other edits you need).
  6. Close mp3DirectCut without saving, and delete the MP3.


This post has been edited by mjb2006: Aug 18 2011, 03:48
Go to the top of the page
+Quote Post
krafty
post Aug 18 2011, 16:39
Post #5





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



QUOTE
I'm not sure if you can do the del after that on the same line. Anyone?


I just did it... (I'm on Linux so that could explain if Windows didn't let you?)


shntool split -q -l 1:00 "policy.wav" && shntool cue split-track*.wav > policy.cue && rm split-track*.wav

Now the issue is... to rename the "joined.wav" FILE statement within the cuesheet to inherit the intended WAV filename!

This post has been edited by krafty: Aug 18 2011, 16:40
Go to the top of the page
+Quote Post
krafty
post Aug 18 2011, 20:30
Post #6





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



Well, I am going to try to write down a kind of algorithm here so anyone could help me with a bash script... invoked from KDE or GNOME right-click menu "Open With ThisScript..."

- When clicking on the file "thisfile.wav" and opening the context menu and choosing "Open With ThisScript..." would start the script PROCESSING the selected file (not any just .wav in the directory, which will contain many .wav files)

1) The script first needs to grab the file name and store it on a variable ("thisfile.wav")
2) Then shntool must process the file just like the line in the post above....

QUOTE
shntool split -l 1:00 $WAVFILE && shntool cue split-track*.wav > $WAVFILE.cue && rm split-track*.wav


3) and as a last part, a tool should replace the automatic "joined.wav" FILE statemente within the cuesheet, using the $WAVFILE instead.


So it will end with two files:
thisfile.wav
thisfile.cue (and inside the cuesheet we would have "thisfile.wav" as the FILE statement)

(it occurred to me that the generated name would be thisfile.wav.cue, so the script should also treat this, removing the ".wav" from it)

This post has been edited by krafty: Aug 18 2011, 20:32
Go to the top of the page
+Quote Post
mjb2006
post Aug 18 2011, 22:17
Post #7





Group: Members
Posts: 755
Joined: 12-May 06
From: Colorado, USA
Member No.: 30694



Right, you didn't say what OS, so I assumed Windows.
QUOTE (krafty @ Aug 18 2011, 09:39) *
rename the "joined.wav" FILE statement within the cuesheet to inherit the intended WAV filename!

Either of these should do:
  • sed 's#joined\.wav#policy\.wav#' policy.cue > policy-fixed.cue && mv -f policy-fixed.cue policy.cue
  • sed -i .bak 's#joined\.wav#policy\.wav#' policy.cue && rm policy.cue.bak

Someone else will have to script-ify it for you.
Go to the top of the page
+Quote Post
krafty
post Aug 19 2011, 17:23
Post #8





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



I kind of figured how to make bash process the file, however my problem now is with sed, which can't interpret $1 as a variable, I am sure missing something! Any help appreciated!

CODE
#!/usr/bin/env bash

shntool split -l 5:00 $1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav

sed 's#joined\.wav#$1\.wav#' $1.cue > $1-fixed.cue
mv -f $1-fixed.cue $1.cue
Go to the top of the page
+Quote Post
dutch109
post Aug 19 2011, 21:14
Post #9





Group: Members
Posts: 122
Joined: 20-June 06
Member No.: 32044



Simple quotes prevent variable names from being interpreted, use double quotes instead, ie :

CODE
sed "s#joined\.wav#$1\.wav#" $1.cue > $1-fixed.cue


--------------------
Vorbis -q2/5 (Android/PC) & WavPack -hhx6
http://playnoise.com/
Go to the top of the page
+Quote Post
krafty
post Aug 20 2011, 19:32
Post #10





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



Thanks dutch109...

CODE
#!/usr/bin/env bash

shntool split -l 5:00 $1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav

sed "s#joined.wav#$1#" $1.cue > $1-fixed.cue
mv -f $1-fixed.cue $1.cue


Now sed is working nicely, thanks for the tip. The FILE statement is returning the proper original name.
But the final result keeps generating:

album.wav
album.wav.cue


I believe I would have to insert a variable to handle the .wav extension in this case.
Any ideas?

This post has been edited by krafty: Aug 20 2011, 19:34
Go to the top of the page
+Quote Post
dutch109
post Aug 20 2011, 20:26
Post #11





Group: Members
Posts: 122
Joined: 20-June 06
Member No.: 32044



You can remove the extension with something like this :
CODE
file_without_ext="${1%\.wav}"


Also instead of creating a new file with sed, you can make your modifications in place with the i option :
CODE
sed -i "s#joined.wav#$1#" $1.cue


--------------------
Vorbis -q2/5 (Android/PC) & WavPack -hhx6
http://playnoise.com/
Go to the top of the page
+Quote Post
krafty
post Aug 20 2011, 20:56
Post #12





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



Thanks again dutch109...

Now it's working fully...
CODE
#!/usr/bin/env bash

shntool split -l 5:00 $1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav

sed -i "s#joined.wav#$1#" $1.cue

audiofilename="${1%\.wav}"
mv -f $1.cue $audiofilename.cue
Go to the top of the page
+Quote Post
krafty
post Aug 21 2011, 04:49
Post #13





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



OK, I thought of integrating more goodies into this script, like insert a fixed "TITLE Speech on Whales" before the INDEXES statements, within the cuesheet. Any thoughts on how to do this? Perhaps a "PERFORMER" statement right after the TITLE statement would be good too. These fields will be fixed initially fixed but if I can get to have TITLE Part 1, TITLE Part 2, that would be ideal.

K3B is accepting the cuesheet very charmly.
Go to the top of the page
+Quote Post
dutch109
post Aug 21 2011, 14:37
Post #14





Group: Members
Posts: 122
Joined: 20-June 06
Member No.: 32044



Mhh, you can try something like this (that will preserve indentation in the cue file) :

CODE
sed -i "s/^\([ \t]*\)\(INDEX 01.*\)$/\1\2\n\1TITLE Title 1\n\1PERFORMER Performer/" cuesheet.cue
sed -i "s/^\([ \t]*\)\(INDEX 02.*\)$/\1\2\n\1TITLE Title 2\n\1PERFORMER Performer/" cuesheet.cue
etc.

When your bash scripts get over 200-300 lines, think about switching to another scripting language like Python, it's a lot more powerful and easier to maintain than bash. wink.gif


--------------------
Vorbis -q2/5 (Android/PC) & WavPack -hhx6
http://playnoise.com/
Go to the top of the page
+Quote Post
krafty
post Aug 21 2011, 22:00
Post #15





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



OK, there seems to be a problem when you record MONO speeches and save them as MONO, because shntool won't process "non CD-Quality" files, and it considers a "CD-Quality" file, only a stereo file. So I have incremented the use of SoX in the script. The SoX job is to create a new stereo file, based on the readings of the mono file. As far as it goes, it processes FLAC perfectly, and curiously, the output file size is just only one or three megabytes bigger than the original mono file (can somebody please explain this particular case to me? - because I re-saved the new stereo file within Audacity as FLAC and I got much more megabytes, using the same compression level) - after SoX doing its thing, shntool now can properly create the cuesheet, and K3B can burn it smoothly the mono file through this cuesheet.

CODE
#!/usr/bin/env bash

sox -S $1 -c 2 stereo-$1
shntool split -l 1:00 stereo-$1
shntool cue split-track*.wav > $1.cue
rm split-track*.wav
rm stereo-$1

sed -i "s#joined.wav#$1#" $1.cue

audiofilename="${1%\.flac}"
mv -f $1.cue $audiofilename.cue


This post has been edited by krafty: Aug 21 2011, 22:01
Go to the top of the page
+Quote Post
krafty
post Aug 22 2011, 15:53
Post #16





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



I'm having a problem with the script... $1 is handling the whole path instead of just the local directory filename (when outside the script directory or from within KDE or GNOME file managers). Any ideas on how to workaround this?

This post has been edited by krafty: Aug 22 2011, 16:46
Go to the top of the page
+Quote Post
klonuo
post Aug 22 2011, 22:06
Post #17





Group: Members
Posts: 258
Joined: 29-April 10
Member No.: 80274



krafty, you can use Google for such issues, i.e. http://www.google.com/search?q=bash+site:tldp.org
or specifically http://tldp.org/LDP/LGNET/18/bash.html

${1##*/} will extract filename from path

Will it work if you run it from base folder? - Check it out.
Go to the top of the page
+Quote Post
krafty
post Aug 23 2011, 03:11
Post #18





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



thanks klonuo...

I followed some guidelines and I got most of things working now....

CODE
#!/usr/bin/env bash

FULLPATH=`dirname $0`
FILE=`basename $1`
FILENOEXT=`basename $1 .flac`

sox -S -V $FULLPATH/$FILE -c 2 $FULLPATH/stereo.wav

shntool split -l 5:00 $FULLPATH/stereo.wav -d $FULLPATH

shntool cue $FULLPATH/split-track*.wav >> $FULLPATH/$FILENOEXT.cue

rm $FULLPATH/split-track*.wav
rm $FULLPATH/stereo.wav

sed -i "s#joined.wav#$FILE#" $FULLPATH/$FILENOEXT.cue


This post has been edited by krafty: Aug 23 2011, 03:22
Go to the top of the page
+Quote Post
mjb2006
post Aug 23 2011, 04:45
Post #19





Group: Members
Posts: 755
Joined: 12-May 06
From: Colorado, USA
Member No.: 30694



The reason a mono file comes out not very much bigger than a stereo one is because FLAC supports joint stereo. Stereo audio can be represented as simple left & right channels (LR or "simple" stereo), or it can be stored as a mid (sum) channel and a side (difference) channel instead (this is MS or "mid-side" stereo). Mono or near-mono content in a stereo stream can be stored much more efficiently using mid-side stereo because the side channel is very quiet, if not silent. FLAC, I think depending on what encoding parameters you use, can pick whichever option saves more space as it encodes each block.
Go to the top of the page
+Quote Post
krafty
post Aug 23 2011, 16:09
Post #20





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



mjb2006, thanks for the explanation. That certainly makes sense.

I can think that SoX is creating a new flac with joint-stereo as default, whereas Audacity is saving as simple stereo!
Go to the top of the page
+Quote Post
TBeck
post Aug 23 2011, 16:17
Post #21


TAK Developer


Group: Developer
Posts: 1095
Joined: 1-April 06
Member No.: 29051



QUOTE (krafty @ Aug 23 2011, 17:09) *
I can think that SoX is creating a new flac with joint-stereo as default, whereas Audacity is saving as simple stereo!

Most likely it's beeing caused by Audacity applying dither, which adds uncorrelated noise to the channels. I am no expert for Audacity, but there is a switch to disable dithering.
Go to the top of the page
+Quote Post
krafty
post Aug 23 2011, 19:30
Post #22





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



Thanks TBeck, I am going to check that.
Go to the top of the page
+Quote Post
krafty
post Aug 24 2011, 00:27
Post #23





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



Interesting data:

-rw-r--r-- 1 linuxuser linuxuser 98M 2011-08-21 22:16 source-file.flac (MONO)
-rw-r--r-- 1 linuxuser linuxuser 98M 2011-08-23 20:16 stereo-aud-nodither-at-all.flac
-rw-r--r-- 1 linuxuser linuxuser 124M 2011-08-23 20:10 stereo-aud-dither.flac
-rw-r--r-- 1 linuxuser linuxuser 117M 2011-08-23 20:06 stereo-sox-dither.flac
-rw-r--r-- 1 linuxuser linuxuser 98M 2011-08-23 20:25 stereo-sox-nodither.flac


SoX did dither the source file.
Audacity by default dithered it too, made it bigger.
When having the options to never dither at all, Audacity renders same filesize for a stereo version.

So most likely this resides on type of dithering.
Go to the top of the page
+Quote Post
krafty
post Aug 24 2011, 03:23
Post #24





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



Well...my further tests reveal that, as long as the audio file resides inside the script directory, it will be fine. But if you call the audiofile from any other location, the script fails... any help would be appreciated. I believe that basename and dirname are not doing their job...
Go to the top of the page
+Quote Post
krafty
post Aug 24 2011, 23:37
Post #25





Group: Members
Posts: 274
Joined: 20-March 10
Member No.: 79175



In this new version, the program behaves as expected when in command line.
You can browse any directory and start the command (inside the bin path).
I removed some unnecessary things. However still no success in having the script to call over the FLAC file from the right path in Dolphin or Nautilus, associating the command in the context menu.

CODE
#!/usr/bin/env bash

FILE=`basename $1`
FILENOEXT=`basename $1 .flac`

sox -S -V $FILE -c 2 stereo.wav

shntool split -l 5:00 stereo.wav

shntool cue split-track*.wav >> $FILENOEXT.cue

rm split-track*.wav
rm stereo.wav

sed -i "s#joined.wav#$FILE#" $FILENOEXT.cue


This post has been edited by krafty: Aug 24 2011, 23:38
Go to the top of the page
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 24th July 2014 - 19:56