Hi all
I want to do something that I am sure is very simple but I am frustrated because I am not sure where to start.
Basically all I want to do is to feed all the files from a directory one by one into an application - i.e. using lame to encode wav files to mp3.
Can this be done from a bash script or should I use perl or ???
Any advice or info much appreciated.
Syd
Here's something I wrote in perl to encode mp3's ripped from a cd. It's not elegant, but it works.
---- Cut here----
#!/usr/bin/perl -w
# this is the SCSI device id $cd_device="1,3,0"; $encoder_options="-S -m s -q 0 --vbr-new -V 0 -b 192 -B 320 -f -k";
mkdir "riptemp"; chdir "riptemp";
system ("/usr/bin/cdda2wav -D $cd_device -B -L");
open (CDINDEX, "audio.cdindex") || die "Can't open file: audio.cdindex \n"; while (<CDINDEX>) { if (/Title>(.*)</) { $album=$1; } if (/Artist>(.*)</) { $artist=$1; } if (/Num="(\d+)">/) { $count=$1; } if (/Name>(.*)</) { $song[$count]=$1; }
} close CDINDEX;
@wavfiles=`ls *.wav`; chomp(@wavfiles);
@mp3files=@wavfiles;
for (0..$#mp3files) { $mp3files[$_]=~ s/wav/mp3/; }
for (0..$#wavfiles) { my $track; $track=$_ + 1; system(qq{/usr/local/bin/lame $encoder_options --tl "$album" --ta "$artist" --tt "$song[$track]" --tn $track $wavfiles[$_] $mp3files[$_]}); }
mkdir "../$artist"; mkdir "../$artist/$album";
for (0..$#mp3files) { my $track; $track=$_ +1; system(qq{ mv $mp3files[$_] "../$artist/$album/$artist - $album - $song[$track].mp3"}); }
system ("rm -f audio*"); chdir ".."; rmdir "riptemp";
---and here :-)-----
On 2004-01-03 15:58:46 +0000 Syd Hancock syd@toufol.com wrote:
Basically all I want to do is to feed all the files from a directory one by one into an application - i.e. using lame to encode wav files to mp3.
Most shells have some way to do this. For bash: for a in *.wav ; do lamecommand "$a" ; done or for rc: for (a in *.wav) { lamecommand $a }
In both, the command is repeated many times with $a being each file name in turn. It is put in ""s for bash to stop filenames with spaces screwing it up, as bash replaces $a and then scans the command. rc doesn't have that problem ;-)
Alternatively, you can use find, which can do subdirectories by default: find . -exec lamecommand '{}' ';'
The '{}' gets replaced by the filename and ';' is the end-of-command marker. Both are single-quoted to stop the shell playing with them.
You can do this from perl, too, but that may be overkill for many instances. The above examples are untested, so test with echo and |more before use.
On Saturday 03 Jan 2004 3:58 pm, Syd Hancock wrote:
Hi all
I want to do something that I am sure is very simple but I am frustrated because I am not sure where to start.
Basically all I want to do is to feed all the files from a directory one by one into an application - i.e. using lame to encode wav files to mp3.
Can this be done from a bash script or should I use perl or ???
Any advice or info much appreciated.
Syd
You should be able to do this from bash but I have a feeling you can do it with lame itself. Have you man lame ?
Ian
On Saturday 03 January 2004 10:01 pm, Ian Bell wrote:
On Saturday 03 Jan 2004 3:58 pm, Syd Hancock wrote:
Hi all
I want to do something that I am sure is very simple but I am frustrated because I am not sure where to start.
Basically all I want to do is to feed all the files from a directory one by one into an application - i.e. using lame to encode wav files to mp3.
Can this be done from a bash script or should I use perl or ???
Any advice or info much appreciated.
Syd
You should be able to do this from bash but I have a feeling you can do it with lame itself. Have you man lame ?
Spooky. I was thinking about doing something similar today. From what I can see on the man page lame doesn't do batch processing, so a 'for all' loop would be the best bet IMO.
BenE
On Saturday 03 Jan 2004 11:07 pm, beneboy wrote:
On Saturday 03 January 2004 10:01 pm, Ian Bell wrote:
On Saturday 03 Jan 2004 3:58 pm, Syd Hancock wrote:
Hi all
I want to do something that I am sure is very simple but I am frustrated because I am not sure where to start.
Basically all I want to do is to feed all the files from a directory one by one into an application - i.e. using lame to encode wav files to mp3.
Can this be done from a bash script or should I use perl or ???
Any advice or info much appreciated.
Syd
You should be able to do this from bash but I have a feeling you can do it with lame itself. Have you man lame ?
Spooky. I was thinking about doing something similar today. From what I can see on the man page lame doesn't do batch processing, so a 'for all' loop would be the best bet IMO.
BenE
IIRC, last time I tried to use lame it had some problems - then I stumbled on an improved version called notlame IIRC.
Ian