8 Replies Latest reply on Aug 14, 2010 2:23 AM by phoenix0625

    Determine bitrate and bandwidth ?

    Philarmon

      Hi !

       

      I have searched for a long time but i just can't figure it out.

       

      My player supports all kind of streams - live, vod, dynamic and progressive download

       

      Now for the tracking purposes, i would need to figure out the bitrate of the stream. That's easy to do for dynamic streams but is there a way to do that for all other kind of streams in OSMF ?

       

      Also, is there some way to figure out user's bandwidth ?

       

      Thank you very much in advance

        • 1. Re: Determine bitrate and bandwidth ?
          charles_newman-SZDpEK

          Hi,

           

          You can get both pieces of information from the NetStream.info property which returns a NetStreamInfo object containing lots of QoS data. Look at the AS3 docs for NetStreamInfo.

           

          The safest way to get to the NetStream (in terms of ensuring capability with future OSMF versions) is to subclass NetLoader and override createNetStream. Of course you can get to the NetStream via the NetStreamLoadTrait but this is a non-public API and is not gauranteed to exist moving forward. There have been some discussions on the OSMF team about exposing NetStream and NetConnection directly, but for now, the former approach is the only method available today that is part of the public API.

           

          - charles

          1 person found this helpful
          • 2. Re: Determine bitrate and bandwidth ?
            Philarmon Level 1

            Thanks Charles,

             

            but i still don't get how do i get to the NetLoader if i use the mediaFactory.createMediaElement() to build my media elements. I really think that exposing those elements would be a good idea.

             

            Basically, it is the same problem i now have like in my other thread so if it will be answered there, please disregard this question.

            http://forums.adobe.com/message/3038279

             

            Thank you !

            Philipp

            • 3. Re: Determine bitrate and bandwidth ?
              Philarmon Level 1

              Hi again !

               

              Finally i've got to the NetStremInfo stuff that helps me with the user's bandwidth but it has no information about the real stream's bitrate. I can see what is the current PLAYED bitrate (currentBytesPerSecond and playbackBytesPerSecond) that constantly changes but that does not mean that the stream was encoded with this bitrate.

               

              I saw that this info is available in the Metadata but somehow it seems that i can't hook it up properly.

               

              If i try

               

              NetClient(netStream.client).addHandler(NetStreamCodes.ON_META_DATA, onMetaData);

               

              I am getting these properties as metadata info:

               

              [trace] videocodecid: avc1
              [trace] duration: 50.92
              [trace] videoframerate: 25
              [trace] tags:
              [trace] avcprofile: 100
              [trace] audiochannels: 2
              [trace] moovPosition: 16694597
              [trace] aacaot: 2
              [trace] trackinfo: [object Object],[object Object]
              [trace] width: 1280
              [trace] audiocodecid: mp4a
              [trace] audiosamplerate: 44100
              [trace] height: 720
              [trace] avclevel: 51

               

              the audiosamplerate is included but no videosamplerate

               

              Then i saw in some code snippets that this approach returned videoDataRate and audioDataRate (that are bitrates as well) - not sure if that is an "older" version of metadata properties though:

               

              var client:Object = netStream.client;
              client.onMetaData = onMetaData;

               

              but OSMF does not seem to like it:

               

              [Fault] exception, information=Error: Error #2089: The Proxy class does not implement setProperty. It must be overridden by a subclass.

               

              HEEEELP !

              • 4. Re: Determine bitrate and bandwidth ?
                Andrian Cucu Adobe Employee

                Hi,

                 

                Here is how I did it:

                 

                 50                NetClient(netStream.client).addHandler(NetStreamCodes.ON_META_DATA, onMetaData);
                 51                function onMetaData(value:Object):void
                 52                {
                 53                     NetClient(netStream.client).removeHandler(NetStreamCodes.ON_META_DATA, onMetaData);
                 54                     // We assume that the asset metadata has the most accurate value,
                 55                     // that's why we overwrite any existing value.
                 56
                 57                     // audiodatarate and videodatarate are set in kilobits. We need to transform it to bytes. 
                 58                     averagePlaybackBytesPerSecond = (value.audiodatarate + value.videodatarate)* KBITSPS_BYTESTPS_RATIO;
                 59                     duration = value.duration;
                 60                }

                 

                 

                https://sourceforge.net/adobe/smp/svn/LATEST/tree/trunk/player/StrobeMediaPlayback/src/org /osmf/net/PlaybackOptimizationMetrics.as


                Note that this metadata is usually not available. You better compute the average yourself (or try to retrieve the metadata just as a hint to speed things up) - you can see how I did it there too.

                 

                Hope this helps,

                -Andrian

                 

                P.S. If you see something wrong or if you think that there are things that can be improved with the approach above, I'd appreciate to get your feedback.

                • 5. Re: Determine bitrate and bandwidth ?
                  Philarmon Level 1

                  Thanks Andrian, that's how i do it but i am just not getting these value.audiodatarate and value.videodatarate and i can't understand why ...

                   

                  Yes, I could calculate the average played bitrate but that's not what i want, i need the actual bitrate of the stream.

                   

                  Anyone ?

                   

                  PS BTW, I love your player Andrian, lots of interesting tweaks there.

                   


                  • 6. Re: Determine bitrate and bandwidth ?
                    Andrian Cucu Adobe Employee

                    Philarmon, if they are not there you cannot get this information, unless there is some kind magic which I don't master. Let's see if we can get a real wizard here

                     

                    Anyone?

                     

                    p.s. Thank You! Btw, do you use the bitrate for buffer optimization or for dynamic stream switch optimization?

                    • 7. Re: Determine bitrate and bandwidth ?
                      Philarmon Level 1

                      Hmm, It turned out that there are different sets of metadata depending on encoding. For some streams i am getting this set:

                       

                      [trace] videodatarate: 450
                      [trace] audiosamplerate: 44100
                      [trace] audiocodecid: 2
                      [trace] keywords:
                      [trace] width: 400
                      [trace] audiochannels: 1
                      [trace] creationdate: Thu Aug 12 10:51:40 2010
                      [trace] avclevel: 31
                      [trace] framerate: 25
                      [trace] title:
                      [trace] audiodevice: Osprey-210 Audio Device 2
                      [trace] description:
                      [trace] audiodatarate: 96
                      [trace] audioinputvolume: 75
                      [trace] author:
                      [trace] presetname: Custom
                      [trace] avcprofile: 66
                      [trace] rating:
                      [trace] videodevice: Osprey-210 Video Device 2.1
                      [trace] height: 300
                      [trace] copyright:
                      [trace] videocodecid: 7

                       

                      For some, i am only getting this:

                       

                      [trace] videocodecid: avc1
                      [trace] duration: 50.92
                      [trace] videoframerate: 25
                      [trace] tags:
                      [trace] avcprofile: 100
                      [trace] audiochannels: 2
                      [trace] moovPosition: 16694597
                      [trace] aacaot: 2
                      [trace] trackinfo: [object Object],[object Object]
                      [trace] width: 1280
                      [trace] audiocodecid: mp4a
                      [trace] audiosamplerate: 44100
                      [trace] height: 720
                      [trace] avclevel: 51

                       

                      Nevertheless, thanks a lot for the help

                       

                      >> Btw, do you use the bitrate for buffer optimization or for dynamic stream switch optimization?

                       

                      No, we actually just need it for the tracking purposes

                      • 8. Re: Determine bitrate and bandwidth ?
                        phoenix0625

                        Hi Phil,

                         

                        Could you please tell me what kind of encoding offers the video data rate metadata?

                         

                        Thanks

                        SR