你如何音频文件(动态),转换为浏览器? [英] How do you convert audio files (on the fly) to the browser?

查看:251
本文介绍了你如何音频文件(动态),转换为浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将音频文件转换成MP3到用户的浏览器上飞。我使用的软件是:了Apache,PHP和放大器; FFMPEG一个Ubuntu系统。这里是code我到目前为止有:

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 -');
?>

通过这个code,只有音频的前几秒被转换,但是,当我注释掉头功能,音频文件是完全转换,但所有二进制数据是通过对筛(而不是包裹在浏览器中的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).

有什么想法?

推荐答案

嗯,我发现那位答案。你算算输出流的大小和输出以下头(音频流输出前):

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}");

这篇关于你如何音频文件(动态),转换为浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