Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page [SOLVED] Noob question about script for batch file processing
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Closed Thread
 
Thread Tools Display Modes
Old 03-07-2005   #1 (permalink)
briansz
Just 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
briansz is offline  
Old 03-07-2005   #2 (permalink)
swemic
Linux Enthusiast
 
Join Date: Feb 2005
Location: SE, Stockholm
Posts: 512
Send a message via ICQ to swemic Send a message via MSN to swemic
You could do a fairly simple Q'n'D script like this:
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
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.
Hope this helps you a bit.
swemic is offline  
Old 03-08-2005   #3 (permalink)
NoStop
Just 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
NoStop is offline  
Old 03-19-2005   #4 (permalink)
Lawrence_Shafer
Just 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.

Code:
#!/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
Lawrence Shafer
__________________
Use the real linux, use Debian!
Lawrence_Shafer is offline  
Old 05-10-2008   #5 (permalink)
5pyd3r
Just Joined!
 
Join Date: May 2008
Posts: 7
Thumbs up

Quote:
Originally Posted by NoStop View Post
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
Thanks a lot this worked very well.
5pyd3r is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 10:35 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0