使用 PHP 进行实时视频流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/223983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:58:50  来源:igfitidea点击:

Live Video Streaming with PHP

phpvideostreaming

提问by

I have a PHP/AJAX/MYSQL chat application. I want to add video chatting to my application. How can I create live video streaming to be used for live video conferences/chatting in a PHP application. What are the key-terms I need to know if I wanted to build such a system? Is it a good idea in the first place to use PHP? Is there something I'm not thinking about? What other languages can I use, perhaps in conjunction with PHP?

我有一个 PHP/AJAX/MYSQL 聊天应用程序。我想在我的应用程序中添加视频聊天。如何在 PHP 应用程序中创建用于实时视频会议/聊天的实时视频流。如果我想构建这样一个系统,我需要知道哪些关键术语?首先使用PHP是个好主意吗?有什么我不考虑的吗?我可以使用哪些其他语言,也许与 PHP 结合使用?

回答by Till

I am not saying that you have to abandon PHP, but you need different technologies here.

我并不是说你必须放弃 PHP,而是你需要不同的技术。

Let's start off simple (without Akamai :-)) and think about the implications here. Video, chat, etc. - it's all client-side in the beginning. The user has a webcam, you want to grab the signal somehow and send it to the server. There is no PHP so far.

让我们从简单开始(没有 Akamai :-))并考虑这里的含义。视频、聊天等 - 一开始都是客户端。用户有一个网络摄像头,您想以某种方式获取信号并将其发送到服务器。到目前为止还没有 PHP。

I know that Flash supports this though (check this tutorial on webcams and flash) so you could use Flash to transport the content to the server. I think if you'll stay with Flash, then Flex(flex and webcam tutorial) is probably a good idea to look into.

我知道 Flash 支持此功能(请查看有关网络摄像头和 Flash 的教程),因此您可以使用 Flash 将内容传输到服务器。我认为如果你会继续使用 Flash,那么Flexflex 和网络摄像头教程)可能是一个值得研究的好主意。

So those are just the basics, maybe it gives you an idea of where you need to research because obviously this won't give you a full video chat inside your app yet. For starters, you will need some sort of way to record the streams and re-publishthem so others see other people from the chat, etc..

所以这些只是基础知识,也许它可以让您了解需要研究的地方,因为显然这不会在您的应用程序中提供完整的视频聊天。首先,您需要某种方式来记录流并重新发布它们,以便其他人从聊天中看到其他人等。

I'm also not sure how much traffic and bandwidth this is gonna consume though and generally, you will need way more than a Stackoverflow question to solve this issue. Best would be to do a full spec of your app and then hire some people to help you build it.

我也不确定这会消耗多少流量和带宽,通常,您需要的不仅仅是 Stackoverflow 问题来解决这个问题。最好的办法是对你的应用程序做一个完整的规范,然后雇佣一些人来帮助你构建它。

HTH!

哼!

回答by Shani

Please note that the below described service is no longer available as it was based on FLV media (Flash)

请注意,以下描述的服务不再可用,因为它基于 FLV 媒体 (Flash)

This project which utilizes the Red5, Flex and PHP for Live Video Streaming and Recording has many features

这个利用 Red5、Flex 和 PHP 进行实时视频流和录制的项目具有许多功能

  1. Stream Live video to the viewers

  2. Record the streams from your cam or other video input devices to the server

  3. Preview the recorded streams and files and thumbnail the frame which you would like to display for the video.

  4. Upload the videos from your computer and convert them to FLV which can be streamed using Red5 .

  5. Choose from any resolutions

  6. Can be plugged to any script

  7. Each website user can have a separate Directory for storing their videos and thumbnails use this link http://code.google.com/p/red5-flex-streamer/

  1. 将实时视频流式传输给观众

  2. 将来自您的摄像头或其他视频输入设备的流录制到服务器

  3. 预览录制的流和文件,并缩略图您要为视频显示的帧。

  4. 从您的计算机上传视频并将其转换为可以使用 Red5 流式传输的 FLV。

  5. 从任何分辨率中选择

  6. 可以插入任何脚本

  7. 每个网站用户都可以有一个单独的目录来存储他们的视频和缩略图,使用此链接 http://code.google.com/p/red5-flex-streamer/

回答by deepcode.co.uk

PHP will let you build the pages of your site that make up your video conferencing and chat applications, but it won't deliver or stream video for you - PHP runs on the server only and renders out HTML to a client browser.

PHP 将允许您构建构成视频会议和聊天应用程序的站点页面,但它不会为您传送或流式传输视频 - PHP 仅在服务器上运行并将 HTML 呈现给客户端浏览器。

For the video, the first thing you'll need is a live streaming account with someone like akamai or the numerous others in the field. Using this account gives you an ingress point for your video - ie: the server that you will stream your live video up to.

对于视频,您需要的第一件事是与 akamai 或该领域的众多其他人有一个实时流媒体帐户。使用此帐户可以为您的视频提供一个入口点 - 即:您将直播视频传输到的服务器。

Next, you want to get your video out to the browsers - windows media player, flash or silverlight will let you achieve this - embedding the appropriate control for your chosen technology into your page (using PHP or whatever) and given the address of your live video feed.

接下来,您希望将视频发送到浏览器 - windows 媒体播放器、flash 或 silverlight 可以让您实现这一点 - 将您选择的技术的适当控件嵌入到您的页面中(使用 PHP 或其他)并给出您的直播地址视频馈送。

PHP (or other scripting language) would be used to build the chat part of the application and bring the whole thing together (the chat and the embedded video player).

PHP(或其他脚本语言)将用于构建应用程序的聊天部分并将整个内容(聊天和嵌入式视频播放器)整合在一起。

Hope this helps.

