Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

Bandwidth Detection

92 replies [Last post]

Jeroen, saying "everyone has broadband" ...Jeroen, saying "everyone has broadband" is propably fine, but that should not lead to the conclusion that bandwidth detection is not needed.

For example, 400kbit VP6 movies are not fullscreen TV quality. You need maybe 700kbit or so for that to start becoming acceptable.

So what about all the people who are on 512kbit broadband? Should we serve them the 700kbit and expect the disappointed user to read the FAQ and realize that they need to select a lower bitrate movie? Or should we present every new user with a nagscreen about how they need to select their bandwidth? That seems sooo 90-ties.... ;-)

Cheers and thanks for a great product anyways!
/G

i for one, appreciate when im given the choice of speed. i have 0.5G line but, always prefer to watch the news at the low speed, so that i can surf on, while the news run in a window or background...
then if i want to watch pretty pictures i select a higher speed.
i would simply stop watching a channel that forced me to settle for any particular speed! so to keep me happy you would have to have both detection and a speed selector (and a cookie to remember my setting!)
i definitely dont see that as ninties -its web 2.0 ajax man! ;)

Well with a 0.5G line why do you even care #)(b)

@Gustaf - oops silly mistake, id really whish!, but unfortunately i should have pressed the M not the G :$ thats when happens when it is way over bedtime for little coders (b)

Bandwidth detection might be needed indeed, but I prefer presenting the users with a small menu instead of automatically doing this within the players.

hi Jeroen..

i don't mind having a small menu that runs in javascript, but i don't have clue how to do it.. what would be nice is if the flash player itself had a low, medium and high setting, so we don't have to add in the html and load a different file within a page.. i'd rather use javascript from within the player.. the question is how do they do it.. - andy

I have received an interesting email from Douglas Camargo on how to do bandwidth switching with SMIL. I'll add support for SMIL playlists, including the bandwidth switching, in the 3.9 players. And add some documentation of course...

By bandwidth switching do you mean mid-stream?

Hmm, actually the SMIL is not very useful for playlists, so I won't add support for that. As to the bandwidth switching, Douglas, can you share the script you wrote for it?

Nope, no mid-stream bandwiidth switching, but a pre-stream check of the bandwidth. For mid-stream switching, I recommend you place small links besides/below the player to switch the bandwidth with.

Hello,

Your player flv is really exceptional, but we need really a Bandwidth detection... because, much of our visitors are not happy because of the cut in the video. the reasons its simple... in Belgium it is always the "stone age" for Internet or then other people look at our site at the same time as programs uses Internet massively...

I found this player which have this function, [url=]http://www.rich-media-project.com/[/url] but it is well its only comparative advantage...

We are even ready to pay more expensive if this function is operational in video Flash player! :d

tank's for all and sorry for this english it's a google translation of french... *)

Jonathan, could you perhaps send me an email with the requirements and any code/ workflow you already have? Then I can have a look at it. Seems that a lot of people want some kind of bandwidth switching, so I am looking at how to best implement it.

My email address is in the resume on the 'about' page.

I've modified your player to get bandwidth detection up and running using serverside detection on Flash Media Server. I start the stream on the lowest bandwidth and have created an object which tells FLVModel.as once the serverside check has been completed. It then swaps to the appropriate stream. Let me know if you want more info.

@Jeroen,

Looks like they are going to drag you into bandwidth detection.

My opinion...
I tend to agree with you that bandwidth detection, playlist generation, statistics, etc., are better kept outside the player. Otherwise it becomes complicated to implement and complicated to maintain - more interactions and unintended consequences.

Like the tools that saw, drill, hammer, round the corners, and open up a cold beer -- but don't do any ONE thing very well.

I'd much rather have an API and, with andersen's demos to start from, implement custom solutions outside of the player.
/My opinion...

I had only been working in flash for a week, but I managed to read a few articles and hack bandwidth detection to modify how much to buffer in Jeroen's player.

I am about to redo that and add the ability to switch streams based on bandwidth detection as well.

It probably would not be much help because I do not know enough about flash to follow the code and find where the best place to implement it is, but if anyone is interested and Jeroen is okay with it I would not mind posting my modifications.

I happen to work for a company that sells software to an industry that is way behind on technology so we need something like that and it was the first direction I ran in.

@James King & @Naomi: if you could send me your code, that'll be really helpful! Peraps there is a way to insert bandwidth detection without messing up the code too much.

@Will: You're right, an API is more suited. Perhaps I can create a separate bandwidth-sniffer SWF that loads the player with the appropiate FLV file. That would do nice as an extra. Helping out people while not having to put it into the core player...

Jeroen,

I emailed you my bandwith detection class a few days ago. Just wondering if you got it?

Got it .. working on it today actually. I'll reply you a possible solution.

Any chance you could share the class with all? If you are already planning to release this thanks in advance.

Will release it today .. ;)

awesome...cant wait. I wish I would have seen this earlier I could have helped. :) maybe next time.

Jeroen this forum needs some kind of notification system. :) OR maybe upgrade to a full forum system like phpbb, invision or vB. I prefer phpbb because of the open source factor and how in depth it is plus phpbb3 is fan-freakin-tastic. Its in beta right now but it works very well and havent notice any bugs personally.

