Re: fix an audio conversion script to work through multiple directories and convert mp3s to ogg vorbis
On Sat, May 7, 2011 at 4:03 PM, Chris Hill ch...@monochrome.org wrote: On Sat, 7 May 2011, Antonio Olivares wrote: My question is the following: How can I run the script to recursively find all mp3's and convert them to ogg vorbis(with ogg extension already in place/or rename them in one step[instead of running two scripts] and deleting the mp3's) all in one time? I had a similar (but not identical) problem, and I wrote a script to solve it. I wanted to recursively go through a directory tree, find flac files, and make mp3s of them while transferring over the ID3 tags, while keeping a duplicate directory structure for the mp3s. And don't do the conversion if the file already exists. My script is based on traverse2.sh by Steve Parker, which is at http://steve-parker.org/sh/eg/directories/. His tutorial site is extremely helpful, and I recommend it. My script is at http://pastebin.com/77NRE6SZ - maybe you can adapt it to your needs. HTH. -- Chris Hill ch...@monochrome.org ** [ Busy Expunging / ] Chris, Thank you for your suggestion. But I have gotten into a problem I get errors and too many directories :(, Directories with spaces get recreated and no ogg files are created :( = #!/bin/sh # # Notes: # # For each music file in the current directory and its subdirectories, # convert it to an ogg. # # This script traverses directory structures using a mechanism adapted # from Steve Parker's traverse2.sh script. # # I assume that the commands ls, rm, sed, grep, pwd, wc and mkdir exist # and can be called by those names. But let's make sure this system has # the necessary third-party software installed, and find the binaries. # Complain and exit if any one is not found. OGGENC=`which oggenc` MPLAYER=`which mplayer` # Exit if we are missing anything: if [ -z $MPLAYER ]; then echo mplayer not found! Exiting. exit 1 fi if [ -z $OGGENC ]; then echo oggenc not found! Exiting. exit 1 fi # Where to log errors? LOGFILE=.conversion_err_log # Where to put the oggs: # Create that directory if necessary OGGROOT=./ogg # change this to whatever you like if [ -d $OGGROOT ]; then echo ; # then we're OK else mkdir $OGGROOT fi # Parameters for lame - will affect sound quality and file size. #LAME_PARAMS=-V 0 -h# variable bitrate, best quality # From Steve Parker, only slightly modified: traverse() { # Traverse a directory ls $1 | while read i do if [ -d $1/$i ]; then THISDIR=$1/$i # Calling this as a subshell means that when the called # function changes directory, it will not affect our # current working directory if [ -d $OGGROOT/$THISDIR ]; then # directory exists, leave it be echo $OGGROOT/$THISDIR already exists, not created. else mkdir $OGGROOT/$THISDIR echo Copying $THISDIR to $OGGROOT/$THISDIR fi traverse $1/$i `expr $2 + 1` else FILE=$1/$i MP3FILE=`echo $FILE | grep -i mp3$` # Ditch the empty lines: if [ -z $MP3FILE ]; then echo # do nothing! else #echo $MP3FILE OGG=$MP3ROOT/$THISDIR/${i%.mp3}.ogg # vvv commented during script debugging vvv if [ -f $OGG ]; then # ogg already exists; don't overwrite if [ -f $LOGFILE ]; then # if the log file exists, append echo $THISDIR/$OGG $LOGFILE else # file does not exist; create echo The following ogg files already exist and were not created: \ $LOGFILE echo $LOGFILE echo $OGGROOT/$OGG $LOGFILE fi else echo Creating ${OGG}... # Create ogg without tags: $MPLAYER -cd $1 -ao pcm:file=$WAV $MP3FILE $OGGENC -b 128 $WAV # else if [ -f $LOGFILE ]; then # if the log file exists, append echo $THISDIR/$MP3FILE $LOGFILE else # file does not exist; create echo No tags found for the following: $LOGFILE echo $LOGFILE echo $THISDIR/$MP3FILE $LOGFILE fi fi fi fi done } traverse . 0 = I have modified to above script. I don't get how the directory structure is copied? I don't see a cp -r from_directory/ to _directory/ then mplayer -ao The option is not the same as I had it before. I guess if I can't get it to work, I would need to go individually through each folder and convert the mp3's with the original scripts. I made another variation and it does not work either, this of course before I try it on the machine where the actual songs that I want to convert: == #!/bin/sh # # Notes: # # For each flac file in the current directory and its subdirectories, # convert it to an mp3,
Re: fix an audio conversion script to work through multiple directories and convert mp3s to ogg vorbis
On Sun, 8 May 2011, Antonio Olivares wrote: On Sat, May 7, 2011 at 4:03 PM, Chris Hill ch...@monochrome.org wrote: On Sat, 7 May 2011, Antonio Olivares wrote: My question is the following: How can I run the script to recursively find all mp3's and convert them to ogg vorbis(with ogg extension already in place/or rename them in one step[instead of running two scripts] and deleting the mp3's) all in one time? I had a similar (but not identical) problem [ snip ] My script is at http://pastebin.com/77NRE6SZ - maybe you can adapt it to your needs. Thank you for your suggestion. But I have gotten into a problem I get errors and too many directories :(, Directories with spaces get recreated and no ogg files are created :( If your directory and/or file names have spaces, you will have to quote the filenames somehow: 'file name' vs. file_name. Maybe you could escape the spaces? None of my names have spaces, for exactly this reason. [ Script mostly snipped ] = #!/bin/sh # From Steve Parker, only slightly modified: [ snip ] traverse() { # Traverse a directory ls $1 | while read i do if [ -d $1/$i ]; then THISDIR=$1/$i # Calling this as a subshell means that when the called # function changes directory, it will not affect our # current working directory if [ -d $OGGROOT/$THISDIR ]; then # directory exists, leave it be echo $OGGROOT/$THISDIR already exists, not created. else mkdir $OGGROOT/$THISDIR echo Copying $THISDIR to $OGGROOT/$THISDIR fi traverse $1/$i `expr $2 + 1` else [ snip ] fi done } traverse . 0 = I have modified to above script. I don't get how the directory structure is copied? I don't see a cp -r from_directory/ to _directory/ then mplayer -ao There is no cp -R. What this is doing is replicating the directory structure, then copying each file. I missed it too, the first several times I looked at it. Almost the entire script is the definition of the traverse() function, which is called in the last line. The function then calls itself whenever it finds a directory, which makes it recurse. I thought it was pretty clever; wish I'd thought of it. [ snip ] Thanks for helping. I am experimenting and trying not to shoot myself in the foot. So was I; that's the main reason why there are all those `echo something` lines - I wanted to see what it would try to do, before actually turning it loose on my files. That and the fact that doing all the conversions takes a few hours. Good luck. -- Chris Hill ch...@monochrome.org ** [ Busy Expunging / ] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
fix an audio conversion script to work through multiple directories and convert mp3s to ogg vorbis
Dear kind FreeBSD users, I have a dilemma, I have a collection of songs in mp3 form from old cd's that I ripped. Sadly, the mp3s can play but with a screeching sound :(. I have confirmed that by converting the mp3's to ogg vorbis format, the screeching sound is lost. So I have decided to convert my songs to ogg vorbis. I have found a script that converts from any sound format to mp3, but I modified it to convert to ogg at 128 k which is default. The script that I modified is found at : http://en.linuxreviews.org/HOWTO_Convert_audio_files However, when I run it, I have to switch to the folder where the mp3's are at and run $ ./convert2ogg mp3 and when it is done $ ./renamer to rename the songs from *.mp3.ogg to *.ogg and then delete the mp3's manually. == [olivares@acer-aspire-1 Download]$ cat renamer #!/bin/sh for i in *.mp3.ogg do mv $i $(echo $i|sed 's/mp3.ogg/ogg/g') done [olivares@acer-aspire-1 Download]$ cat convert2ogg #!/bin/sh # # Usage: convertoogg fileextention # if [ $1 = ];then echo 'Please give a audio file extention as argument.' exit 1 fi for i in *.$1 do if [ -f $i ]; then rm -f $i.wav mkfifo $i.wav mplayer \ -quiet \ -vo null \ -vc dummy \ -af volume=0,resample=44100:0:1 \ -ao pcm:waveheader:file=$i.wav $i dest=`echo $i|sed -e s/$1$/ogg/` oggenc -b 128 $i.wav $dest rm -f $i.wav fi done == My question is the following: How can I run the script to recursively find all mp3's and convert them to ogg vorbis(with ogg extension already in place/or rename them in one step[instead of running two scripts] and deleting the mp3's) all in one time? Say I have a folder with songs: Los Invasores de Nuevo Leon - Disc 1 - Disc 2 - Disc 3 . . - Disc 20 And instead of going in manually and running the above scripts through each folder, run a modified script that will recursively find all mp3's in the directories and convert them to ogg, rename them and delete the mp3's? I know it can be done, but I am not expert and am afraid to screw up [see thread of updating freebsd with portmaster -af in case you have doubts]. I tend to shoot myself in the foot :( Something like $ find -iname *.mp3 -exec ./convert2ogg ~/Los\ Invsores\ de\ Nuevo\ Leon/mp3 or similar that can do the job with a modified convert2ogg file that can rename the output correctly in the first step. Any suggestions/advice/comments/observations are welcome. I will attempt this on Monday on my machine at work since it is the one that has the screeching sound :( I will also try to get back a machine[the one with # portupgrade -af , # portmaster ?,etc] Regards, Antonio ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: fix an audio conversion script to work through multiple directories and convert mp3s to ogg vorbis
On Sat, 7 May 2011, Antonio Olivares wrote: My question is the following: How can I run the script to recursively find all mp3's and convert them to ogg vorbis(with ogg extension already in place/or rename them in one step[instead of running two scripts] and deleting the mp3's) all in one time? I had a similar (but not identical) problem, and I wrote a script to solve it. I wanted to recursively go through a directory tree, find flac files, and make mp3s of them while transferring over the ID3 tags, while keeping a duplicate directory structure for the mp3s. And don't do the conversion if the file already exists. My script is based on traverse2.sh by Steve Parker, which is at http://steve-parker.org/sh/eg/directories/. His tutorial site is extremely helpful, and I recommend it. My script is at http://pastebin.com/77NRE6SZ - maybe you can adapt it to your needs. HTH. -- Chris Hill ch...@monochrome.org ** [ Busy Expunging / ] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org