dongzhi6905 2009-10-22 16:55
浏览 56
已采纳

如何将音频文件(动态)转换为浏览器?

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 converted, 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?

  • 写回答

1条回答 默认 最新

  • duanhan5388 2009-10-22 21:02
    关注

    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}"); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料