Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

:)

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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 5 '10 at 23:54
    
Use taskset (see edits above) –  Sam Halicke Nov 6 '10 at 0:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.