Note that every thread has it's own RSS feed, maybe that might serve as a means of notification?

Bandwidth detection is implemented in the 3.99 player. Have a look [url=http://www.jeroenwijering.com/extras/bandwidthcheck.html]at this page[/url] for a real-life test. The bandwidth checker uses two variables (one for the bitrates and one for the testfile to use), and can be deployed over HTTP and RTMP.

Bandwidth detection does not seem very accurate. At home, the player detects 1521 kbs (my connexion is 512k)and the video in the test page stops every 5 seconds and wait for loading :|

Jeroen You are amazing. This bandwidth detection is just what we needed and so simple to use too.

Brilliant

Now all we need is to know how much of the video was played when the viewer navigates away.... ;)

@David O,

If you enable the JavaScript API, the player continuously outputs the time. Send that back to the server for logging.

Parse the log, the highest time reached on a particular video by a particular user is how much of the video they watched.

A little bit of traffic, but then you have your stats.

Thanks for the tip Will! I am not sure what you mean though, I'll try and do some homework...

How does one send the javascript API back to the server for logging? any clues?

Also Does anyone know what happens if the bandwidth detection falls below the bandwidth of the lowest Kb file? i.e. I have one at 100 one at 300 and one at 700 but say some one is on dial up and they get detected at 50kb will nothing play? I can't check its as (like Jeroen said earlier) I don't know anyone who has dial up over here.

Can I get round the problem by suffixing the 100 file with 0 instead of 100? Or will the player default to the lowest in this case?

Thanks for all the good work and help

David

@David O,

You could probably test the bandwidth detection by making the choices 0,25,50 with three different files named video_0.flv, video_25.flv, and video_50.flv and see what happens. Best case would be to test on a real dial-up though.

On the amount of video played. It's pretty simple (he says after spending half a day on it) because Jeroen has output the needed data through the player's JavaScript API.

So, you need his JavaScript from the demo page.

You need to enable the JS API.

var s1 = new SWFObject('flvplayer-3.99.swf', 'mpl', '540', '580', '7');
s1.addVariable('enablejs', 'true');
s1.addVariable('javascriptid', 'mpl');
... the rest of the player code ...

You need a JS function to send the title & time to the server.

function sendDuration(title_time)
{
  xmlhttp.open('GET', 'http://my.domain.com/path-to-file/stats.php' + title_time, true);
  xmlhttp.send();
}

You need some JS to enable XHTML

// Get an XMLHttpRequest object in a portable way.
var xmlhttp

function newRequest()
{
  xmlhttp = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest)
  {
    try
    {
      xmlhttp = new XMLHttpRequest();
    }
    catch (e)
    {
      xmlhttp = false;
    }
  }
  else if (window.ActiveXObject)
  {
    // For Internet Explorer on Windows
    try
    {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        xmlhttp = false;
      }
    }
  }
}

You need to add the fourth line, in bold, to the three existing vars in Jeroen's JS code.

var currentPosition;
var currentVolume;
var currentItem;
<strong>var currentTitle;</strong>

You need to add the line in bold to Jeroen's JS code.

  if(typ == "time")
  {
    currentPosition = pr1;
// Add this next line to the existing JavaScript code...
<strong>sendDuration('?title=' + currentTitle + '&time=' + currentPosition);</strong>
  }

You need to initiate the XHTML in the <body> tag.

<body onload="javascript:newRequest();">

You need a little script like this on the server to log the data.

<?php

// log stats
// call with: http://my.domain.com/path-to-file/stats.php?title=Video Title&time=5

$title = (isset($_GET["title"])) ? strval($_GET["title"]) : "No Title";
$time  = (isset($_GET["time"]))  ? strval($_GET["time"])  : "0";

$filename = 'stats.log';

// check to see if $filename exists, if not, create it.
touch($filename) or die("Unable to create: " . $filename);

// log file format
$datetime = "[" . date('d/M/Y:h:i:s O') . "]";
$somecontent = $_SERVER[REMOTE_ADDR] . "  " . $datetime . "  " . $title . "  " . $time . "\n";

// open $filename for append.
$handle = fopen($filename, 'a') or die("Could not open file: " . $filename . "\n");

// Write $somecontent to the open file.
fwrite($handle, $somecontent) or die("Could not write to file: " . $filename . "\n");
 
fclose($handle);

?>

All of the above will result in a log file that looks like this.

192.168.0.1  [05/Jul/2007:05:00:18 -0700]  Futurama - Less Than Hero  1
192.168.0.1  [05/Jul/2007:05:00:19 -0700]  Futurama - Less Than Hero  2
192.168.0.1  [05/Jul/2007:05:00:19 -0700]  Futurama - Less Than Hero  3
192.168.0.1  [05/Jul/2007:05:02:58 -0700]  Futurama - Less Than Hero  4
192.168.0.1  [05/Jul/2007:05:02:58 -0700]  Futurama - Less Than Hero  4
192.168.0.1  [05/Jul/2007:05:02:59 -0700]  Futurama - Less Than Hero  5
192.168.0.1  [05/Jul/2007:05:03:00 -0700]  Futurama - Less Than Hero  6
192.168.0.1  [05/Jul/2007:05:03:01 -0700]  Futurama - Less Than Hero  7
192.168.0.1  [05/Jul/2007:05:03:01 -0700]  Futurama - Less Than Hero  7
192.168.0.1  [05/Jul/2007:05:03:02 -0700]  Futurama - Less Than Hero  8
192.168.0.1  [05/Jul/2007:05:03:03 -0700]  Futurama - Less Than Hero  9
192.168.0.1  [05/Jul/2007:05:03:04 -0700]  Futurama - Less Than Hero  10
192.168.0.1  [05/Jul/2007:05:03:05 -0700]  Futurama - Less Than Hero  11
192.168.0.1  [05/Jul/2007:05:03:06 -0700]  Futurama - Less Than Hero  12
192.168.0.1  [05/Jul/2007:05:03:07 -0700]  Futurama - Less Than Hero  13
192.168.0.1  [05/Jul/2007:05:03:08 -0700]  Futurama - Less Than Hero  14
192.168.0.1  [05/Jul/2007:05:03:09 -0700]  Futurama - Less Than Hero  15
192.168.0.1  [05/Jul/2007:05:03:10 -0700]  Futurama - Less Than Hero  16
192.168.0.1  [05/Jul/2007:05:03:12 -0700]  Futurama - Less Than Hero  18
192.168.0.1  [05/Jul/2007:05:03:13 -0700]  Futurama - Less Than Hero  19
192.168.0.1  [05/Jul/2007:05:03:14 -0700]  Futurama - Less Than Hero  20
192.168.0.1  [05/Jul/2007:05:03:16 -0700]  Futurama - Less Than Hero  22
192.168.0.1  [05/Jul/2007:05:03:17 -0700]  Futurama - Less Than Hero  23
192.168.0.1  [05/Jul/2007:05:03:19 -0700]  Futurama - Less Than Hero  25
192.168.0.1  [05/Jul/2007:05:03:20 -0700]  Futurama - Less Than Hero  26
192.168.0.1  [05/Jul/2007:05:03:21 -0700]  Futurama - Less Than Hero  27
192.168.0.1  [05/Jul/2007:05:03:22 -0700]  Futurama - Less Than Hero  28
192.168.0.1  [05/Jul/2007:05:03:23 -0700]  Futurama - Less Than Hero  29
192.168.0.1  [05/Jul/2007:05:03:24 -0700]  Futurama - Less Than Hero  30
192.168.0.1  [05/Jul/2007:05:03:25 -0700]  Futurama - Less Than Hero  31
192.168.0.1  [05/Jul/2007:05:03:26 -0700]  Futurama - Less Than Hero  32
192.168.0.1  [05/Jul/2007:05:03:27 -0700]  Futurama - Less Than Hero  33
192.168.0.1  [05/Jul/2007:05:03:28 -0700]  Futurama - Less Than Hero  34
192.168.0.1  [05/Jul/2007:05:03:29 -0700]  Futurama - Less Than Hero  35
192.168.0.1  [05/Jul/2007:05:03:31 -0700]  Futurama - Spanish Fry  1
192.168.0.1  [05/Jul/2007:05:03:32 -0700]  Futurama - Spanish Fry  2
192.168.0.1  [05/Jul/2007:05:03:32 -0700]  Futurama - Spanish Fry  3
192.168.0.1  [05/Jul/2007:05:03:34 -0700]  Futurama - Spanish Fry  4
192.168.0.1  [05/Jul/2007:05:03:35 -0700]  Futurama - Spanish Fry  5
192.168.0.1  [05/Jul/2007:05:03:35 -0700]  Futurama - Spanish Fry  6
192.168.0.1  [05/Jul/2007:05:03:37 -0700]  Futurama - Spanish Fry  7
192.168.0.1  [05/Jul/2007:05:03:38 -0700]  Futurama - Spanish Fry  8
192.168.0.1  [05/Jul/2007:05:03:38 -0700]  Futurama - Spanish Fry  9
192.168.0.1  [05/Jul/2007:05:03:39 -0700]  Futurama - Spanish Fry  10
192.168.0.1  [05/Jul/2007:05:03:40 -0700]  Futurama - Spanish Fry  11
192.168.0.1  [05/Jul/2007:05:03:42 -0700]  Futurama - Spanish Fry  12
192.168.0.1  [05/Jul/2007:05:03:42 -0700]  Futurama - Spanish Fry  13
192.168.0.1  [05/Jul/2007:05:03:45 -0700]  Futurama - The Route of All Evil  0
192.168.0.1  [05/Jul/2007:05:03:45 -0700]  Futurama - The Route of All Evil  1
192.168.0.1  [05/Jul/2007:05:03:46 -0700]  Futurama - The Route of All Evil  2
192.168.0.1  [05/Jul/2007:05:03:47 -0700]  Futurama - The Route of All Evil  3
192.168.0.1  [05/Jul/2007:05:03:48 -0700]  Futurama - The Route of All Evil  4
192.168.0.1  [05/Jul/2007:05:03:49 -0700]  Futurama - The Route of All Evil  5
192.168.0.1  [05/Jul/2007:05:03:50 -0700]  Futurama - The Route of All Evil  6
192.168.0.1  [05/Jul/2007:05:03:51 -0700]  Futurama - The Route of All Evil  7
192.168.0.1  [05/Jul/2007:05:03:52 -0700]  Futurama - The Route of All Evil  8
192.168.0.1  [05/Jul/2007:05:03:53 -0700]  Futurama - The Route of All Evil  9
192.168.0.1  [05/Jul/2007:05:03:54 -0700]  Futurama - The Route of All Evil  10
192.168.0.1  [05/Jul/2007:05:03:55 -0700]  Futurama - The Route of All Evil  11
192.168.0.1  [05/Jul/2007:05:03:56 -0700]  Futurama - The Route of All Evil  12
192.168.0.1  [05/Jul/2007:05:03:57 -0700]  Futurama - The Route of All Evil  13

