Results 1 to 5 of 5
Hi all, I've been using Linux for nearly two years now, but I'm far from a programmer. So I hope you'll all be gentle and not laugh too much at ...
- 03-07-2005 #1Just Joined!
- Join Date
- Mar 2005
- Posts
- 1
[SOLVED] Noob question about script for batch file processing
Hi all, I've been using Linux for nearly two years now, but I'm far from a programmer. So I hope you'll all be gentle and not laugh too much at this question.
I have a folder of mp3s of different bitrates. I want to use lame to reencode all of them to be 128 kbit, as this is music for the gym and quantity is more important than quality. I've done this successfully with 1 file at a time,
lame -h song.mp3 song128.mp3
But I want to do it in a batch to all files in the folder, appending '128' or similar to the name of each converted file.
This is probably really easy, but I'm at a loss. Any ideas?
Thanks,
Brian
- 03-07-2005 #2Linux Enthusiast
- Join Date
- Feb 2005
- Location
- SE, Stockholm
- Posts
- 512
You could do a fairly simple Q'n'D script like this:
This is as I said, a Q'n'D script, you'll have to run it in the directory where you have all your stored MP3 files, but change it as you wish to better fit your purpose.Code:#!/bin/bash # Get all files in current directory myMp3Files=$(ls *.mp3) # Loop through all files and do your changes for looMp3File in $myMp3Files do # Get original filename without .mp3 extension originTune=$(echo $loopMp3File|awk '{gsub("."," ");print $1}'); # Create your new filename including .mp3 newTune=$originTune"-128.mp3" echo "Converting $loopMp3File into $newTune"; # do the converting myConvert=$(lame -h $loopMp3File $newTune); done
Hope this helps you a bit.
- 03-08-2005 #3Just Joined!
- Join Date
- Feb 2005
- Posts
- 5
There's always more than one way to skin a cat when it comes to a powerful o/s like GNU/Linux.

You can try this within a directory of mp3's at the command prompt:
ls -1 *.mp3 | sed "s/\(.*\)\.mp3/\1.mp3 \1_128.mp3/" |xargs -n 2 lame -h
Notes:
1) I haven't tested it so you might want to test it in a directory where you have just a few mp3's first to see that it works
2) It should output new mp3's with filenames like: song_128.mp3
3) This will only work if the mp3 filenames have no spaces in them
4) The meta data will not be carried over to the new 128 files, but neither would that happen with the way you're running lame in your example.
I'd like to know if it worked for you.
Cheers
- 03-19-2005 #4Just Joined!
- Join Date
- Mar 2005
- Location
- Tennessee
- Posts
- 1
Here is a script to convert wav's to mp3's. It is tested and I have used it for a long time. It could be easily converted to do mp3 to mp3. I have added a bunch of usless stuff just for looks and fun.
Lawrence ShaferCode:#!/bin/bash clear echo echo autolame V 0.12 echo echo "autolame was written by Lawrence Shafer" echo "Please send any flames, laughter hugs and" echo "updates/enhancements to lawrence(at)pastimes.cc" sleep 5 # Usage Instructions. # 0 make sure you have lame installed! # 1 Copy this file to /usr/bin/autolame. # 2 cd to the directory where the wav's are that you want to convert. # 3 type autolame # 4 they're done! # need to ad arg for lame command line and for in/out filenames so you dont have to run it in the wav folder # Get all files in current directory myWavFiles=$(ls *.wav) # Go through the wav's and convert them for oldWav in $myWavFiles do clear echo echo auto-lame V 0.12 echo # Get original filename without .Wav extension originName=$(echo $oldWav|awk '{sub(".wav"," ");print $1}'); echo $originName echo # Create the new filename including .mp3 newMp3=$originName".mp3" echo "Encoding $oldWav to $newMp3"; echo echo # Convert it lameit=$(lame -h $oldWav $newMp3); done
- 05-10-2008 #5Just Joined!
- Join Date
- May 2008
- Posts
- 34




