<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Merge mp3s with PHP?</title>
	<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP/</link>
	<description>Comments on Ask MetaFilter post Merge mp3s with PHP?</description>
	<pubDate>Mon, 18 Jul 2005 15:28:03 -0800</pubDate>
	<lastBuildDate>Mon, 18 Jul 2005 15:28:03 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Merge mp3s with PHP?</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP</link>	
		<description>How can I merge multiple MP3s into a single MP3 using a web scripting language such as PHP, ASP.NET, etc.? &lt;br /&gt;&lt;br /&gt; You&apos;d think this would be the kind of thing you could just look up on Google, but I&apos;ve had a heck of a time finding anything close to what I&apos;m looking for.&lt;br&gt;
&lt;br&gt;
Specifically, I&apos;ve got a bunch of small MP3 snippets, and I want to merge them end-to-end into a single MP3 file.&lt;br&gt;
&lt;br&gt;
There are Windows-based tools that will do this, but I need to automate it for a website.  &lt;br&gt;
&lt;br&gt;
All I&apos;m finding on Google are scripts having to do with playlists or ID3 tags. Haven&apos;t been able to come up with anything about actually manipulating mp3 files.&lt;br&gt;
&lt;br&gt;
Any suggestions?</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2005:site.21381</guid>
		<pubDate>Mon, 18 Jul 2005 15:06:13 -0800</pubDate>
		<dc:creator>oissubke</dc:creator>
		
			<category>mp3</category>
		
			<category>web</category>
		
			<category>scripting</category>
		
			<category>programming</category>
		
	</item> <item>
		<title>By: mbrubeck</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345427</link>	
		<description>I believe you can simply concatenate MP3 files to join them.  Execute the &quot;cat&quot; command on Unix-like systems, or write your own code to open each input file in turn and write its contents to the output file.&lt;br&gt;
&lt;br&gt;
Warning: This can leave garbage like ID3 tags in the middle of the resulting file, making it technically invalid.  Most programs can still play the file, but some might not.&lt;br&gt;
&lt;br&gt;
For a more &quot;correct&quot; solution, you will need to call a library or executable that understands MPEG streams.  What operating system are you using, and do you have a preferred programming language?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345427</guid>
		<pubDate>Mon, 18 Jul 2005 15:28:03 -0800</pubDate>
		<dc:creator>mbrubeck</dc:creator>
	</item><item>
		<title>By: Rothko</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345430</link>	
		<description>mbrubeck, using &quot;cat&quot; will only play the first MP3 in the concatenated file.&lt;br&gt;
&lt;br&gt;
If you run Cygwin or Linux, you can compile &lt;a href=&quot;http://sox.sourceforge.net/&quot;&gt;SoX&lt;/a&gt; to include MP3 support, then modify &lt;a href=&quot;http://www.dausha.net/index.php/Technical/JoinWavs&quot;&gt;this script&lt;/a&gt; to join MP3 files on the command-line. Anything you can do on the command line &lt;a href=&quot;http://us2.php.net/system&quot;&gt;you can script with PHP&lt;/a&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345430</guid>
		<pubDate>Mon, 18 Jul 2005 15:30:22 -0800</pubDate>
		<dc:creator>Rothko</dc:creator>
	</item><item>
		<title>By: mbrubeck</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345439</link>	
		<description>The SoX script apparently requires decoding and then re-encoding the MP3 files, resulting in a loss of quality.  It would be better to do the same thing using a program like &lt;a href=&quot;http://mpgtx.sourceforge.net/&quot;&gt;mpgtx&lt;/a&gt;, which works losslessly.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345439</guid>
		<pubDate>Mon, 18 Jul 2005 15:40:10 -0800</pubDate>
		<dc:creator>mbrubeck</dc:creator>
	</item><item>
		<title>By: revgeorge</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345445</link>	
		<description>What mbrubeck said.  &lt;pre&gt;&lt;code&gt;header(&apos;Content-type: audio/mpeg&apos;);&lt;br&gt;
readfile(&apos;foo.mp3&apos;);&lt;br&gt;
readfile(&apos;bar.mp3&apos;);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
It&apos;s not going to make valid MP3s, but if you want archival quality materials you probably shouldn&apos;t be using MP3.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345445</guid>
		<pubDate>Mon, 18 Jul 2005 15:47:04 -0800</pubDate>
		<dc:creator>revgeorge</dc:creator>
	</item><item>
		<title>By: cillit bang</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345467</link>	
		<description>MPEG uses a robust streaming architecture for its files that means if there&apos;s garbage in the middle, it can move through it, recognise where valid MPEG data begins again, and re-synchronize.&lt;br&gt;
&lt;br&gt;
ID3 tags are themselves garbage data added to the beginning or end of a valid chunk of MPEG frames, and the designers of ID3 assumed players would skip over them. Therefore an MP3 with tags in the middle is no less valid then one with tags anywhere else (See Section 3, &lt;a href=&quot;http://www.id3.org/id3v2-00.txt&quot;&gt;here&lt;/a&gt;).&lt;br&gt;
&lt;br&gt;
So yes, use concat if your needs are simple. I&apos;ve jus ttried it with iTunes and QuickTime, and both play fine.&lt;br&gt;
&lt;br&gt;
(NB This is based on hearsay, I haven&apos;t read up on it formally)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345467</guid>
		<pubDate>Mon, 18 Jul 2005 16:11:44 -0800</pubDate>
		<dc:creator>cillit bang</dc:creator>
	</item><item>
		<title>By: sbutler</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345484</link>	
		<description>Alright, I&apos;m basing my information on &lt;a href=&quot;http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm&quot;&gt;this doc&lt;/a&gt;. An mp3 file format consists of a series of frames, each with its own header and payload. Therefore, in this setting you should be able to just concatenate two mp3 files together and get a valid file out.&lt;br&gt;
&lt;br&gt;
&lt;strong&gt;Except&lt;/strong&gt; for the ID3v1 tag which is 128 bits on the end. So, it would probably be best to remove the ID3 tags from each file before joining them (this is just ID3v1 tags, I don&apos;t know how v2+ work).&lt;br&gt;
&lt;br&gt;
&lt;strong&gt;Except&lt;/strong&gt;, mp3 frames are apparently allowed to reference other frames in the file. I don&apos;t know how they do this. If you&apos;re lucky, they use a relative offset so that the frame is relocatable. If you&apos;re not, then they use an absolute offset and you&apos;re screwed.&lt;br&gt;
&lt;br&gt;
But emperical evidence suggests catting two files together should work so I guess it&apos;s a relative offset. If you can figure out how to remove the ID3 tags then I think you&apos;ll be good in almost all situations.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345484</guid>
		<pubDate>Mon, 18 Jul 2005 16:27:00 -0800</pubDate>
		<dc:creator>sbutler</dc:creator>
	</item><item>
		<title>By: sbutler</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345486</link>	
		<description>Actually, PHP has an &lt;a href=&quot;http://www.php.net/manual/en/function.id3-remove-tag.php&quot;&gt;id3_remove_tag&lt;/a&gt; function, which is exactly what you want. Good luck!</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345486</guid>
		<pubDate>Mon, 18 Jul 2005 16:29:30 -0800</pubDate>
		<dc:creator>sbutler</dc:creator>
	</item><item>
		<title>By: blue_beetle</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345526</link>	
		<description>note: ASP.NET is not a scripting language. It&apos;s a set of technologies, in which a scripting language can be a part.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345526</guid>
		<pubDate>Mon, 18 Jul 2005 17:46:26 -0800</pubDate>
		<dc:creator>blue_beetle</dc:creator>
	</item><item>
		<title>By: ph00dz</title>
		<link>http://ask.metafilter.com/21381/Merge-mp3s-with-PHP#345580</link>	
		<description>Neat! I never knew that php had that, sbutler. Those php d00dz have just thought of everything, haven&apos;t they?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21381-345580</guid>
		<pubDate>Mon, 18 Jul 2005 19:36:11 -0800</pubDate>
		<dc:creator>ph00dz</dc:creator>
	</item>
	</channel>
</rss>
