简体   繁体   English

在Linux服务器上将PHP音频和视频上传链接到FFMPEG

[英]Linking PHP audio and video uploads to FFMPEG on a linux server

I host a site on a Linux server that I built with php where I am able to upload audio files in one section and video files to another. 我在用php构建的Linux服务器上托管一个站点,可以在其中将音频文件上传到另一部分,将视频文件上传到另一部分。

Each section uses php to upload a single audio file and a single video file. 每个部分都使用php上传单个音频文件和单个视频文件。 Each upload is assigned a unique filename so they can be viewed separately on an individual page where the uploader can post comments about their audio or video. 每次上传均分配有唯一的文件名,因此可以在单独的页面上单独查看它们,上传者可以在其中发布有关其音频或视频的评论。

I want to be able to allow musicians and performers in the local area display their work. 我希望能够允许本地的音乐家和表演者展示他们的作品。 The site works, but large video files do not upload and my audio player only plays a few formats, and I like to convert them all to mp3's. 该网站可以正常工作,但无法上传大型视频文件,并且我的音频播放器仅播放几种格式,我希望将它们全部转换为mp3。

I installed ffmpeg on my linux server to help me with this and am able to connect to it with my terminal. 我在Linux服务器上安装了ffmpeg来帮助解决这个问题,并且能够通过终端连接到它。 My question is how do I get ffmpeg to interface with my uploaded php files. 我的问题是如何使ffmpeg与我上传的php文件交互。

For example, as the user uploads an audio file, can I have ffmpeg convert it while it's uploading, or do I need to set up a temporary folder for uploads, store it there, then have ffmpeg compress the file, convert it to a specific format and save it in another folder? 例如,当用户上传音频文件时,我可以在上传时将ffmpeg转换为音频文件,还是需要为上传设置临时文件夹,将其存储在其中,然后让ffmpeg压缩文件,将其转换为特定文件格式化并将其保存在另一个文件夹中?

I would prefer to have it compress and change the format while it's uploading so as not to use server space, but if this is not the way ffmpeg works, then I don't have a choice. 我希望它在上传时进行压缩和更改格式,以免占用服务器空间,但是如果ffmpeg不能正常工作,那么我别无选择。 Any help would be appreciated. 任何帮助,将不胜感激。

It is NOT possible to transcode while uploading. 上传时无法转码。 But, it is possible to transcode all your videos to mp4 files and all your audio files to mp3 files using ffmpeg command which you can call from your PHP code using exec statements. 但是,可以使用ffmpeg命令将所有视频转码为mp4文件,并将所有音频文件转码为mp3文件,您可以使用exec语句从PHP代码中调用ffmpeg命令。

H264 BP is the video codec which is almost universal and supports most of the platforms devices, browsers, players etc. AAC is the best audio codec to use for online streaming. H264 BP是几乎通用的视频编解码器,并支持大多数平台设备,浏览器,播放器等。AAC是用于在线流传输的最佳音频编解码器。

So, convert all your videos with following exec statementin PHP. 因此,请在PHP中使用以下exec语句转换所有视频。

exec("ffmpeg -i INPUT.avi -r 25 -b:v 1M -pass 1 -c:v libx264 -profile:v baseline -c:a aac -strict experimental -b:a 192k OUTPUT.mp4");

And convert all your audios with following exec statement in PHP. 并使用PHP中的以下exec语句转换所有音频。

exec("ffmpeg -i INPUT.wav -c:a aac -strict experimental -b:a 192k OUTPUT.mp3");

I once had the opportunity to work on such task around 4 years back. 大约4年前,我曾经有机会从事这项工作。 I still remember how I did this. 我仍然记得我是怎么做到的。 I installed ffmpeg and it should work using commands as well on shell. 我安装了ffmpeg,它也可以在shell上使用命令来工作。 I used exec library of php to execute ffmpeg commands which converted video files into desired format ie mp4. 我使用php的exec库执行ffmpeg命令,该命令将视频文件转换为所需的格式,即mp4。 You better check out exec and learn ffmpeg command to convert file into desired format. 您最好签出exec并学习ffmpeg命令将文件转换为所需格式。 Hope it helps 希望能帮助到你

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

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