You can see how long I watched each of these videos. Normally your user's IP would be in place of 192.168.0.1, but I'm testing locally.

The final piece of the puzzle would be a script that parsed the log file, looking for the highest number associated with an IP/Title pair and outputs the IP, Titles, and Time or, depending on your needs, outputs the Title and time watched for all IPs.

Maybe like this:
.....IP..............Title...........Time..
192.168.0.1 Futurama - Less Than Hero 35
192.168.0.1 Futurama - Spanish Fry ...13
192.168.0.1 The Route of All Evil ....13
or
.........Title...........Time..
Futurama - Less Than Hero 11
Futurama - Less Than Hero 13
Futurama - Less Than Hero 13
Futurama - Less Than Hero 15
Futurama - Less Than Hero 15
Futurama - Less Than Hero 15
.....................Total 6
Futurama - Spanish Fry ...3
Futurama - Spanish Fry ...10
Futurama - Spanish Fry ...10
Futurama - Spanish Fry ...13
Futurama - Spanish Fry ...13
Futurama - Spanish Fry ...18
Futurama - Spanish Fry ...26
Futurama - Spanish Fry ...136
Futurama - Spanish Fry ...145
.....................Total 9
The Route of All Evil ....1
The Route of All Evil ....1
The Route of All Evil ....1
The Route of All Evil ....3
The Route of All Evil ....3
The Route of All Evil ....3
The Route of All Evil ....5
The Route of All Evil ....13
The Route of All Evil ....14
The Route of All Evil ....16
The Route of All Evil ....19
The Route of All Evil ....33
The Route of All Evil ....45
The Route of All Evil ....66
The Route of All Evil ....78
The Route of All Evil ....89
The Route of All Evil ....99
The Route of All Evil ....103
The Route of All Evil ....134
....................Total 19

Or averages, or whatever meets your needs.

for example code please also see the [url=http://www.jeroenwijering.com/extras/statistics.html]statistics page[/url]...

@andersen,

How do I keep this working without having:

<ul id="data"></ul>

in the <body>? When I comment that out, the JS callback stops, like getUpdate() is no longer being called?!?

@andersen,

The point of my post was to answer David O's (and a lot of other users' question): "Now all we need is to know how much of the video was played when the viewer navigates away.... " which the statistics callback cannot do.

By logging the second-by-second viewing, if the user closes the window, jumps to another site, closes the browser, shuts off his computer, disconnects from the Internet, whatever, you have a record of how much of the video he watched.

Then it's simple to parse that log and find out how much of any or all of your videos your users are watching, before they quit for whatever reason. I know somebody's going to want an answer to that question also, but I don't know how we'll ever get that data.

Would it be possible to add a ratio factor?

Ie, if right now it works like this:
Download 100K testfile --> 2 sec --> 50K stream
Download 100K testfile --> 1 sec --> 100K stream
Download 100K testfile --> 0.5 sec --> 200K stream

But if we can specify a factor (in this case 0.8), it would look like this:
Download 100K testfile --> 2 * 0.8 sec --> 63K stream
Download 100K testfile --> 1 * 0.8 sec --> 125K stream
Download 100K testfile --> 0.5 * 0.8 sec --> 250K stream

This would allow to tweak the speedtestresult/quality ratio manually :)

Hi guys

For the bandwidth detection, does the file have to be named 'video' ?
It works when I name it video, not when I named it 'test'. Of course I also named the flv files test_100 etc. If this is the case I would have a problem where I have 2 audio files I need to play from the same directory.

Also, I get the bandwidth detection saying anything from 300kbps to 900kbps - all within a few secs of testing, what's going on there? Does it really work properly?

Thanks a lot

lol
bandwidth detection does not work properly !
And it's useless...

Is this link of any help to you Jeroen, Will, Andersen? Some clientside javascript to detect bandwidth. Not sure how to implement it into the player myself...

http://www.learningapi.com/sm5/sm5_clientcode.html

In my opinion, bandwidth detection is a BIG waste of time, other than to determine FAST or SLOW.

If the user is on good DSL or better (1.5mbps) bandwidth doesn't matter.

If the user is on dialup or wireless, the connection speed is going to vary tremendously from second to second, so testing is unreliable, other than to determine SLOW.

Good point will. Most users on dialup have common sense not to try and stream video anyway, or if they do, its usually only short clips or they let it all buffer first.

