Firstly, ffmpeg
is the tool of choice for this. It's CPU-intensive because that's the nature of encoding video or audio.
You can simply rip the stream (assuming original mp3 audio is in the stream) from the track and save it. I've used this bash
snippet before for directories of *.flv
files:
#!/bin/bash
for i in *.flv;
do ffmpeg -i "$i" -acodec copy `basename $i .flv`-`date +%H%M%S%N`.mp3;
done
If the stream is not natively in mp3 format, you need to re-encode. Or perhaps you want a different bitrate, etc. This task will definitely consume more CPU than the former:
ffmpeg -i "$file" -f mp3 -vn -acodec libmp3lame -ab 192 `basename $file .flv`-`date +%H%M%S%N`.mp3;
edit: to limit to one core: taskset 1 ffmpeg <rest of args>
-- taskset
is part of the util-linux
package on Debian systems. You may also want to renice
the process, setting its priority value to something in the positive range (sounds backwards, but lower nice
value = more cpu time). As always, man taskset
, man renice
, man nice
.
This is how you do what you want to do with ffmpeg from the shell -- implementing in PHP is left as an exercise for the reader.