Welcome Guest, Not a member yet? Register   Sign In
Practical PHP media streaming theory
#1

[eluser]Unknown[/eluser]
I’ve been scripting in PHP for about 8 years now. The reason I initially started writing PHP was because I wanted to make a net radio broadcast site. Back then the only real way to do it was to use shoutcast server but it was far from what I wanted. Thus began my quest to either find or build a practical media streaming PHP solution.

Today there are a number of really neat projects that come close to what I’m looking for in media streaming. All of them are commercial and require payment or the rest are OSS but don’t offer alot. I think the “practical” technology already (or is very close) in existance to create a PHP based media streaming library.

First, let’s define what the goal is:
Build a OPEN SOURCE php library that a php developer can use to build a media streaming site. The PHP will act as a middleman between the source media and the streaming server as well as between the client(listener/viewer) and the streaming server.
Basic layout:
source -> PHP source controller -> binary to transcode and stream source
client -> PHP client controller -> binary that streams the sources

The whole point is to get PHP in between the binary that does all the transcoding and streaming and the source/clients. When this is accomplished in a reliable and practical way you can build whatever you want in php to control things. You could build a request system or a DJ manager or control who can listen in.

Of course a number of the binaries out that do media streaming have some of these things already built in. Icecast (the last time I checked it) has a pretty decent listener auth built into it but it’s not that practical for someone to have icecast on their server. So then what binary exists that can do all the transcoding and streaming and that’s practical to have on a server? I think ffmpeg in conjunction with ffserver is the solution (if not now then in the near future).

I’m sure a number of you are now immediatley saying “This is crazy.”, “FFMPEG is a pain to install on a server.” or the statement question combo that always seems to surface “I use a windows server. What’s ffmpeg?”. In response, if you search on the web for streaming solutions of media on a server, ffmpeg always seems to come up as either THE solution or a possible solution for a server with a LAMP stack. The problem right now with ffmpeg is it’s hard to install on a server or the server host doesn’t allow/have it installed.

The growing demand for media streaming on a web server will, I think, eventually make ffmpeg either easy to install or readily available by host providers. Already you can get hosting with ffmpeg installed if you google it.

So now we got our practical binary that takes care of all our transcoding and streaming needs but how do we get php in the middle? Well, there are a number of concerns (in the thousands maybe) that I still need to find out but my initial guess as a way too accomplish this would be the following.
Have ffserver only stream locally on the server and accept no external requests from clients and then have clients request a php file that executes a CURL to get the local stream and then feed that CURL request to the client. For external sources it’d be a similar thing.

So, in theory, a php based media streaming server I think can be accomplished using the technique I’ve very generally outlined above. There still remains a number of questions though,
Can ffserver load a config dynamically (no restart but more like a reload without killing connections)?
Can php CURL handle a real time stream and pass it on to the request reliably? (i kind of have large doubts here)
Threading with php might be needed. In which case, how? I think the general solution to that is create another php process that then interprets the script separately (woefully inefficient). This is probably not needed though since the request is going through apache.
Can php or ffmpeg/ffserver handle a switch from one source to another seamlessly?
Can ffmpeg/ffserver handle a shoutcast or icecast input source and if not can php take that source and feed it into ffmpeg somehow?
... just to name a few.

Anyway, as I said I come back to this every now and again. Just wanted your opinions and spark some debate on this subject that I know alot of you have or will have to wonder about at some point.




Theme © iAndrew 2016 - Forum software by © MyBB