希望这可以帮助。

回答by deepcode.co.uk

For live video conferencing you can't ignore the need of a streaming server.

对于实时视频会议,您不能忽视流媒体服务器的需求。

Yes, flash will let you display video from a webcam within the local flash control, but that won't let you then send that video over the network - for that you need a streaming server to send it to.

是的,Flash 可以让您在本地 Flash 控件中显示来自网络摄像头的视频,但这不会让您通过网络发送该视频 - 为此您需要一个流媒体服务器来发送它。

If you're going to build something like this it's prudent to think about how you're going to host the video from a very early stage as it will influence how you build the application. Flash/Flex/Silverlight/Windows Media....etc....

如果您要构建这样的东西,从很早的阶段就考虑如何托管视频是明智的,因为这会影响您构建应用程序的方式。Flash/Flex/Silverlight/Windows Media....等...

回答by Conan

There are a lot of "off-the-shelf" 'servers' that will run in your environment. Most of these utilize the aforementioned Flex or Silverlight to implement the actual video itself but I'm pretty sure all will run under LAMP/PHP.

有很多“现成的”“服务器”将在您的环境中运行。其中大部分使用前面提到的 Flex 或 Silverlight 来实现实际的视频本身,但我很确定所有这些都将在 LAMP/PHP 下运行。

The challenges will picking the best software from everything that's available and getting your hosting-provider to let you stream video (it goes without saying that streaming is heavy on bandwidth).

挑战将是从所有可用的软件中挑选最好的软件,并让您的托管服务提供商让您流式传输视频(不用说,流式传输占用了大量带宽)。

回答by Gaurav

PHP/AJAX/MySQL will not be enough for creating the live video streaming application There is a similar thread here. It primarily suggests using Flex or Silverlight.

PHP / AJAX / MySQL将是不够的创建实况视频流应用程序有一个类似的线程在这里。它主要建议使用 Flex 或 Silverlight。

回答by manish kumar

You can easily build a website as per the requirements. PHP will be there to handle the website development part. All the hosting and normal website development will work just as it is. However, for the streaming part, you will have to choose a good streaming service. Whether it is Red5 or Adobe, you can choose from plenty of services.

您可以根据要求轻松构建网站。PHP 将在那里处理网站开发部分。所有托管和正常的网站开发都将按原样进行。但是,对于流媒体部分,您必须选择一个好的流媒体服务。无论是 Red5 还是 Adob​​e,您都可以从众多服务中进行选择。

Choose a service that provides a dedicated storage to get something done right. If you do not know how to configure the server properly, you can just choose a streaming service. Good services often give a CDN that helps broadcast the stream efficiently. Simply launch your website in PHP and embed the YouTube player in the said web page to get it working.

选择提供专用存储的服务以正确完成某些事情。如果您不知道如何正确配置服务器,您可以选择流媒体服务。好的服务通常会提供一个 CDN,帮助有效地广播流。只需在 PHP 中启动您的网站并将 YouTube 播放器嵌入到所述网页中即可使其正常工作。

回答by jimcavoli

Same problem/answer here, quoted below

同样的问题/答案在这里,引用如下

I'm assuming you mean that you want to run your own private video calls, not simply link to Skype calls or similar. You really have 2 options here: host it yourself, or use a hosted solution and integrate it into your product.


Self-Hosted ----------------- This is messy. This can all be accomplished with PHP, but that is probably not the most advisable solution, as it is not the best tool for the job on all sides. Flash is much more efficient at a/v capture and transport on the user end. You can try to do this without flash, but you will have headaches. HTML5 may make your life easier, but if you're shooting for maximum compatibility, flash is the simplest way to go for creating the client. Then, as far as the actual server side that will relay the audio/video, you could write a chat server in php, but you're better off using an open source project, like janenz00's mention of red5, that's already built and interfacing with it through your client (if it doesn't already have one). Or you could homebrew a flash client as mentioned before and hook it up to a flash streaming server on both sides...either way it gets complicated fast, and is beyond my expertise to help you with at all.


Hosted Service ----------------- All in, my recommendation, unless you want to administer a ridiculous setup of many complex servers and failure points is to use a hosted service like UserPlaneor similar and offload all the processing and technical work to people who are good at that, and then worry about interfacing with their api and getting their client well integrated into your site. You will be a happier developer if you do.

我假设您的意思是您想要运行自己的私人视频通话,而不是简单地链接到 Skype 通话或类似通话。您在这里确实有 2 个选择:自己托管,或者使用托管解决方案并将其集成到您的产品中。


自托管 ----------------- 这很混乱。这一切都可以用 PHP 来完成,但这可能不是最可取的解决方案,因为它不是所有方面的工作的最佳工具。Flash 在用户端的 a/v 捕获和传输方面效率更高。您可以尝试在没有闪光灯的情况下执行此操作,但是您会头疼。HTML5 可能会让您的生活更轻松,但如果您要获得最大的兼容性,Flash 是创建客户端的最简单方法。然后,至于将中继音频/视频的实际服务器端,您可以在 php 中编写一个聊天服务器,但最好使用开源项目,例如 janenz00提到的red5,它已经通过您的客户端构建并与之连接(如果它还没有)。或者你可以自制一个之前提到的 flash 客户端,并将它连接到双方的 flash 流媒体服务器......无论哪种方式都会变得复杂,而且我的专业知识无法帮助你。


托管服务 ----------------- 总而言之,我的建议,除非您想管理许多复杂服务器的荒谬设置并且故障点是使用像UserPlane或类似的托管服务 并将所有处理和技术工作卸载给擅长这方面的人,然后担心与他们的 api 接口以及让他们的客户端很好地集成到您的站点中。如果你这样做,你会成为一个更快乐的开发者。