<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to resample MP3 audio files on Linux using LAME</title>
	<atom:link href="http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/feed/" rel="self" type="application/rss+xml" />
	<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/</link>
	<description>Linux Tweaks, HowTo&#039;s and Reviews</description>
	<lastBuildDate>Thu, 17 May 2012 22:10:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Toby</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-8518</link>
		<dc:creator>Toby</dc:creator>
		<pubDate>Tue, 24 Apr 2012 16:27:59 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-8518</guid>
		<description>&lt;blockquote cite=&quot;&quot;&gt;IFS=$&#039;\n&#039;; find -type f -iname &quot;*.mp3&quot; &#124; while read i; do /home/alexsmith/scripts/mp3shrink.sh &quot;$i&quot; &amp; done

Be careful when using this, since it will shrink all files in background, easily overloading the CPU.&lt;/blockquote&gt;

What you need is &lt;a href=&quot;http://www.maier-komor.de/xjobs.html&quot; rel=&quot;nofollow&quot;&gt;xjobs&lt;/a&gt; (from a package manager near you):

&lt;code&gt;find -type f -iname &quot;*.mp3&quot; &#124; xjobs $HOME/scripts/mp3shrink.sh&lt;/code&gt;

(P.S. you should use ${TMPDIR-/tmp} in place of plain old /tmp, then you can point it somewhere in the same filesystem as the music, to make the final copy stage faster - and to work with systems using e.g. pam_tmpdir)</description>
		<content:encoded><![CDATA[<blockquote cite=""><p>IFS=$'\n'; find -type f -iname "*.mp3" | while read i; do /home/alexsmith/scripts/mp3shrink.sh "$i" &amp; done</p>
<p>Be careful when using this, since it will shrink all files in background, easily overloading the CPU.</p></blockquote>
<p>What you need is <a href="http://www.maier-komor.de/xjobs.html" rel="nofollow">xjobs</a> (from a package manager near you):</p>
<p><code>find -type f -iname "*.mp3" | xjobs $HOME/scripts/mp3shrink.sh</code></p>
<p>(P.S. you should use ${TMPDIR-/tmp} in place of plain old /tmp, then you can point it somewhere in the same filesystem as the music, to make the final copy stage faster - and to work with systems using e.g. pam_tmpdir)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Linerd</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-7426</link>
		<dc:creator>Linerd</dc:creator>
		<pubDate>Thu, 17 Nov 2011 21:07:01 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-7426</guid>
		<description>Thanks for the script. I haven&#039;t gotten back into this to rewrite it using gstreamer. It&#039;s definitely a cleaner way to go about it. :)</description>
		<content:encoded><![CDATA[<p>Thanks for the script. I haven't gotten back into this to rewrite it using gstreamer. It's definitely a cleaner way to go about it. <img src='http://tuxtweaks.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elder-Geek</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-7425</link>
		<dc:creator>Elder-Geek</dc:creator>
		<pubDate>Thu, 17 Nov 2011 19:45:52 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-7425</guid>
		<description>If you are looking for the script above modified to use gStremamer, here it is.
This script uses gStreamer instead of lame and id3v to re sample mp3s while preserving v1 and v2 tags as well as embedded cover art. It requires &lt;em&gt;gstreamer-tools&lt;/em&gt; and there is no need for the &lt;em&gt;cptag&lt;/em&gt; script

&lt;code&gt;
#!/bin/bash
#
#mp3shrink - A script to resample all mp3 files in a
# directory.  This script depends upon gstremar-tools
#
# It is suggested that mp3shink be placed in the 
# user&#039;s private bin (~/bin).
######################################################

# List mp3&#039;s in current directory.
ls *.mp3 &gt; mp3_list
ls *.MP3 &gt;&gt; mp3_list

# Parse the mp3_list and replace spaces with escaped spaces.
sed -i &#039;s: :\\ :g&#039; mp3_list

# Check if resample directory exists and create it if it doesn&#039;t.
if
   test -e ./resample
then
   echo &quot;resample directory/file already exists - delete it? (Y/n)&quot;
   read reply
   if
     [ &quot;$reply&quot; != &quot;n&quot; ]
   then
     rm -r resample
     mkdir resample
   else
     exit
   fi
else
   mkdir resample
fi

# Resample each mp3 and write tags using the cptag script
# CBR bitrate bitrate=128
# VBR quality quality=9 

cat mp3_list &#124;while read song
do
   echo &quot;$song&quot;
   gst-launch filesrc location= \&quot;$song\&quot; ! decodebin2 ! audioconvert ! lamemp3enc target=bitrate bitrate=128 ! id3v2mux ! filesink location=\&quot;resample/$song\&quot;
done

#clean up
if
   test -e mp3_list
then
   rm mp3_list
fi
if
   test -e tag2.txt
then
   rm tag2.txt
fi
exit
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>If you are looking for the script above modified to use gStremamer, here it is.<br />
This script uses gStreamer instead of lame and id3v to re sample mp3s while preserving v1 and v2 tags as well as embedded cover art. It requires <em>gstreamer-tools</em> and there is no need for the <em>cptag</em> script</p>
<p><code><br />
#!/bin/bash<br />
#<br />
#mp3shrink - A script to resample all mp3 files in a<br />
# directory.  This script depends upon gstremar-tools<br />
#<br />
# It is suggested that mp3shink be placed in the<br />
# user's private bin (~/bin).<br />
######################################################</p>
<p># List mp3's in current directory.<br />
ls *.mp3 &gt; mp3_list<br />
ls *.MP3 &gt;&gt; mp3_list</p>
<p># Parse the mp3_list and replace spaces with escaped spaces.<br />
sed -i 's: :\\ :g' mp3_list</p>
<p># Check if resample directory exists and create it if it doesn't.<br />
if<br />
   test -e ./resample<br />
then<br />
   echo "resample directory/file already exists - delete it? (Y/n)"<br />
   read reply<br />
   if<br />
     [ "$reply" != "n" ]<br />
   then<br />
     rm -r resample<br />
     mkdir resample<br />
   else<br />
     exit<br />
   fi<br />
else<br />
   mkdir resample<br />
fi</p>
<p># Resample each mp3 and write tags using the cptag script<br />
# CBR bitrate bitrate=128<br />
# VBR quality quality=9 </p>
<p>cat mp3_list |while read song<br />
do<br />
   echo "$song"<br />
   gst-launch filesrc location= \"$song\" ! decodebin2 ! audioconvert ! lamemp3enc target=bitrate bitrate=128 ! id3v2mux ! filesink location=\"resample/$song\"<br />
done</p>
<p>#clean up<br />
if<br />
   test -e mp3_list<br />
then<br />
   rm mp3_list<br />
fi<br />
if<br />
   test -e tag2.txt<br />
then<br />
   rm tag2.txt<br />
fi<br />
exit<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Smith</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-6957</link>
		<dc:creator>Alex Smith</dc:creator>
		<pubDate>Thu, 13 Oct 2011 14:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-6957</guid>
		<description>Hi, guys!

Thanks a lot for the scripts!

I found a very nice package which copies id3tags directly in an easier manner.

&lt;code&gt;
sudo apt-get install libid3-tools
&lt;/code&gt;

This lib has a nice binary called id3cp, which copies all id3tags from one file to another.

Thus, the script became simpler, like this:

&lt;code&gt;
#!/bin/bash

if [ $(file --mime &quot;$1&quot; &#124; grep &quot;audio/mpeg&quot; &#124; wc -l) -eq 0 ]
then
    echo &quot;Not an mp3 file: $i&quot;
    exit 1
fi

echo &quot;Shrinking $1&quot;
tmp=$(basename &quot;$1&quot;)
lame --silent -v --preset standard &quot;$1&quot; &quot;/tmp/$tmp&quot;
id3cp &quot;$1&quot; &quot;/tmp/$tmp&quot;
mv &quot;/tmp/$tmp&quot; &quot;$1&quot;
echo &quot;Done shrinking $1&quot;
&lt;/code&gt;

Note that I modified the script to encode one file at a time, thus making it possible to process multiple files in background with something like this:

&lt;code&gt;
IFS=$&#039;\n&#039;; find -type f -iname &quot;*.mp3&quot; &#124; while read i; do /home/alexsmith/scripts/mp3shrink.sh &quot;$i&quot; &amp; done
&lt;/code&gt;

Be careful when using this, since it will shrink all files in background, easily overloading the CPU.

To shrink a single file, one could just type this:

&lt;code&gt;
./mp3shrink.sh inputfile.mp3
&lt;/code&gt;

After the process, inputfile.mp3 will be shrinked down. Please note that inputfile.mp3 itself will get shrinked. This may not be what you want.</description>
		<content:encoded><![CDATA[<p>Hi, guys!</p>
<p>Thanks a lot for the scripts!</p>
<p>I found a very nice package which copies id3tags directly in an easier manner.</p>
<p><code><br />
sudo apt-get install libid3-tools<br />
</code></p>
<p>This lib has a nice binary called id3cp, which copies all id3tags from one file to another.</p>
<p>Thus, the script became simpler, like this:</p>
<p><code><br />
#!/bin/bash</p>
<p>if [ $(file --mime "$1" | grep "audio/mpeg" | wc -l) -eq 0 ]<br />
then<br />
    echo "Not an mp3 file: $i"<br />
    exit 1<br />
fi</p>
<p>echo "Shrinking $1"<br />
tmp=$(basename "$1")<br />
lame --silent -v --preset standard "$1" "/tmp/$tmp"<br />
id3cp "$1" "/tmp/$tmp"<br />
mv "/tmp/$tmp" "$1"<br />
echo "Done shrinking $1"<br />
</code></p>
<p>Note that I modified the script to encode one file at a time, thus making it possible to process multiple files in background with something like this:</p>
<p><code><br />
IFS=$'\n'; find -type f -iname "*.mp3" | while read i; do /home/alexsmith/scripts/mp3shrink.sh "$i" &amp; done<br />
</code></p>
<p>Be careful when using this, since it will shrink all files in background, easily overloading the CPU.</p>
<p>To shrink a single file, one could just type this:</p>
<p><code><br />
./mp3shrink.sh inputfile.mp3<br />
</code></p>
<p>After the process, inputfile.mp3 will be shrinked down. Please note that inputfile.mp3 itself will get shrinked. This may not be what you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Othmane</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-6835</link>
		<dc:creator>Othmane</dc:creator>
		<pubDate>Mon, 03 Oct 2011 11:47:50 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-6835</guid>
		<description>Thank you for this great script! :D</description>
		<content:encoded><![CDATA[<p>Thank you for this great script! <img src='http://tuxtweaks.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Linerd</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-6771</link>
		<dc:creator>Linerd</dc:creator>
		<pubDate>Mon, 26 Sep 2011 23:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-6771</guid>
		<description>You might be interested in this post showing how to resample using gstreamer. http://wp.me/pB103-sn</description>
		<content:encoded><![CDATA[<p>You might be interested in this post showing how to resample using gstreamer. <a href="http://wp.me/pB103-sn" rel="nofollow">http://wp.me/pB103-sn</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-6761</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Mon, 26 Sep 2011 18:16:29 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-6761</guid>
		<description>This is fantastic! The only change I made was to add an option to find the track&#039;s year.  Thanks!</description>
		<content:encoded><![CDATA[<p>This is fantastic! The only change I made was to add an option to find the track's year.  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Linerd</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-5038</link>
		<dc:creator>Linerd</dc:creator>
		<pubDate>Wed, 02 Mar 2011 02:17:10 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-5038</guid>
		<description>You&#039;re welcome. This post is pretty old. If I were to do it again I&#039;d probably try something with Gstreamer. It&#039;s an audio framework for Linux. In my script above I had to do some work-arounds for a bug in LAME in order to keep some of the tags. Gstreamer tends to do a good job of keeping tags as well as embedded album art. Check out these posts. They won&#039;t show exactly how to resample MP3&#039;s, but it should give you an idea how to do it. http://tuxtweaks.com/tag/gstreamer/</description>
		<content:encoded><![CDATA[<p>You're welcome. This post is pretty old. If I were to do it again I'd probably try something with Gstreamer. It's an audio framework for Linux. In my script above I had to do some work-arounds for a bug in LAME in order to keep some of the tags. Gstreamer tends to do a good job of keeping tags as well as embedded album art. Check out these posts. They won't show exactly how to resample MP3's, but it should give you an idea how to do it. <a href="http://tuxtweaks.com/tag/gstreamer/" rel="nofollow">http://tuxtweaks.com/tag/gstreamer/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-5037</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Wed, 02 Mar 2011 00:57:34 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-5037</guid>
		<description>Thank you for an amazing script. They both worked perfectly the first time. However it doesn&#039;t copy the embedded image over. Not a huge deal, but I will see if there is another script that has that feature. Thanks for writing this one.</description>
		<content:encoded><![CDATA[<p>Thank you for an amazing script. They both worked perfectly the first time. However it doesn't copy the embedded image over. Not a huge deal, but I will see if there is another script that has that feature. Thanks for writing this one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: masat</title>
		<link>http://tuxtweaks.com/2008/08/how-to-resample-mp3-audio-files-on-linux-using-lame/comment-page-1/#comment-4517</link>
		<dc:creator>masat</dc:creator>
		<pubDate>Mon, 15 Nov 2010 06:01:38 +0000</pubDate>
		<guid isPermaLink="false">http://linugadgetech.wordpress.com/2008/08/10/how-to-resample-mp3-audio-files-on-linux-using-lame/#comment-4517</guid>
		<description>Nice script Linerd!, just what I was looking for. It worked fine for me after the adds from AAM and Luca. I like to keep the directory structure of my music collection also in my music player, thus I made some minor changes to deal with this. 
1.I used &#039;find&#039; instead of &#039;ls&#039; to list files with full path
2.I add a line to copy the directory structure of the music collection to encode into the resample dir.
3.Finally, I put check for resample directory first, before listing mp3s, otherwise preexistent files will be listed

Here is the modified script: 
[term]&lt;pre&gt;
#!/bin/bash
#
#mp3shrink - A script to resample all mp3 files in a
# directory.  This script calls the cptag script which
# must also be in the user&#039;s path. cptag depends upon
# lame and mid3v2 (mid3v2 can be found in the
# python-mutagen package).
#
# It is suggested that both the mp3shink and cptag
# scripts be placed in the user&#039;s private bin (~/bin).
######################################################

# Check if resample directory exists and create it if it doesn&#039;t.
if
   test -e ./resample
then
   echo &quot;resample directory/file already exists - delete it? (Y/n)&quot;
   read reply
   if
     [ &quot;$reply&quot; != &quot;n&quot; ]
   then
     rm -r resample
     mkdir resample
   else
     exit
   fi
else
   mkdir resample
fi

#Copy directory structure of the music collection to encode into resample directory
find . -type d &#124; cpio -pvdm ./resample; rm -r ./resample/resample 

# List mp3&#039;s in current directory.
find . -name \*.mp3 &gt; mp3_list
find . -name \*.MP3 &gt;&gt; mp3_list

# Parse the mp3_list and replace spaces with escaped spaces.
sed -i &#039;s: :\\ :g&#039; mp3_list

# Resample each mp3 and write tags using the cptag script
cat mp3_list &#124;while read song
do
   echo &quot;$song&quot;
   ~/bin/cptag &quot;$song&quot;
done

#clean up
if
   test -e mp3_list
then
   rm mp3_list
fi

if
   test -e tag2.txt
then
   rm tag2.txt
fi

exit
&lt;/pre&gt;[/term]

Hope somebody find this post useful as I did with previous comments.</description>
		<content:encoded><![CDATA[<p>Nice script Linerd!, just what I was looking for. It worked fine for me after the adds from AAM and Luca. I like to keep the directory structure of my music collection also in my music player, thus I made some minor changes to deal with this.<br />
1.I used 'find' instead of 'ls' to list files with full path<br />
2.I add a line to copy the directory structure of the music collection to encode into the resample dir.<br />
3.Finally, I put check for resample directory first, before listing mp3s, otherwise preexistent files will be listed</p>
<p>Here is the modified script: </p>
<div class="term">
<pre>
#!/bin/bash
#
#mp3shrink - A script to resample all mp3 files in a
# directory.  This script calls the cptag script which
# must also be in the user's path. cptag depends upon
# lame and mid3v2 (mid3v2 can be found in the
# python-mutagen package).
#
# It is suggested that both the mp3shink and cptag
# scripts be placed in the user's private bin (~/bin).
######################################################

# Check if resample directory exists and create it if it doesn't.
if
   test -e ./resample
then
   echo "resample directory/file already exists - delete it? (Y/n)"
   read reply
   if
     [ "$reply" != "n" ]
   then
     rm -r resample
     mkdir resample
   else
     exit
   fi
else
   mkdir resample
fi

#Copy directory structure of the music collection to encode into resample directory
find . -type d | cpio -pvdm ./resample; rm -r ./resample/resample 

# List mp3's in current directory.
find . -name \*.mp3 &gt; mp3_list
find . -name \*.MP3 &gt;&gt; mp3_list

# Parse the mp3_list and replace spaces with escaped spaces.
sed -i 's: :\\ :g' mp3_list

# Resample each mp3 and write tags using the cptag script
cat mp3_list |while read song
do
   echo "$song"
   ~/bin/cptag "$song"
done

#clean up
if
   test -e mp3_list
then
   rm mp3_list
fi

if
   test -e tag2.txt
then
   rm tag2.txt
fi

exit
</pre>
</div>
<p>Hope somebody find this post useful as I did with previous comments.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