Well I am just using this mainly for audio, it would be super helpful it if worked, otherwise I need to provide 3 different bandwidths to choose from.

@Mark,

The bandwidth detection does work. The problem with dialup, wireless, and other slow connections (and slow connections are the only thing you really need to detect) is that the actual bandwidth varies tremendously from second to second. You could do the bandwidth test multiple times and average it, but that would take time and detract from the user experience.

If you're mainly serving audio, even a slow dialup should be adequate for decent quality sound on computer audio systems, unless you are serving 5.1 MP3s. If the user is on 14.4kbps dialup, maybe they should go listen to a CD.

Hi guys

just a note here to say that bandwidth detection does work great for my requirements. I downloaded a tool called Netlimiter http://www.netlimiter.com/ and I was able to reduce the bandwidth for my browser. The bandwidth detection picks it up perfectly every time and delivers the appropriate file - perfecto! I am very happy and also grateful, thanks Jeroen for the great work. And the Will and Andersen for all your support.

:)(b)

hi,

the bandwidth detection is fine! i am looking for a possibilty to let user change the bandwidth later (while playing) manually.

so far i saw: there is no event to force the bandwidth...

any other ideas?

There's indeed no way to change bandwidths later. But I'll have a look at adding this functionality!

Jeroen, great work on the player! You should be publicly awarded ;-)

I think bandwidth detection is important to make the user experience as transparent as possible, and I'm glad you implemented it.

Here is my experience so far . . .

The speed reported by Flash in the browser varies widely depending on the size of the test file; larger test files produce higher reported data rates (which are also more accurate).

Here are my averaged results:

100k test file: 1,122 kbps
200k test file: 1,846 kbps
500k test file: 3,400 kbps
1000k test file: 5,413 kbps

So which speed is correct? Apparently, none of them.

My actual speed is much higher than any of those figures according to three different web-based speed testing services which very consistently show it to average 14,800 kbps (a fast cable modem).

It doesn't seem practical to use a 1 MB file just to test for bandwidth (and that doesn't produce an accurate result in any case), but if I use the 100k file as suggested in the documentation, the player under-reports actual speed by a factor of 13!

Essentially, a 100k test file gives a VERY conservative result. And if I use it, the player will not play my 1,500 kbps video file even though my connection could easily handle it--instead, because it thinks the bandwidth is around 1,122 kbps, it shifts down to the smaller 500 kbps file I provided as an alternate.

One workaround would be to adjust the size of the test file until the results it gives exceed the maximum bandwidth of your video. For example, if the bandwidth of your big, beautiful, 720 pixel corporate video is 1,800 kbps, according to my results above, a 200k test file testing at 1,826 kbps would allow it play. We know the actual bandwidth of the connection is even higher, so there should never be a problem.

I suppose it's possible to tweak the thresholds of so.addVariable("bwstreams","500,1000"); to trigger at a different point as a way to tweak the behavior, but that seems like such a hack.

Still, it would be best just to know the true speed (within reason).

By the way, the bandwidth shaper like [url=]http://www.netlimiter.com[/url] is useful to test if the player switches between multiple videos when it should.

I'm just bringing all this up to hopefully encourage some discussion and to nail down a method that either more accurately determines the true bandwidth, or presents the best workaround.

You'll get better bandwidth detection with the Media Server detection script, since that one doesn't include ping and averages 5 tries. If you need better detection/streamserving, it's better to use FMS instead of FLV files. For FLV, the bandwidth detection is just a means of doing a rough bandwidth-estimation, I think.

Hi @Jeroen, @Will

Regarding dynamic bandwidth detection (player adjusting output automatically based on user bandwidth) rather than using multiple video files. Using multiple files consumes lot of disk space and is cumbersome..The technique using 100k.jpg file was not reliable. I tried it. It once showed bandwidth as infinity:)I found the following script used by xmoov.(Dynamic bandwidth detection by Terry). I am pasting the script here. Maybe we can adapt it to our player(Stream.php). Will is my guru and an expert and he can make a try. The script is:
=================================================
<?

// SCRIPT CONFIGURATION
//------------------------------------------------------------------------------------------
// MEDIA PATH
//
// you can configure these settings to point to video files outside the public html folder.
//------------------------------------------------------------------------------------------

// points to server root
define('XMOOV_PATH_ROOT', '');

// points to the folder containing the video files.
define('XMOOV_PATH_FILES', 'video/');

//------------------------------------------------------------------------------------------
// SCRIPT BEHAVIOR
//------------------------------------------------------------------------------------------

//set to TRUE to use bandwidth limiting.
define('XMOOV_CONF_LIMIT_BANDWIDTH', TRUE);

//set to FALSE to prohibit caching of video files.
define('XMOOV_CONF_ALLOW_FILE_CACHE', FALSE);

//------------------------------------------------------------------------------------------
// BANDWIDTH SETTINGS
//
// these settings are only needed when using bandwidth limiting.
//
// bandwidth is limited my sending a limited amount of video data(XMOOV_BW_PACKET_SIZE),
// in specified time intervals(XMOOV_BW_PACKET_INTERVAL).
// avoid time intervals over 1.5 seconds for best results.
//
// you can also control bandwidth limiting via http command using your video player.
// the function getBandwidthLimit($part) holds three preconfigured presets(low, mid, high),
// which can be changed to meet your needs
//------------------------------------------------------------------------------------------

//set how many kilobytes will be sent per time interval
define('XMOOV_BW_PACKET_SIZE', 90);

//set the time interval in which data packets will be sent in seconds.
define('XMOOV_BW_PACKET_INTERVAL', 0.3);

//set to TRUE to control bandwidth externally via http.
define('XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH', TRUE);

//------------------------------------------------------------------------------------------
// DYNAMIC BANDWIDTH CONTROL
//------------------------------------------------------------------------------------------

function getBandwidthLimit($part)
{
switch($part)
{
case 'interval' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 1;
break;
case 'mid' :
return 0.5;
break;
case 'high' :
return 0.3;
break;
default :
return XMOOV_BW_PACKET_INTERVAL;
break;
}
break;
case 'size' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 10;
break;
case 'mid' :
return 40;
break;
case 'high' :
return 90;
break;
default :
return XMOOV_BW_PACKET_SIZE;
break;
}
break;
}
}

//------------------------------------------------------------------------------------------
// INCOMING GET VARIABLES CONFIGURATION
//
// use these settings to configure how video files, seek position and bandwidth settings are accessed by your player
//------------------------------------------------------------------------------------------

define('XMOOV_GET_FILE', 'file');
define('XMOOV_GET_POSITION', 'position');
define('XMOOV_GET_AUTHENTICATION', 'key');
define('XMOOV_GET_BANDWIDTH', 'bw');

// END SCRIPT CONFIGURATION - do not change anything beyond this point if you do not know what you are doing

//------------------------------------------------------------------------------------------
// PROCESS FILE REQUEST
//------------------------------------------------------------------------------------------

if(isset($_GET[XMOOV_GET_FILE]) && isset($_GET[XMOOV_GET_POSITION]))
{
// PROCESS VARIABLES

# get seek position
$seekPos = intval($_GET[XMOOV_GET_POSITION]);
# get file name
$fileName = htmlspecialchars($_GET[XMOOV_GET_FILE]);
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;

# assemble packet interval
$packet_interval = (XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('interval') : XMOOV_BW_PACKET_INTERVAL;
# assemble packet size
$packet_size = ((XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('size') : XMOOV_BW_PACKET_SIZE) * 1042;

# security improved by by TRUI www.trui.net
if (!file_exists($file))
{
print('<b>ERROR:</b> xmoov-php could not find (' . $fileName . ') please check your settings.');
exit();
}
if(file_exists($file) && strrchr($fileName, '.') == '.flv' && strlen($fileName) > 2 && !eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg('^[^./][^/]*$', $fileName))
{
$fh = fopen($file, 'rb') or die ('<b>ERROR:</b> xmoov-php could not open (' . $fileName . ')');

$fileSize = filesize($file) - (($seekPos > 0) ? $seekPos + 1 : 0);

// SEND HEADERS
if(!XMOOV_CONF_ALLOW_FILE_CACHE)
{
# prohibit caching (different methods for different clients)
session_cache_limiter("nocache");
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
}

# content headers
header("Content-Type: video/x-flv");
header("Content-Disposition: attachment; filename=\"" . $fileName . "\"");
header("Content-Length: " . $fileSize);

# FLV file format header
if($seekPos != 0)
{
print('FLV');
print(pack('C', 1));
print(pack('C', 1));
print(pack('N', 9));
print(pack('N', 9));
}

# seek to requested file position
fseek($fh, $seekPos);

# output file
while(!feof($fh))
{
# use bandwidth limiting - by Terry
if(XMOOV_CONF_LIMIT_BANDWIDTH)
{
# get start time
list($usec, $sec) = explode(' ', microtime());
$time_start = ((float)$usec + (float)$sec);
# output packet
print(fread($fh, $packet_size));
# get end time
list($usec, $sec) = explode(' ', microtime());
$time_stop = ((float)$usec + (float)$sec);
# wait if output is slower than $packet_interval
$time_difference = $time_stop - $time_start;
if($time_difference < (float)$packet_interval)
{
usleep((float)$packet_interval * 1000000 - (float)$time_difference * 1000000);
}
}
else
{
# output file without bandwidth limiting
print(fread($fh, filesize($file)));
}
}

}

}
?>

========================================

How can we do it in our player ? I am using stream script with playlist generated dynamically from Mysql...

Thanks in advance

Shelley

@will

Will, you there ????????

:)
Will is hiding shelley :)LOL
xmoov.com player is excellent..it is the upcoming flv player...

This is indeed possible as well, but only works with http streaming. The trick with the 100k image and the multiple files work with regular FLV downloads.

The PHP script from XMOOV is a way better solution - if you use http streaming. I've gotten a copy from him myself as well, and will take a look at adapting it.

By the way, there's no bandwidth switching in the XMoov PHP script, but throttling. Though throttling is also very useful, you do need a set of files encoded in different bitrates for bandwidth switching.

In the market there is another Un-believable player is developed by Agriya.
Having all Major Server support and Extra feature. They may have the bandwidth Detection player.

http://www.agriya.com/products.html#flvPlayer

http://www.agriya.com/products.html#flvPlayer

Thanks For the Great Link
Really it is Awesome
(b)

I can't see any really exiting features in Agriya in order change from jeroen's player

Hi I've been using the JWplayer with the Bandwidth detection using 100k image and it works great. I'd like to do something similar with another Flash application I'm building would anyone be able to share with me how this is actually being down in the action script. The only flash detection scripts I can find online use the Flash Communication Server bwcheck.asc file. I'm trying to get away from needing a Flash Communication Server. I would very much like to use the image script that is used in the jwplayer. Any advice would be appreciated.

Thanks

Nikki

Hi,

i hate to cross-post ... but may be this thread is the best place for this question.

Given the inherent problems with detection, I think it would be great to be able to "adjust" the detected bandwidth via the Javascript-API. In case the user is "unhappy" with the determined bandwidth, one could easily adjust the bandwidth selection via JS without having to reload or alter the playlist or do any server-based stuff.

Any thoughts? Best Regards,

Fredrik

Hi Fredrik, note that you can already easily do that. It's the method I prefer myself as well! Just make the links that load a hi/lo quality video into the player and you're done. If you want switching to appear seamlessly, please save the position of the video in JS and then shoot an 'start' flashvar along with the new video file when switching.

what methods to use of bw detection ?

@Larry - from the readme: http://www.jeroenwijering.com/extras/readme.html#interaction

bwfile (url): Image to use for bandwidth checking; used in conjunction with bwstreams. Assign a simple image to this flashvar (this one will do nice), or the rtmp location of the serverside bwcheck script that can be downloaded here. Here's an example bandwidth checking player.
bwstreams (comma-separated list of bitrates): The different streams to use for bandwidth checking; used in conjunction with bwfile. If, for example, you want to play the video video.flv and set this to 100,250,500,1000 and the player detects a bandwidth of 349kbps, the file video_250.flv will be played. Here's an example bandwidth checking player. Note that bandwidth checking is ignored for audio and images!

@JeroenW - thanks for the answer ... in my experience that works fine for single files, but i have yet to figure out how to make this work w/ playlists.
Reloading playlists and selecting a video from that and then setting the "start" flashvar does not seem to work in a reliable way ... so i am basically looking for a way to keep the same playlist loaded but "tell" the player to load the "..._700.flv" flash file instead of the "..._1200.flv" that it auto-detected ... is that possible?

Best Regards,

Fredrik

No, that's not possible yet. I still have to come up with a more decent way of bandwidth detection I see...

I have a small request -- could you add a configuration variable to test for bandwidth *after* the person has hit PLAY (when the video doesn't auto-play?) Otherwise, every single person who runs across the flash applet gets the bwfile, even if they have no intentions of playing it. This adds up on bandwidth costs quick. :(

I know there will be a delay as the download happens/test happens, but I don't mind that much (it'd be really neat if it could say "detecting bandwidth" while it was doing it, but not necessary). :)

Thanks so much!
Justin

Agriya Player appears good. But it is full of bugs. I have tried it and have got the files. If we play multiple files it will show loading at the end of the video continuously. Very bad. No support too. I hope Jeroen will come up with a better design :)

Having multiple files for bandwidth throttling is not a good idea.

Hi,
Just wondering if anyone out there has used the adobe media sever bandwidth detection will an static xml play list ? Not too sure how to combined the two ?

Should I have 3 xml playlist or can I get the flash player to chose the correct rtmp stream from within the xml file.

This is excellent. Jeroen, thank you so much for all your hard work on FLV Player - I use it for every video application I build.

You might want to add bwfile and bwstreams to the "supported flashvars" page, though - I couldn't find them until I did some Googling.

A suggestion: it'd be great if FLV Player could do bandwidth detection once per session (or once per session per day), store the results in a cookie, and then access that cookie to determine the bandwidth for subsequent views. There is video all over my site - I don't like the idea of adding 100KB to every page load for every video on the page.

Also, some pages on my site have multiple FLV Players - the cookie method might also allow players to share the bandwidth test results, rather than each of them conducting its own test. Not sure how doable that is, but I figured it was worth a mention.

I guess I could knock something together with JavaScript, but that complicates things, and requires the user to have JavaScript enabled.

Another thought: If bandwidth detection occurs while the rest of the page is loading, wouldn't you get a lower-than-actual result (because some of the bandwidth is being used to download images and other dependent files)?

FWIW, it's absolutely not true that everyone has bandwidth these days. There are still plenty of grannies out in the countryside with dialup :)

Thanks again!

Yeah, my grannie's only got 47kbps and NO DSL available. Hard to watch Youtube on that when I'm visiting her.

Hi,

So bandwidth detection is not possible with last player version.
I was using the 3.10 and now it disappear...

With one can i choose more recent with it ?

If you re-download the 3.16 it'll be there again. I broke it but quickly put it back in today.

The 4.0 player will not support this kind of bandwidth detection anymore, by the way.

I'm still working on another mechanism, but I want to detect bandwidth from the stream and not from an extra image. Also, mid-stream switching has to be possible.

Hello Jeroen,

I just want to thank you Jeroen for your hard work and for providing such a nice application free. I don't have words for thanking you and your work

Excellent Media Player.

Thanks once again

Hi Jeroen! When you are ready for 4.0 version?

Are there any examples or details of bandwidth detection with 4.0 yet? When I switch over to 4.0 my player no longer works.

Still working on the BW detection. The 4.0 is done, but it didn't make it in there. Here's the roadmap:

http://code.longtailvideo.com/trac/roadmap

And a switchable HD/SD player (toggle button in the control bar) like in dailymotion... possible ?
Thx for such a great player

Yes, a manual toggle is very well possible. That'll be in the 4.2 player. I'm hoping to add automatic toggle in this version as well though (based upon your bandwidth).

I think that kind of the best solution because sometimes people have great bandwith but there computeurs can't handle MP4 hd. Good thing is that when you switch from hd2sd or sd2hd, video stop and go back at the same point. Just the quality change. I Love that on daily'.
Hope I can try it soon and thx again

i have on problem with de api but i resolve it.

somethings class ( player.as ), listen a ModelEvent.BUFFERING, where this event don't exist but exist BUFFER . For that, the player never listen when the video is buffering

I can't wait till JW player supports automatic (dynamic) bandwidth toggling! That and the already implement skinning functionality are huge! :)

@Ojes: thanks for the hint, will fix this!

What will we need to do when it's automatic? Will we just set a flag to say we want to use this, or will the setup be more extensive?

I just want to get a template ready, so as soon as this is ready I can start posting videos with the better bandwidth toggling.

You should just make sure to have a loQ and HiQ version of your videos.

Good morning Jeroen,

First, I just want to say that you are doing an awesome job, your player is so full featured, this is a delight to work with it.

I am about to implement a bandwidth detection mechanism on one of my sites, but after reading several threads on the site and looking at your roadmap (http://code.jeroenwijering.com/trac/milestone/Flash%204.3). You are about to implement it. So I don't want to double up on the work...

My question is, are you still on track for 4.3 to be released in two days?

Thanks,
JG

The 4.3 is indeed done in terms of grunt coding (so you can check it out). However, there's no real bandwidth switching in there (still waiting for FMS3), but you can set a manual bandwidth switch (High Quality - Low Quality, like Vimeo). This is the HD plugin - also available for download already @ the wiki.

OK. It looks like we are stuck with the 3.16 version of the player until FMS3 as well. Our users are not quite savvy enough to know which speed they should click, but they do know when things are not working, or not smooth enough for the speed they are used to.

By the way, edgecast supports FMS 3.0.
http://www.edgecast.com/video_download_stream.htm

Here is the explanation for how it is done:
http://www.adobe.com/devnet/flashmediaserver/articles/dynamic_stream_switching.html

I don't have the experience to understand what is going on in your code, otherwise I would write this change for you. :)

Thank you for all your work

From what I understand, FMS 3.5 will support dynamic streaming seamlessly from a single video but for a smoother bit rate switch during playback, it requires multiple encodings of the video using the extension F4V instead of FLV. So with this in mind, I think it's a good idea to have JW Player 4.3 recognize F4V files. F4V files are just FLV's but with a different extension. "file=flv:video.f4v" doesn't seem to work with JW 4.2.

Hi Jeroen.

We have been using 3.15 very successfully for the last 12 months for Longleat Junior Rangers:

http://www.longleat.co.uk/kidzone/junior-rangers/

And a key feature of it's success has been the old 100k bandwidth detection. The site is mainly watched by 4 to 12 year old Kids and their Mothers and, to be honest, it needs to work like Television - you just turn it on and it works.

We run 4 streams 400,600,800kbps and a 50kbps stream whch displays a graphic telling the viewer that their connection is not fast enough to watch the video. This means that the viewer is never left hanging on waiting for something to happen.

We have just gone into shooting the 2009 series and I will also be producing a similar series for another client.

Now I would like to update the player to make use of the new skins - but from what I have read on the site I am confused as to what V4.2 has to offer regarding Bandwidth detection for progressive download.

Does it or will it ever offer the same flexibiilty as V3.15?

If it doesn't - I'll have to stick with the old player (which is excellent!) as I can't afford to confuse and alienate our regular viewers.

Just another quick observation regarding the old 100k bandwidth detection.

This has also proved very useful where viewers are logged into the site via an office network. The office networks connection to the internet may be very fast but if the network is busy the connection speed at an individual machine can be very low.

In my view - if you are offering video content on your website you need to guarantee that the video or a fallback graphic will play. To leave the audience with a stuttering video or a blank screen is a kiss of death.

Therefore Bandwidth Detection that works without any viewer interaction is of paramount importance.

@Bobak

f4v files are actually mp4 files i think so use

mp4:file.f4v

and it should work.

In Will's post on Jul. 05, 2007 where he shows how to implement logging he refers to Jeroen's JavaScript from the demo page. I can't find this, I think perhaps due to the site changing around. Could anybody provide a link?

thanks

Now Agriya release the another FLV Player names High definition(HD) FLV Player. It supports all the video format
http://www.agriya.com/products-hd-player/

Hello JeroenW,

Just now we have purchard your JW FLV player. We want to play different quality of video. Based on the bandwidth, the player will play the video. Please let me know how is it possible in the latest version.

Thanks