Skip to content

Instantly share code, notes, and snippets.

@mdwheele
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdwheele/e55538ac6c4a7f20c609 to your computer and use it in GitHub Desktop.
Save mdwheele/e55538ac6c4a7f20c609 to your computer and use it in GitHub Desktop.
.DS_Store
.idea/

Barebones PHP Concat MP3 with LAME

This is a simple PHP script that uses lame to concatenate MP3 files. It does NO error checking beyond what LAME might figure out and also does no shell escaping. I heavily advise against using this in any production capacity and would also advise it only be used as a baseline minimal viable product to build upon.

Syntax

php concat.php [input files ...] [output file]

Examples

Concatenate two MP3 files: php concat.php low.mp3 high.mp3 merged.mp3

Concatenate an entire directory: php concat.php *.mp3 merged.mp3

<?php
// Take script name out of argv[0]
array_shift($argv);
$output = array_pop($argv);
// Get filenames
$files = $argv;
// Build command
$command = sprintf(
'for f in %s; do lame --decode --mp3input $f -; done | lame -a -b 96 - %s',
implode(' ', $files),
$output
);
// Run that command
exec($command);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment