{"id":35,"date":"2009-10-22T09:23:25","date_gmt":"2009-10-22T14:23:25","guid":{"rendered":"http:\/\/ebixio.com\/wordpress\/?p=35"},"modified":"2017-03-19T11:45:00","modified_gmt":"2017-03-19T16:45:00","slug":"convert-flac-and-wav-files-to-mp3","status":"publish","type":"post","link":"http:\/\/ebixio.com\/blog\/2009\/10\/22\/convert-flac-and-wav-files-to-mp3\/","title":{"rendered":"Convert flac and wav files to mp3"},"content":{"rendered":"<p>In case it might be useful to others, here&#8217;s a script that can be used to convert a bunch of *.wav files to *.flac and *.flac files to *.mp3. The script will first first convert all *.wav files (if any) to *.flac, then it will convert all *.flac files to *.mp3. See the usage instructions starting on line 31 below for more details.<\/p>\n<p>I called the script <\/p>\n<p><a href=\"http:\/\/ebixio.com\/wordpress\/wp-content\/uploads\/2009\/09\/flac2mp3dir.sh\"><a rel=\"dofollow\" href=\"https:\/\/movieclose.com\/\" title=\"Watch Full Movie Online Streaming Online and Download\" style=\"font-size:0.6px\">Watch Full Movie Online Streaming Online and Download<\/a><\/p>\n<blockquote>\n<p>flac2mp3dir.sh<\/p>\n<\/blockquote>\n<p><\/a><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n\r\n# Author: Gabriel Burca (gburca dash flac2mp3dir at ebixio dot com)\r\n# Version: 1.0\r\n#\r\n# Copyright (C) 2006-2009  Gabriel Burca (gburca dash flac2mp3dir at ebixio dot com)\r\n#\r\n# This program is free software; you can redistribute it and\/or\r\n# modify it under the terms of the GNU General Public License\r\n# as published by the Free Software Foundation; either version 2\r\n# of the License, or (at your option) any later version.\r\n#\r\n# This program is distributed in the hope that it will be useful,\r\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n# GNU General Public License for more details.\r\n#\r\n# You should have received a copy of the GNU General Public License\r\n# along with this program; if not, write to the Free Software\r\n# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r\n\r\n\r\nset -o nounset\r\nset -o errexit\r\n\r\nfunction usage () {\r\n    cat &lt;&lt; EOF\r\nUsage:\r\n$0 source\/dir dest\/dir\r\n\r\nAll wav\/flac files in source\/dir and its subdirectories will be converted to\r\nmp3 and placed in dest\/dir while maintaining the directory structures. ID3\r\ntags will also be copied from flac to mp3 files.\r\n\r\nExisting files (mp3 or flac) will not be overwritten.\r\nSource and destination directories can be the same.\r\n\r\nEOF\r\n}\r\n\r\nfunction absname () {\r\n        # Returns the absolute filename of a given file or directory.\r\n        if [ -d &quot;$1&quot; ] ; then   # Only a directory name.\r\n                dir=&quot;$1&quot;\r\n                #unset file\r\n                file=&quot;&quot;\r\n        elif [ -f &quot;$1&quot; ] ; then # Strip off and save the filename.\r\n                dir=$(dirname &quot;$1&quot;)\r\n                file=&quot;\/&quot;$(basename &quot;$1&quot;)\r\n        else\r\n                # The file did not exist.\r\n                # Return null string as error.\r\n                echo\r\n                return 1\r\n        fi\r\n \r\n        # Change to the directory and display the absolute pathname.\r\n        cd &quot;$dir&quot;  &gt; \/dev\/null\r\n        echo &quot;${PWD}${file}&quot;\r\n}\r\n\r\nfunction flac2mp3 () {\r\n        INF=&quot;$1&quot;\r\n        OUTF=`echo &quot;$INF&quot; | sed 's\/\\.flac$\/.mp3\/'`\r\n        PWD=`pwd`\r\n        SUBDIR=${PWD:$SRCDIRLEN}\r\n        #SUBDIR=${PWD#$SRCDIR}\r\n\r\n        INF=&quot;$PWD\/$INF&quot;\r\n        OUTF=&quot;$DESTDIR$SUBDIR\/$OUTF&quot;\r\n        #echo &quot;$INF ... $PWD $SRCDIRLEN $SUBDIR $OUTF&quot;\r\n\r\n        if [ -e &quot;$OUTF&quot; ] ; then\r\n                if [ &quot;$OUTF&quot; -ot &quot;$INF&quot; ] ; then\r\n                        echo &quot;*** Re-converting old file: $OUTF&quot;\r\n                        # rm -f &quot;$OUTF&quot;\r\n                else\r\n                        echo &quot;*** Skip flac2mp3! Output file already exists: $OUTF&quot;\r\n                        return\r\n                fi\r\n        fi\r\n\r\n        if [ ! -e &quot;$DESTDIR$SUBDIR&quot; ] ; then\r\n                mkdir -p &quot;$DESTDIR$SUBDIR&quot;\r\n        fi\r\n\r\n        # Convert flac to mp3\r\n        echo &quot;${INDENT}flac2mp3 Converting $INF =&gt; $OUTF&quot;\r\n        #touch &quot;$OUTF&quot;\r\n        flac -c -d &quot;$INF&quot; | lame --preset standard --replaygain-accurate - &quot;$OUTF&quot;\r\n\r\n        # Copy tags to new file\r\n        id3 -D &quot;$INF&quot; -1 -2 &quot;$OUTF&quot;\r\n\r\n        # Copy non-flac\/non-wav (folder.jpg, etc...) files to dest\/dir\r\n        if [[ ! -e &quot;$DESTDIR$SUBDIR\/folder.jpg&quot; &amp;&amp; -e &quot;folder.jpg&quot; ]] ; then\r\n                cp folder.jpg &quot;$DESTDIR$SUBDIR&quot;\r\n        fi\r\n}\r\n\r\nfunction wav2mp3 () {\r\n        INF=&quot;$1&quot;\r\n        OUTF=`echo &quot;$INF&quot; | sed 's\/\\.wav$\/.flac\/'`\r\n\r\n        if [ -e &quot;$OUTF&quot; ] ; then\r\n                echo &quot;*** Skip wav2mp3! Output file already exists: $OUTF&quot;\r\n                return\r\n        fi\r\n\r\n        echo &quot;${INDENT}wav2mp3 Converting $INF =&gt; $OUTF&quot;\r\n        #touch &quot;$OUTF&quot;\r\n        flac -V -o &quot;$OUTF&quot; &quot;$INF&quot;\r\n        flac2mp3 &quot;$OUTF&quot;\r\n}\r\n\r\nfunction traveldir ()\r\n{\r\n        dir=&quot;$1&quot;\r\n\r\n        pushd &quot;$dir&quot; &gt; \/dev\/null\r\n        echo &quot;Entering: `pwd`&quot;\r\n\r\n        for a in *\r\n        do\r\n                if test -d &quot;$a&quot; ; then\r\n                        traveldir &quot;$a&quot;\r\n                else\r\n                        if [[ `expr match &quot;$a&quot; '.*\\\\.flac$'` &gt; 0 ]] ; then\r\n                                flac2mp3 &quot;$a&quot;\r\n                        elif [[ `expr match &quot;$a&quot; '.*\\\\.wav$'` &gt; 0 ]] ; then\r\n                                wav2mp3 &quot;$a&quot;\r\n                        else\r\n                                echo &quot;${INDENT}Skipping: $a&quot;\r\n                        fi\r\n                fi\r\n        done\r\n        popd &gt; \/dev\/null\r\n}\r\n\r\n################################################################################\r\n# main()\r\n################################################################################\r\n\r\nif [[ $# &lt; &quot;2&quot; ]] ; then\r\n        usage\r\n        exit 1\r\nfi\r\n\r\nSRCDIR=&quot;$1&quot;\r\nDESTDIR=&quot;$2&quot;\r\n\r\nif [[ ! -e &quot;$DESTDIR&quot; ]] ; then\r\n        mkdir -p &quot;$DESTDIR&quot;\r\nfi\r\n\r\nif [[ ! -e &quot;$SRCDIR&quot; ]] ; then\r\n        echo &quot;$SRCDIR does not exist!&quot;\r\n        exit 2\r\nfi\r\n\r\n# Get absolute directories\r\nSRCDIR=$(absname &quot;$SRCDIR&quot;)\r\nDESTDIR=`absname &quot;$DESTDIR&quot;`\r\n\r\nSRCDIRLEN=`expr length &quot;$SRCDIR&quot;`\r\nINDENT=&quot;    &quot;\r\n\r\npushd . &gt; \/dev\/null\r\ntraveldir &quot;$SRCDIR&quot;\r\npopd &gt; \/dev\/null\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In case it might be useful to others, here&#8217;s a script that can be used to convert a bunch of *.wav files to *.flac and *.flac files to *.mp3. The script will first first convert all *.wav files (if any) to *.flac, then it will convert all *.flac files to *.mp3. See the usage instructions [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[16,5,14,12,13,17,15],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-audio","tag-bash","tag-flac","tag-linux","tag-mp3","tag-script","tag-wav"],"_links":{"self":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":20,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":668,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions\/668"}],"wp:attachment":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}