开发者

How do you convert audio files (on the fly) to the browser?

I would like to be able to convert audio files to MP3 to the users browser on the fly. The software I am using is: Apache, PHP & FFMPEG on an ubuntu system. Here is the code I have so far:

<?php
     header("Content-Transfer-Encoding: binary");
     header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");

     passthru('ffmpeg -i song.flac -v 0 -ab 320k -f mp3 -');
?>

With this code, only the first few seconds of the audio are convert开发者_运维知识库ed, however, when I comment out the header functions, the audio file is completely converted but all binary data is passed through to the screen (instead of wrapped in the browsers mp3 player).

Any thoughts?


Well i fount the answer. You have to calculate the output stream's size and output the following header (before the audio stream output):

header("Content-Length: {$calculatedFileSize}"); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