It appears that proc_open() is what I was looking for. Here's the snippet of code I wrote and tested that does exactly what I was looking for:
Where:
- $wav is the original WAV data to be converted.
- $mp3 holds the converted MP3 data,
$descriptorspec = array(
0 => array( "pipe", "r" ),
1 => array( "pipe", "w" ),
2 => array( "file", "/dev/null", "w" )
);
$process = proc_open( "/usr/bin/lame --cbr -b 32k - -", $descriptorspec, $pipes );
fwrite( $pipes[0], $wav );
fclose( $pipes[0] );
$mp3 = stream_get_contents( $pipes[1] );
fclose( $pipes[1] );
proc_close( $process );
The final outputted data is identical to if I had run /usr/bin/lame --cbr -b 32k in.wav out.mp3
.