1

Okay so i have this idea for a weekend project where I want to transcode flv/mp4 streams directly into mp3 format.

How can I easily do that via PHP/Apache on a CentOS Server? (hopefully not as CPU intensive as FFMPEG) Any idea's are appreciated!

:)

BoRo
  • 11
  • 1

1 Answers1

2

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.

Sam Halicke
  • 6,122
  • 1
  • 24
  • 35
  • Awww fudge! I was hoping for a ffmpeg-alternative :( and you can run that using the exec() or system() php functions. do you think i can limit ffmpeg to one core only? when it runs, it takes 90% of the CPU;s processing power....meanwhile apache lags/opens pages very slowly :S Thanks tho! :) – BoRo Nov 05 '10 at 23:54
  • Use taskset (see edits above) – Sam Halicke Nov 06 '10 at 00:19