Wednesday, May 09, 2012

Streaming with Adobe Flash Media Server

I am spoiled. For programming, my editor of choice is Notepad; I can see what I'm doing and don't want an automated editor telling me what to do. On the other hand - or OTOH in Net jargon - I expect a program to have an interface that is intelligent. Particularly server software. I am too used to Microsoft software that - to paraphrase - just works. You insert a CD, hit Enter a few times and you're up and running. To change any setting, you start up the administration console and it tells you what to do and shows a little iconic message when you do it incorrectly.

Which is why I am vexed by software that just sits there without offering any clue as to what to do next.

Leaving aside grumblings on others, let's move on to my experience with Adobe's Flash Media Server. The version I am using is 4.

Pop in the CD, hit enter a few times and it installs. So far, so good.

What comes next? A look at the demo pages show that it streams audio and video files. Better and better.

The next logical step is to try streaming our own files. This is where everything breaks down and you'd soon be tearing your hair out or maybe putting your fist through the screen.

There is no documentation on how to do this. None. Nada.

Flash Media Server - FMS - does have, what it calls, an administration console. The problem is that it doesn't actually administer anything. It only monitors your server's workings, how many streams are open, number of users, that sort of stuff.

The help opens up Adobe's website and leaves you there.

Ok, so let's JFGI. Easier said than done. A few pages lead to forums, sites, bug reports and shops where you can buy airline tickets. I finally came to Beginner's Guide to streaming video with FMS, a page on Adobe's Devnet. "Bingo", I said to myself. Yes, I do talk to myself now and then. Reading the article word for word, searching for that flash of inspiration, was a complete waste of 10 minutes; the article deals with how to write a Flash client which reads and displays a stream on the client. Why an article of said title deals with the client end only is beyond me. I am sure that Mr. Green's works are helpful to a lot of people, but would have preferred it had he talked a bit about the server side of things.

Enough with the rambling. Let's move on to how you stream your own files.

You have to know a couple of things before you understand this. Firstly, FMS also installs the Apache web server, regardless of whether you have it installed on a Windows machine with IIS or not. FMS streams using RTMP protocol that runs on port 1935. If you have a firewall, open that port. RTMP protocol has an auto-fallback to RTMPT protocol that runs on port 80 in case it can't make a connection. Apache opens another port, 5080, for its admin console.

Secondly, configuration is done not via the admin console but by modifying the file system directly using Windows Explorer and, my favorite, Notepad.

In a standard setup, assuming you took all defaults while installing, the file system would look like this:

  • IIS: C:\Intepub\wwwroot
  • FMS: C:\Program Files\Adobe\Flash Media Server 4

Let's assume your media files - MP3 and MP4 - are in C:\MyFiles.

There is no need to change anything within IIS setup nor its folders.

All changes are to be done in FMS folders.

Each location or type that is streamed is called a Streaming Point. Within FMS, it is called an 'application'. Inside the FMS folder is another folder call 'applications'. This contains multiple folders, one each for each streaming point.

In the 'applications' folder, create a new one called 'mystream'. Next, copy all the files - but not the folder - from the 'vod' folder.

In your 'mystream' folder, edit the file named 'Application.xml'. At the top are two lines:

<streams>/;${VOD_COMMON_DIR}</streams> <streams>/;${VOD_DIR}</streams>

Delete one of the lines and change the other to:

<streams>/;${MYSTREAM_DIR}</streams>

Now, you have created a new application. You just need to define the variable. These are defined in fms.ini which is in the conf folder of FMS. Insert this line after the line that defines VOD-COMMON_DIR:

MYSTREAM_DIR = C:\MyFiles

FMS is now all set. We just need to configure Apache to serve files from here. The Apache configuration file is called httpd.conf which is in the Apache2.2\conf folder within FMS. Edit this file to add these lines:

<location = "mystream"> HttpStreamingEnabled true HttpStreamingContentPath "/MyFiles" Options -Indexes FollowSymLinks </location>

All configuration is now done. Use the Windows Services control panel widget to restart FMS and Apache services.

The easiest way to test that streaming is working is to use JW Player's demo file. Edit it to point to your server:

<script type="text/javascript"> jwplayer("mediaplayer").setup({ flashplayer: "player.swf", file: "file1.mp4", streamer: "rtmp://myserver.mydomain.com/mystream/", image: "preview.jpg" }); </script>

The type of files that you can put in there are FLV, MP4 and MP3. They must use the codec supported by JW Player otherwise you won't get the correct result in the player.

And, that, is how you stream with FMS!


P.S: I noticed that this editor has scrambled some of the code that I pasted.

No comments: