LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2010, 02:21 AM   #1
air4time
Member
 
Registered: Aug 2004
Distribution: Slackware 10.2
Posts: 35

Rep: Reputation: 15
script to exact audio from avi then move all mp3 ...


First of all thanks

Here is my script and I borrow most of it from http://www.linuxquestions.org/linux/...files_to_AVI_0

Code:
#!/bin/bash

# remove spaces
for i in *.[Aa][Vv][Ii]; do mv "$i" `echo $i | tr ' ' '_'`; done > /dev/null 2>&1 &

# remove uppercase
for i in *.[Aa][Vv][Ii]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done > /dev/null 2>&1 & 
echo " Spaces and Uppercase removed done"

#added this to make sure where I was since I was getting a error "no  such file or directory"
pwd

#this fix that error So my best guess was it did not  wait for the above to finish before starting the next thing
sleep 10

#convert avi to mp3
for i in *.[Aa][Vv][Ii]; do nice -n 10 ffmpeg -i $i -ab 128 -ar 44100 "`basename "$i"`.mp3";echo "Conversion done";done

#old convert audio from flv starts at 09 seconds and  is only 60  seconds long
#ffmpeg -i "filename".flv -ss 00:00:09 -t 60 -ab 128 - ar 44100  "nofilename".mp3

#old convert MPG to AVI
#for i in *.[Mm][Pp][Gg]; do nice -n 10 mencoder $i - ovc lavc  -lavcopts  vcodec=mpeg4:vbitrate= $vbitrate:vhq:vqmin=2:vlelim=-4:vcelim=9:lumi_ma#sk=0.05:dark_mask=0.01  -vf pp=md  -vop scale=640:480, -oac lavc  -lavcopts  acodec=mp3:abitrate=128 -o "`basename "$i"`.avi";echo  "Conversion done";done

#normalize all mp3s 
normalize-audio -m -v  *.mp3 ;echo "Normalize done"

#move new mp3 to /home/"user"/audio I have already made a dir called audio
 mv -v *.mp3 ~/audio ;echo "Move done"

exit;
I had to put "sleep" in because without it the conversion would fail "no such file or directory". This works but there must be a better way to do it . Like a way for it to wait for the spaces etc to be removed before moving on.

I am not sure if I did the echos right cause I only want them to "echo" if it did the job with no errors.

Also is there a way to not have the ".avi" in the mp3 file?

Thanks again
 
Old 10-20-2010, 02:52 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Indeed the script goes on immediately after the two loops, since they are executed in background. If you remove the ampersand at the end of the loops, they will be executed in foreground and the script will wait for completion before going on.

In that case the echo will be executed after the completion of the second loop, independently of its success. There are many ways to check if a command completed successfully, mainly by checking the exit status of the command itself, but take in mind that mv fails every time it encounters a file without spaces and without uppercase characters (that is the file does not need to be renamed).

Regarding the .avi extension you can easily change it using parameter substitution. For example:
Code:
nice -n 10 ffmpeg -i $i -ab 128 -ar 44100 ${i/.avi/.mp3}
Hope this helps.
 
Old 10-20-2010, 04:43 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,499

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Was just wondering why you do all the fluffing around with removing spaces and changing case?
I mean if it is just a want then cool but seems a lot of work that probably isn't necessary.

Also, is there a reason why all actions are in separate loops?
Again this seems like a lot of overhead when you are potentially working on the same data.

Lastly, your third loop does not seem to take into account that you have changed the case hence the [Aa] constructs are not required.
 
Old 10-20-2010, 03:30 PM   #4
air4time
Member
 
Registered: Aug 2004
Distribution: Slackware 10.2
Posts: 35

Original Poster
Rep: Reputation: 15
Code:
#!/bin/bash             

#tring to see if it worked

# remove uppercase
for i in *.[Aa][Vv][Ii]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done > /dev/null 2>&1  
if [ "$?" = "0" ]; then
   echo " removed uppercase worked moving on"
   
else
   echo "remove uppercase something went wrong" ;exit

fi

