简体   繁体   English

流式传输为html5音频或将.amr转换为.ogg

[英]Stream as html5 audio or convert .amr to .ogg

I want to stream .amr audio files on my server. 我想在我的服务器上传输.amr音频文件。 After spending a couple hours of research, it's clear to me that this is not feasible under the current state of html5 audio. 经过几个小时的研究后,我很清楚,在目前的html5音频状态下,这是不可行的。 Following this disappointing finding, I spent several additional hours looking for a simple way to convert .amr files to .ogg, with similarly disappointing results. 在这个令人失望的发现之后,我花了几个小时寻找一种简单的方法将.amr文件转换为.ogg,同样令人失望的结果。

I'm shocked that after well over 10 years of use, there is no simple way to play/convert files encoded under this standard, but can someone please help me to find a usable solution? 令我震惊的是,经过10多年的使用,没有简单的方法来播放/转换根据此标准编码的文件,但是有人可以帮我找到可用的解决方案吗? The closest viable options seem to be sox and ffmpeg . 最接近的可行选项似乎是soxffmpeg I'm ideally looking for a concise set of instructions for converting .amr to .ogg directly from php but using the command line would be fine. 我理想地寻找一个简明的指令集,直接从php转换.amr到.ogg但是使用命令行就没问题了。

I am about to dig into the specifics of using these two libraries but figured that I would post here in hopes that some kind soul might help enlighten others that are under time constraints and so do not wish to spend an afternoon untangling the use-case specifics of what should be a straightforward task. 我将深入研究使用这两个库的具体细节,但我想我会发布这里希望某些灵魂可能有助于启发那些受时间限制的人,所以不希望花一个下午来解决用例细节什么应该是一个简单的任务。 If someone else does not post, I will answer the question myself. 如果其他人没有发帖,我会自己回答这个问题。

Here are some of the other 'answers' that I've found which led me to post here: 以下是我发现的一些其他“答案”,这些答案促使我发布在这里:

If you are about to mark this as 'off-topic' or close the question for some other reason, please consider the following: 如果您要将此标记为“偏离主题”或因其他原因而关闭该问题,请考虑以下事项:

A search on https://superuser.com/search?q=convert+.amr+to+.ogg , which is stated in at least one of the above links as the appropriate forum for the question, (as of today) results in 4 posts, none of which even remotely address this question. https://superuser.com/search?q=convert+.amr+to+.ogg上搜索,至少在上述链接之一中作为问题的适当论坛(截至今天),帖子,其中没有一个甚至远程解决这个问题。

The SO Posting Guidelines seem to me to be completely in alignment with this kind of question. 在我看来, SO发布指南完全符合这类问题。 I'm baffled as to why someone would close the questions that came up in my search. 我很困惑为什么有人会关闭我搜索中出现的问题。 I'm a very experienced developer, asking a question directly related to development work that I'm doing, and have been blocked by an issue that I would like to provide a solution for to aid in other developers being held up by similar issues. 我是一个非常有经验的开发人员,他提出了一个与我正在进行的开发工作直接相关的问题,并且被一个我希望提供解决方案的问题所阻止,以帮助其他开发人员遇到类似问题。

The fact that nothing came up in my search to save me from doing hours of research leads me to see this as a worthy question for SO. 事实上,在我的搜索中没有出现让我免于进行数小时研究的事实,这使我认为这是一个值得思考的问题。 Please help restore my sentiment for this site which is a valuable resource but has left me cold due to so many of these kinds of senseless and seemingly indiscriminate post closings. 请帮助恢复我对这个网站的感情,这是一个宝贵的资源,但由于这么多无意义和看似不分青红皂白的关闭后,让我感到很冷。

Thanks... 谢谢...

If you're in an environment where the tools are already installed, converting the file is actually a very simple procedure. 如果您处于已安装工具的环境中,则转换文件实际上是一个非常简单的过程。 For ffmpeg and sox, the commands in their most basic forms are just: 对于ffmpeg和sox,最基本形式的命令只是:

ffmpeg -i ./file.amr ./file.ogg

or 要么

sox ./file.amr ./file.ogg

So if we upload a file with an input name of 'audio', from PHP this would look something like: 因此,如果我们上传一个输入名称为'audio'的文件,那么从PHP看起来就像这样:

<?php
if (isset($_FILES['audio']) && is_file($TmpFile=$_FILES['audio']['tmp_name'])) {
    // I name uploaded files as curr ms timestamp and track file data via db. 
    $NewFile = './uploads/'.round(microtime(true)*1000).'.ogg';  
    shell_exec("ffmpeg -i {$TmpFile} -acodec libvorbis ".$NewFile);
    // You'll want to add other file data to the database here...
} else {
    // Deal with bad file uploads...
}
?>

Unfortunately, my server environment doesn't have these tools installed, so I have to compile them manually. 不幸的是,我的服务器环境没有安装这些工具,所以我必须手动编译它们。 For my case specifically, I'm using a virtual shared host so I don't have universal access privileges on the system. 对于我的具体情况,我使用的是虚拟共享主机,因此我没有对系统的通用访问权限。 Keep in mind that this is reflected in some of the code I'm using to install the various ffmpeg components. 请记住,这反映在我用于安装各种ffmpeg组件的一些代码中。

cd ~/
curl -O http://ffmpeg.org/releases/ffmpeg-2.0.tar.gz
tar -xzvf ffmpeg-2.0.tar.gz
mv -fv ./ffmpeg-2.0 ./ffmpeg
rm -v ./ffmpeg-2.0.tar.gz

cd ~/ffmpeg
curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz
tar -xzvf libogg-1.3.1.tar.gz
rm -v libogg-1.3.1.tar.gz
cd libogg-1.3.1
./configure --prefix="$HOME/ffmpeg" --disable-shared
make
make install
make distclean

cd ~/ffmpeg/
curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
tar -xzvf libvorbis-1.3.3.tar.gz
rm -v libvorbis-1.3.3.tar.gz
cd libvorbis-1.3.3
./configure --prefix="$HOME/ffmpeg" --with-ogg="$HOME/ffmpeg" --disable-shared
make
make install
make distclean

cd ~/ffmpeg/
curl -O -L http://sourceforge.net/projects/opencore-amr/files/opencore-amr/opencore-amr-0.1.3.tar.gz
tar -xzvf opencore-amr-0.1.3.tar.gz
rm -v opencore-amr-0.1.3.tar.gz
cd opencore-amr-0.1.3
./configure --prefix="$HOME/ffmpeg" --disable-shared --bindir="$HOME/bin"
make
make install
make distclean

cd ~/ffmpeg/
curl -O http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar -xzvf yasm-1.2.0.tar.gz
rm -v yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix="$HOME/ffmpeg" --bindir="$HOME/bin"
make
make install
make distclean


cd ~/ffmpeg/
mkdir ~/ffmpeg/tmp
chmod 777 ~/ffmpeg/tmp
export TMPDIR="$HOME/ffmpeg/tmp"
export PKG_CONFIG_PATH="$HOME/ffmpeg/lib/pkgconfig"
./configure --prefix="$HOME/ffmpeg" --extra-cflags="-I$HOME/ffmpeg/include" --extra-ldflags="-L$HOME/ffmpeg/lib" --bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl --enable-nonfree --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvorbis
make
make install
make distclean
rm -rfv $TMPDIR
export TMPDIR=""
export PKG_CONFIG_PATH=""

You could just copy and paste the above bash commands into a shell, or you could put them into an executable script, and it should take care of everything. 您可以将上面的bash命令复制并粘贴到shell中,也可以将它们放入可执行脚本中,它应该处理所有事情。 You'll probably want to check for the newest versions of each component and update the code accordingly. 您可能希望检查每个组件的最新版本并相应地更新代码。 You may also want to add other libraries if you're working with different file formats as well, but this boiled down to what I needed specifically. 如果你正在使用不同的文件格式,你可能还想添加其他库,但这归结为我需要的具体内容。

You could also use: 你也可以使用:

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

and eliminate the first block of code in the installation script if you have git installed, or if you have neither git nor curl you could just download each and upload to your server or use fget or something similar. 如果您安装了git,则消除安装脚本中的第一个代码块,或者如果您既没有git也没有curl,您可以只下载每个代码并上传到您的服务器或使用fget或类似的东西。

In all, this amounted to several hours of hunting down files, tracing compilation errors, tracking down the correct options for my scenario, and other aspects of this kind of tedium that makes up the worst of exactly what I like least about development work. 总而言之,这相当于几个小时的搜索文件,追踪编译错误,追踪我的场景的正确选项,以及这种单调乏味的其他方面构成了我最不喜欢开发工作的最坏情况。 I hope that this post might save others from this kind of unnecessary pain and suffering :-) 我希望这篇文章可以拯救其他人免受这种不必要的痛苦和痛苦:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM