You will recieve your password to this address. Address is not made public.

Your preferred username that is used when logging in.

How To: Pseudostreaming with IIS and ASP.NET Created Feb 4, 2009

This thread is solved

Views: 8676     Replies: 12     Last reply 13 days ago  
You must login first before you can use this feature

noc@connect2ccc.org

Posts: 58

Registered:
May 26, 2008

How To: Pseudostreaming with IIS and ASP.NET

Posted: Feb 4, 2009

For almost a year, Ive been using flowplayer's pseudostreaming capabilities with IIS6 and ASP.NET 2.0. I thought I'd share this because it does not require PHP so you can use this on a very basic IIS setup.
  • Open up IIS Manager. In the site properties, click the "Home directory" tab then click the "Configuration" button.
  • Add an entry for .flv. The Executable path is whatever the aspnet_isapi.dll path is for your version of .NET Framework. Check some of the other file types like .config to be sure. Set Verbs to "Limit to:" with the value GET,HEAD,POST,DEBUG. Click OK get back to the site properties.
  • If you have not done so already, you'll need to make sure you have a mime type for flv files, so go to the HTTP Headers tab and click the MIME Types... button. If .flv does not appear, click new. Extention is .flv and MIME type is flv-application/octet-stream. You may have something else here and I'm not sure if it matters if you have this exact value but this works for me. Click OK and get back to the site properties.
  • One thing to consider is the size of the flv files and how long they will take for your visitors to download. In my case, I have some flv files that are 150MB, so it can take some slow DSL users maybe 30 min or more to download as they watch. Because of this, the script would time out before the download is done, cutting the video off. By default the script will stop in 110 seconds, so if that is not enough time for some slower connections, go to the ASP.NET tab and click Edit Configuration. Now go to the application tab and change the Request execution timeout to a higher value. I chose 1800 seconds. We are done with the site properties for now.
  • In order to make sure any request for a .flv file is handled by ASP.NET, edit the web.config file (should be in the root of your website) and add the following lines just before </system.web> near the end of the file:
  • 
        <httpHandlers>        
               verb="*" path="*.flv" type="FLVStreaming" />
        </httpHandlers> 
    
  • In the root of the website, create an App_Code folder if you dont already have one. Place a file called FLVStreaming.cs there with the following inside: ( This is for ASP 2 ONLY, not ASP 1.1 )
  • 
    using System;
    using System.IO;
    using System.Web;
    
    public class FLVStreaming : IHttpHandler
    {
        private static readonly byte[] _flvheader = HexToByte("464C5601010000000900000009");
    
        public FLVStreaming()
        {
        }
    
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                int pos;
                int length;
    
                // Check start parameter if present
                string filename = Path.GetFileName(context.Request.FilePath);
    
                using (FileStream fs = new FileStream(context.Server.MapPath(filename), FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    string qs = context.Request.Params["start"];
    
                    if (string.IsNullOrEmpty(qs))
                    {
                        pos = 0;
                        length = Convert.ToInt32(fs.Length);
                    }
                    else
                    {
                        pos = Convert.ToInt32(qs);
                        length = Convert.ToInt32(fs.Length - pos) + _flvheader.Length;
                    }
    
                    // Add HTTP header stuff: cache, content type and length        
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetLastModified(DateTime.Now);
    
                    context.Response.AppendHeader("Content-Type", "video/x-flv");
                    context.Response.AppendHeader("Content-Length", length.ToString());
    
                    // Append FLV header when sending partial file
                    if (pos > 0)
                    {
                        context.Response.OutputStream.Write(_flvheader, 0, _flvheader.Length);
                        fs.Position = pos;
                    }
    
                    // Read buffer and write stream to the response stream
                    const int buffersize = 16384;
                    byte[] buffer = new byte[buffersize];
                    
                    int count = fs.Read(buffer, 0, buffersize);
                    while (count > 0)
                    {
                        if (context.Response.IsClientConnected)
                        {
                            context.Response.OutputStream.Write(buffer, 0, count);
    						
    						//Starts sending to client right away
    						context.Response.Flush();
    			
                            count = fs.Read(buffer, 0, buffersize);
                        }
                        else
                        {
                            count = -1;
                        }a
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
    
        public bool IsReusable
        {
            get { return true; }
        }
    
        private static byte[] HexToByte(string hexString)
        {
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
            return returnBytes;
        }
    
    }
    
  • Now go back to IIS Manager and find that App_Code folder under your site. Bring up the properties of the App_Code folder, and on the Directory tab, Click the Create button to create an application. The application name field should then show App_Code. I'm also not 100% sure you need this step in every case, but I did.
  • Now the server is ready to go. For flowplayer, use the pseudostreaming plugin as demonstrated on the plugin page:http://www.flowplayer.org/plugins/streaming/pseudostreaming.html
As for flash video, I've been using the Adobe flash video encoder to create the flv files since I created the videos for my site in Adobe Premiere. After creating the flv, I used flvmdi for metadata injections. http://www.buraks.com/flvmdi/

This is mostly off the top of my head and I set this up a year ago so I'm sorry if I missed something.

Anssi
Flowplayer Flash & video streaming developer

Posts: 818

Registered:
Jul 24, 2007

» How To: Pseudostreaming with IIS and ASP.NET

Posted: Feb 4, 2009

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
Thanks for sharing this!

Lappen

Posts: 1

Registered:
Mar 31, 2009

» How To: Pseudostreaming with IIS and ASP.NET

Posted: Mar 31, 2009

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
Hi, I have done all the above, but I get error 200 stream not found.
This is when I try to play a .flv from my own server, configured as above. I have tried with the relative filename and the http:// sitename.
When I try to access the flv-file directly from IE i get "HTTP 403.1 Forbidden: Execute Access Forbidden"

When I use the url:'http://examples-s3.simplecdn.net/videos/Extremists.flv' as in the demo it works fine.

When I put the flv-file on another server (at work) it streams, but not pseudostreaming (not configured).

It feels like an IIS problem, but do anyone know how to correct the problem?

nrossello

Posts: 1

Registered:
Sep 8, 2009

How To: Pseudostreaming with IIS and ASP.NET

Posted: Sep 9, 2009

Reply to: » How To: Pseudostreaming with IIS and ASP.NET, from Lappen
I am having the same problem.... 200 Stream not found...
btw
<httpHandlers>
<add verb="*" path="*.flv" type="FLVStreaming" />
</httpHandlers>

i can't get it to work fine

oncallken
Ken Ballard Oncall Interactive http://www.oncallinteractive.com

Posts: 1

Registered:
Apr 1, 2009

Purpose of _flvheader?

Posted: Apr 1, 2009

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
Hey all...I'm trying to refactor this process and code to pseudostream mp3's. The thing that I'm getting hung up on is I'm not sure what the _flvheader is doing. I see that it's getting appended onto the beginning of the stream, but I'm afraid this is way outside of my knowledge. Can anyone enlighten me on this? I'm assuming this value will have to be changed for mp3's, but I'm not sure where to begin on that.


private static readonly byte[] _flvheader = HexToByte("464C5601010000000900000009");

Thanks in advance for your help!

chanduu4u

Posts: 3

Registered:
Apr 3, 2009

how to use the control

Posted: Apr 3, 2009

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
Hello, every this fine, thanks for sharing.
Can you please provide the code for aspx and aspx.cs?

thanks in advance

Chanduu4u

noc@connect2ccc.org

Posts: 58

Registered:
May 26, 2008

» how to use the control

Posted: Apr 15, 2009

Reply to: how to use the control, from chanduu4u
everything you need is provided. This will work with any pseudostreaming enabled flowplayer setup and flv videos.

chanduu4u

Posts: 3

Registered:
Apr 3, 2009

code for asp.net 2.0

Posted: Apr 24, 2009

Reply to: » how to use the control, from noc@connect2ccc.org
oops! where is the code?

tuanb

Posts: 1

Registered:
Apr 17, 2009

» How To: Pseudostreaming with IIS and ASP.NET

Posted: Apr 17, 2009

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
Hi,
I got an error in FLVStreaming.cs file at
line 71 }a

What is the correct syntax for this line?
Thanks,

arjen

Posts: 20

Registered:
Feb 4, 2009

» » How To: Pseudostreaming with IIS and ASP.NET

Posted: Apr 17, 2009

Reply to: » How To: Pseudostreaming with IIS and ASP.NET, from tuanb
Hi Tuanb,

Just remove the 'a' from that line and leave the '}'.

Regards,

crimsondeath

Posts: 1

Registered:
May 11, 2009

One more thing

Posted: May 11, 2009

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
First of all, thanks for posting this. It works great.
However, I did have to add one extra line of code.
At the end of the while(){} statement that writes the bytes I had to add a:
context.Response.Close();

Or else after a few times of refreshing the page IIS would no longer respond, or take a very long time to do so.
So if anyone has this same problem I believe this might help.

Thanks,

nhardel

Posts: 1

Registered:
Jul 10, 2009

Setup of web.config file

Posted: Jul 10, 2009

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
This doesnt look right


<httpHandlers>
    verb="*" path="*.flv" type="FLVStreaming" />
</httpHandlers>

Shouldn't it look more like this?


<httpHandlers>
  <add verb="*" path="*.flv" type="FLVStreaming" />
</httpHandlers>

and my web.config file has multiple </system.web>
so which one should I be looking for?

omar

Posts: 8

Registered:
Jan 26, 2009

mp4?

Posted: 13 days ago

Reply to: How To: Pseudostreaming with IIS and ASP.NET, from noc@connect2ccc.org
Can this be setup for mp4?