# remove spaces
for i in *.avi; do mv "$i" `echo $i | tr ‘ ‘ ‘_’`; done > /dev/null 2>&1   
#for files in *.avi; do mv “$files” `echo $files | tr ‘ ‘ ‘_’`; done > /dev/null 2>&1  
if [ "$?" = "0" ]; then
   echo "removed spaces worked moving on"
   
else
   echo "remove spaces something went wrong" ;exit

fi

#convert avi to mp3
for i in *.avi; do nice -n 10 ffmpeg -i $i -ab 128 -ar 44100 ${i/.avi/.mp3};done
if [ "$?" = "0" ]; then
   echo "worked moving on"
   
else
   echo "convert avi to mp3 something went wrong" ;exit

fi
#old convert audio from flv starts at 09 seconds and  is only 60  seconds long
#ffmpeg -i "filename".flv -ss 00:00:09 -t 60 -ab 128 - ar 44100  "nofilename".mp3

#old convert MPG to AVI
#for i in *.[Mm][Pp][Gg]; do nice -n 10 mencoder $i - ovc lavc  -lavcopts  vcodec=mpeg4:vbitrate= $vbitrate:vhq:vqmin=2:vlelim=-4:vcelim=9:lumi_ma#sk=0.05:dark_mask=0.01  -vf pp=md  -vop scale=640:480, -oac lavc  -lavcopts  acodec=mp3:abitrate=128 -o "`basename "$i"`.avi";echo  "Conversion done";done

#normalize all mp3s 
normalize-audio -m -v  *.mp3 ;echo "Normalize done"
if [ "$?" = "0" ]; then
   echo "worked moving on"
   
else
   echo "normalize all mp3s something went wrong" ;exit

fi
#move new mp3 to /home/"user"/audio I have already made a dir called audio
 mv -vn *.mp3 ~/audio ;echo "Move done"
if [ "$?" = "0" ]; then
   echo "worked moving on"
   
else
   echo "move new mp3 something went wrong" ;exit

fi
exit;
Thanks colucix
As you can see I edit it a little. Took out the ampersand (had to look it up to see what it was lol) added some "exit status " stuff and now I find out that the code to remove spaces is having errors and exit with 1
Here is part of what it prints out
Quote:
mv: missing destination file operand after `becker.s01e22.regarding.reggie.dvdrip.xvid-saints.avi'
Try `mv --help' for more information.
something went wrong
In the updated script you will see another line quoted out for removing spaces and it does the same thing? I tried searching for a reason for the error but came up empty. I even added spaces to some of the files to see if maybe that was the reason for the error but was not it. To me it looks like the "remove uppercase" is almost the same thing but it works and exits with "0".

Thanks grail
It seems like without removing the spaces , "mv" does not work right.I welcome any input on how to make this smaller.BTW change to just "avi" in 3rd loop.Thanks for pointing that out should have been obvious lol.
 
Old 10-20-2010, 07:39 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,499

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
Well its untested, but something like this:
Code:
#!/bin/bash

while read -r file_name
do
        mp3_name="${file_name%avi}mp3"
        nice -n 10 ffmpeg -i "$file_name" -ab 128 -ar 44100 "mp3_name"
done< <(find . -maxdepth 1 -type f -iname '*.avi') && echo "All Conversions done"

#normalize all mp3s 
normalize-audio -m -v  *.mp3 && echo "Normalize done"

#move new mp3 to /home/"user"/audio I have already made a dir called audio
[[ -d ~/audio ]] || mkdir -v ~/audio

mv -v *.mp3 ~/audio && echo "Move done"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slack, Wine and Exact Audio Copy simonb1975uk Slackware 10 09-03-2007 05:42 AM
Convert move frames (avi/dvi/etc) to images(png/jpg/etc) 3saul Linux - Software 1 03-05-2006 09:29 PM
MP3Releaser 4 Linux - script suite 2 rip audio in mp3 scene releasing rules i_zh Linux - Software 1 01-19-2006 11:56 AM
Exact Copy Audio Music CD Help Requested cscott Linux - Software 3 08-26-2004 06:21 AM
AVI Audio to MP3 File Obi Perrin Linux - Software 2 03-10-2003 10:27 AM


All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration