How to make basic live stream with HTML5 video API and PHP?

Asked

Viewed 17,330 times

7

I would like to know the basics about how to create (make) a live stream system...I have a blog script in php where I created a system of users and even a system of friendships but I would like to add the possibility for each user to create a "species" own channel to make live stream content (games, Views, tutos, etc...) transmitting to friends on their lists or publicly. I’ve looked at numerous scripts throughout the internet but they have much more than I need I do not search for anything with filters or systems of my own, I would like to create to implement in my script already ready.

Any help is welcome. From simple examples to grateful study tips to all good year-end :)

  • You are using RTMP protocol?

  • I am not using anything. I am looking for study material (indications, etc...).

  • https://github.com/qwantix/php-rtmp-client

  • 3

    Search by "webrtc", is a javascript-accessible API of browsers designed for exactly what kind of problem you have, real-time video/audio/data transmission between browsers. Behold this demo which shows channel creation with live stream webcams, the same can be done for screen sharing (although support is still restricted).

  • @Brunorb yes, I have been using Webrtc for some time in tests and has shown to be the best option within my needs

2 answers

8

Live stream (live stream)

  • As stated in SO-en, the PHP is not indicated for the use of "live stream" (live stream).

    I will not say that it is impossible to do PHP, but maybe it is a hard way, because it will be necessary that something captures the Webcam of the person who transmits the video, save in a document the data and the people who watch are waiting for new bytes be added to the server, this can be very costly for develop and to the server.

    See an example is Youtube, they do live streams and display videos that are on the server while the site youtube.com is on a server optimized for web pages, the videos are on another totally isolated server, which is optimized for video streaming and it is likely that their "live-stream" is on another server yet (ie 3 servers with different technologies). So data transmission is not done by a language like "PHP", but probably by a specific technology for transmissions.

    You may be able to use PHP for this, but probably your server won’t last a day.

  • And as this response in SO-en to record video with HTML5, you will need to use Webrtc. This enables audio and video streaming.

Alternative RTMP (Flash Required)

I haven’t tested it yet, but this is the way:

Just like Youtube, you can separate into two servers one you can use Apache for web page and the "PHP client" (using port 80) and in Ngnix you will only use for RTMP (I think that the standard is door 1935)

Non-live stream alternative

But there is the following script to write with PHP (if not real-time) that you can use PHP Webcam Video Recorder

  • 1

    It is thanks the answer seems to be very detailed but this is "video-stream" of a file already hosted on the server (I even tested this method) but I search "live-stream"

  • 2

    @Lauromoraes I know that it is not video-stream what you need, I wrote in parentheses (if not in real time), is as written in the reply, for Html5 to record is required "Webrtc" and PHP is not the technology recommended to manage the transmission. So there’s no way to provide you with a solution or tutorial for something that apparently doesn’t there is no :) I hope you don’t mind my remark

2

YES, it is possible to carry out this proposal with PHP.

In fact Youtube (both Yout and other similar platforms) runs thanks to Ffmpeg. And this is not to say that it is a server different from the others that you use to program (except for the scalability and speed, memory etc)

So if you are using Linux, study this powerful application (command lines and ways of use) very important, so much so that php has a native bilioteca that works with Ffmpeg.

In the case of PHP thinks so, let’s talk about your project (or idea): PHP will run on the server, so you will use to convert the files, organize, (read the stream etc) and make available to the user.

But to record, you can’t record with PHP or Javascript, because they’re not connected with the computer’s devices (like the camera for example). So for the user to send a video you need another question.

That’s why everyone indicated the use of Flash, which until then was the only device that connected to the camera and Microphone (don’t forget that). But now you have Html5 that can also connect to these devices. So you can already send a video of your users - with Flash or with Html5.

It will take work, but it is worth the research in this area.

I’ve done something similar, but only one user sent video to a PHP server and several user connecting live and watching. With an Adobe application called Adobe Media Live Encoder. It had a version that was free, nowadays it is paid. :/

In your case it’s bolder programming, but it’s worth it.

Links: https://ffmpeg.org/

-- I can’t post more links because it’s my first participation in Stack ;)

  • Good in this mold would not be "live-stream" but only "stream".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.