Help with 'batch conversion using lame' shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with 'batch conversion using lame' shell script
# 1  
Old 04-06-2010
Question Help with 'batch conversion using lame' shell script

Hi.

I am trying to write an sh script that will:

1. take each wav file in ~/Documents
2. convert each into mp3 format using "lame" encoder
3. save the new mp3 in ~/Documents/newmp3s.

It has to follow the 3 steps in this order for each wav file before taking the next file.

I tried a for loop taken from another forum, but not only does the script still saves the new mp3 files in ~/Documents but the loop also doesn't end.

Any help would be much appreciated. Right now I'm using Audacity for manual conversion Smilie
# 2  
Old 04-06-2010
Personally, I'm thinking that the use of lame, Audacity and whether they're mp3 files is irrelevant to your problem. How about posting the stricken script so that someone can review/correct the loop that's misbehaving...?
# 3  
Old 04-06-2010
Quote:
Originally Posted by curleb
Personally, I'm thinking that the use of lame, Audacity and whether they're mp3 files is irrelevant to your problem. How about posting the stricken script so that someone can review/correct the loop that's misbehaving...?
Here is the code:

Code:
#!/bin/bash

cd ~/Documents

for file in *.wav; 
do lame "$file"; 
done

for i in *.mp3; do
mv "$i" ~/Documents/newmp3s
done

# 4  
Old 04-06-2010
okay, so the sequence you'd said was required earlier is not what the script you've posted is actually doing. You have them separated into two loops, which is fine, but might be off in terms of timing...maybe you're checking in on the results before the first loop is completed...

Assuming that lame takes your hello.WAV file and outputs it as hello.MP3, try:

Code:
#!/bin/bash

cd ~/Documents

for file in *.wav 
do 
   lame "$file" 
   mv ${file%.wave}.mp3 ~/Documents/newmp3s/. 
done

cd -


Last edited by curleb; 04-06-2010 at 11:06 PM.. Reason: uh-duh...
# 5  
Old 04-06-2010
I tried your solution and it only saved my 2 test files (Hello1.wav and Hello2.wav) in ~/Documents as *.wav.mp3 files, still in ~/Documents.

I tried putting the idea from your code into my previous code and it worked.

Here is the new code:

Code:
#!/bin/bash

cd ~/Documents

for file in *.wav; 
do lame "$file"; 

for i in *.wav.mp3 ; do
mv "$i" ~/Documents/'newmp3s'
cd ~/Documents/'newmp3s'
rename 's/.wav//' *.mp3
cd ..
done
done

Thanks for that.

But now if i want to convert mp3s into mp3s (i do that to decrease file size), using exactly the same code, the 'rename' command will remove the 'mp3' extension in all but the last new converted file in ~/Documents/newmp3s. Any workaround for that?

Code:
#!/bin/bash

cd ~/Documents

for file in *.mp3; 
do lame "$file"; 

for i in *.mp3.mp3 ; do
mv "$i" ~/Documents/newmp3s
cd ~/Documents/newmp3s
rename 's/.mp3//' *.mp3
cd ..
done
done

# 6  
Old 04-06-2010
Does lame care about the input file's extension; ie, takes your input file as is and bases processing on file structure instead of extensions? If so, why not strip it off (or do a temporary cp) prior to passing it to lame, and then do the rename to .MP3 as per usual?
# 7  
Old 04-07-2010
Quote:
Originally Posted by curleb
Does lame care about the input file's extension; ie, takes your input file as is and bases processing on file structure instead of extensions? If so, why not strip it off (or do a temporary cp) prior to passing it to lame, and then do the rename to .MP3 as per usual?
Yes it cares about the extension. I tried this:

Code:
lame hello hello.mp3

and i got 'Warning: Unsupported audio format' even though 'hello' is of mp3 format.

I would just like to replicate the 'one-click conversion' from the audio converters in Windows, without installing software.

I can still add the 'mp3' extension in all files after conversion, that's no biggie.

---------- Post updated at 04:02 PM ---------- Previous update was at 11:58 AM ----------

I also noticed that all the songs in my Music Library does not include the '.mp3' extension in their filename :S

I copied 2 songs to ~/Documents and my script bypassed those 2 files because lame does not recognize them as mp3s. Audacity does though and it still uses lame for encoding.

I think it's getting too complicated now. I'll just look for a program that does batch encoding in *nix.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Batch to shell script conversion

Hi All, I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script. below is the batch script: @echo off IF "%1"== "" GOTO ARGERR REM UPDATE THESE PROPERTIES TO... (2 Replies)
Discussion started by: sukhdip
2 Replies

2. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

3. Shell Programming and Scripting

Shell script from batch file

Hi, I am a junior dba and started carrier very new. I have a batch file to create some script of db creation. I want that batch file to convert in .sh file so that I can directly run that in the AIX box to generate those files. Please help me with the code for AIX. Batch file is here: ... (2 Replies)
Discussion started by: dba_aix
2 Replies

4. Shell Programming and Scripting

Batch to bash conversion

Hi, I am just trying to convert the batch script to bash script and i am stuck at one point where I have the below code for /f "delims=" %%a in (a.txt) do ( for /f "tokens=1,2,3* delims==" %%i in ("%%a") do ( for /f "tokens=1,2,3* delims= " %%x in ("%%i") do ( if... (4 Replies)
Discussion started by: prasanna2166
4 Replies

5. Shell Programming and Scripting

Need to run the batch script from shell scripting

Hi All, I am working on shell scripting.My script is completed but I have one task that is to trigger the batch script(with or without parameter) from my shell scripting(reside on linux system) and output which is geneareted by the batch should e.g. if batch script creates any files then I want... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

6. Shell Programming and Scripting

Conversion batch shell script

while converting batch file to shell script ...dis command is ther i dunno how to change...can anyone knws how to change into shell script rm !(D:\temp\XX.txt) (3 Replies)
Discussion started by: monisha
3 Replies

7. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

8. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

9. Shell Programming and Scripting

Change the Windows Batch script to UNIX shell script.

Hi, When I run the below script in UNIX it's throwing syntax errors. Actually it's a windows batch script. Could anyone change the below Windows Batch script to UNIX shell script... Script: REM :: File Name : Refresh_OTL.bat REM :: Parameters : %1 - Region REM :: : %2 - Cube Type REM ::... (5 Replies)
Discussion started by: tomailraj
5 Replies

10. UNIX for Dummies Questions & Answers

batch command in a shell script

How do I execute a batch command from a script, which "waits" with the next command until the first one has finished? ======= A piece of my script looks like this: #!/bin/sh (...) # run a long batch job: ./run_calculation.sh # then rename resulting file: mv output.dat backup.dat (...) ... (7 Replies)
Discussion started by: ivvo
7 Replies
Login or Register to Ask a Question