·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3.0发布h264视频编码的视频流stream

时间:2016-01-07 09:02酷播
[AS3]as3.0发布h264视频编码的视频流stream,NetStream.publish捕捉摄像头的图像,并编码后发送到FMS服务器。flash 11终于支持发布h264的流。因为推送h264的流,需要flash player能编码h264格式视频

NetStream.publish捕捉摄像头的图像,并编码后发送到FMS服务器。flash 11终于支持发布h264的流。因为推送h264的流,需要flash player能编码h264格式视频,在flash player 11加入了h264编码器。

官方参考:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/H264VideoStreamSettings.html

编写推送h164的as程序必须要较高版本的sdk,之前使用的flex sdk 4.1的flash player版本是10.0,不能用来编写这个程序。

下载flex sdk:

http://www.adobe.com/devnet/flex/flex-sdk-download.html

 

 h264和h263对比图(同样的码率和分辨率):

  1. package 
  2.     import fl.controls.Button; 
  3.     import fl.controls.CheckBox; 
  4.     import fl.controls.ComboBox; 
  5.     import fl.controls.Label; 
  6.     import fl.controls.TextInput; 
  7.      
  8.     import flash.display.Sprite; 
  9.     import flash.display.StageAlign; 
  10.     import flash.display.StageScaleMode; 
  11.     import flash.events.Event; 
  12.     import flash.events.MouseEvent; 
  13.     import flash.events.NetStatusEvent; 
  14.     import flash.media.Camera; 
  15.     import flash.media.H264Profile; 
  16.     import flash.media.H264VideoStreamSettings; 
  17.     import flash.media.Microphone; 
  18.     import flash.media.Video; 
  19.     import flash.net.NetConnection; 
  20.     import flash.net.NetStream; 
  21.      
  22.     public class H264Publisher extends Sprite 
  23.     {     
  24.         public function H264Publisher() 
  25.         { 
  26.             if(this.stage == null){ 
  27.                 this.addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage); 
  28.             } 
  29.             else{ 
  30.                 this.onAddedToStage(null); 
  31.             } 
  32.         } 
  33.          
  34.         private function onAddedToStage(evt:Event):void{ 
  35.             this.stage.align = StageAlign.TOP_LEFT; 
  36.             this.stage.scaleMode = StageScaleMode.NO_SCALE; 
  37.              
  38.             var urlPanel:Sprite = new Sprite(); 
  39.             this.addUrlPanel(urlPanel, onMouseClickStartPublish, onMouseClickStopPublish); 
  40.              
  41.             var cameraPanel:Sprite = new Sprite(); 
  42.             this.addCameraPanel(cameraPanel); 
  43.              
  44.             var encodingPanel:Sprite = new Sprite(); 
  45.             this.addEncodingPanel(encodingPanel); 
  46.              
  47.             urlPanel.x = 10
  48.             urlPanel.y = 10
  49.              
  50.             cameraPanel.x = urlPanel.x; 
  51.             cameraPanel.y = urlPanel.y + 30; 
  52.              
  53.             encodingPanel.x = cameraPanel.x; 
  54.             encodingPanel.y = cameraPanel.y + 30; 
  55.              
  56.             video = new Video(); 
  57.             video.x = encodingPanel.x; 
  58.             video.y = encodingPanel.y + 30; 
  59.              
  60.             this.addChild(urlPanel); 
  61.             this.addChild(cameraPanel); 
  62.             this.addChild(encodingPanel); 
  63.             this.addChild(video); 
  64.         } 
  65.          
  66.         private var fmsUrl:String; 
  67.         private var fmsStream:String; 
  68.         private function discoveryFmsUrl():void{ 
  69.             var url:String = txtUrl.text; 
  70.              
  71.             if(url.toLowerCase().indexOf("rtmp://") < 0){ 
  72.                 trace("[error] the url must start with rtmp://", "error"); 
  73.                 return; 
  74.             } 
  75.              
  76.             // remove the start rtmp:// 
  77.             urlurl = url.substr(url.toLowerCase().indexOf("rtmp://") + "rtmp://".length); 
  78.              
  79.             var server:String = url.substr(0, url.indexOf("/")); 
  80.             urlurl = url.substr(url.indexOf("/") + 1); 
  81.              
  82.             var port:String = "1935"
  83.             if(server.indexOf(":") >= 0){ 
  84.                 port = server.substr(server.indexOf(":")+1); 
  85.                 serverserver = server.substr(0, server.indexOf(":")); 
  86.             } 
  87.              
  88.             var appIndex:int = -1; 
  89.             for(var i:int = 0; i < this.cbAppLevel.selectedIndex + 1; i++){ 
  90.                 if(url.indexOf("/", appIndex + 1) < 0){ 
  91.                     break; 
  92.                 } 
  93.                  
  94.                 appIndex = url.indexOf("/", appIndex + 1); 
  95.             } 
  96.             var app:String = url.substr(0, appIndex); 
  97.             var stream:String = url.substr(appIndex + 1); 
  98.              
  99.             // if user input ip address, set the server; otherwise, set the vhost. 
  100.             var serverIsIPAddress:Boolean = true
  101.             var serverserverItems:Array = server.split("."); 
  102.             for(i = 0; i < serverItems.length; i++){ 
  103.                 if(isNaN(Number(serverItems[i]))){ 
  104.                     serverIsIPAddress = false
  105.                 } 
  106.             } 
  107.              
  108.             fmsUrl = "rtmp://" + server + ":" + port + "/" + app; 
  109.             fmsStream = stream
  110.         } 
  111.          
  112.         private function buildEncodingParameters(publishStream:NetStream, c:Camera, m:Microphone):void{ 
  113.             var x264profile:String = (this.cbX264Profile.selectedLabel == "Main") ? H264Profile.MAIN : H264Profile.BASELINE; 
  114.             var x264level:String = this.cbX264Level.selectedLabel; 
  115.             var x264KeyFrameInterval:int = int(this.cbX264KeyFrameInterval.selectedIndex + 1); 
  116.             var cameraWidth:int = int(this.cbCameraSize.selectedLabel.substr(0, this.cbCameraSize.selectedLabel.indexOf("x"))); 
  117.             var cameraHeight:int = int(this.cbCameraSize.selectedLabel.substr(this.cbCameraSize.selectedLabel.indexOf("x") + 1));; 
  118.             var cameraFps:Number = Number(this.cbCameraFps.selectedLabel); 
  119.             var cameraBitrate:int = int(this.cbCameraBitrate.selectedLabel); 
  120.             var cameraQuality:int = 85
  121.             var microEncodeQuality:int = 8
  122.             var microRate:int = 22; // 22 === 22050 Hz 
  123.              
  124.             trace("[Publish] h.264(x264) encoding parameters: "  
  125.                 + "profile=" + x264profile  
  126.                 + ", level=" + x264level 
  127.                 + ", keyFrameInterval(gop)=" + x264KeyFrameInterval 
  128.                 + "; video(camera) width=" + cameraWidth 
  129.                 + ", height=" + cameraHeight 
  130.                 + ", fps=" + cameraFps 
  131.                 + ", bitrate=" + cameraBitrate 
  132.                 + ", quality=" + cameraQuality 
  133.                 + "; audio(microphone) encodeQuality=" + microEncodeQuality 
  134.                 + ", rate=" + microRate + "(22050Hz)" 
  135.             ); 
  136.              
  137.             var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings(); 
  138.             // we MUST set its values first, then set the NetStream.videoStreamSettings, or it will keep the origin values. 
  139.             h264Settings.setProfileLevel(x264profile, x264level);  
  140.             publishStream.videoStreamSettings = h264Settings
  141.             // the setKeyFrameInterval/setMode/setQuality use the camera settings. 
  142.             // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/VideoStreamSettings.html 
  143.             // Note This feature will be supported in future releases of Flash Player and AIR, for now, Camera parameters are used. 
  144.             /*h264Settings.setKeyFrameInterval(4); 
  145.             h264Settings.setMode(800, 600, 15); 
  146.             h264Settings.setQuality(500, 0);*/ 
  147.              
  148.             // set the camera and microphone. 
  149.              
  150.             // setKeyFrameInterval(keyFrameInterval:int):void 
  151.             //     keyFrameInterval:int — A value that specifies which video frames are transmitted in full (as keyframes) instead of being  
  152.             //        interpolated by the video compression algorithm. A value of 1 means that every frame is a keyframe, a value of 3 means  
  153.             //        that every third frame is a keyframe, and so on. Acceptable values are 1 through 48. 
  154.             c.setKeyFrameInterval(x264KeyFrameInterval); 
  155.              
  156.             // setMode(width:int, height:int, fps:Number, favorArea:Boolean = true):void 
  157.             //  width:int — The requested capture width, in pixels. The default value is 160. 
  158.             //  height:int — The requested capture height, in pixels. The default value is 120. 
  159.             //  fps:Number — The requested rate at which the camera should capture data, in frames per second. The default value is 15. 
  160.             c.setMode(cameraWidth, cameraHeight, cameraFps); 
  161.              
  162.             // setQuality(bandwidth:int, quality:int):void 
  163.             //  bandwidth:int — Specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.  
  164.             //        To specify that the video can use as much bandwidth as needed to maintain the value of quality, pass 0 for bandwidth.  
  165.             //        The default value is 16384. 
  166.             //  quality:int — An integer that specifies the required level of picture quality, as determined by the amount of compression  
  167.             //         being applied to each video frame. Acceptable values range from 1 (lowest quality, maximum compression) to 100  
  168.             //        (highest quality, no compression). To specify that picture quality can vary as needed to avoid exceeding bandwidth,  
  169.             //        pass 0 for quality. 
  170.             //  winlin: 
  171.             //        bandwidth is in bps not kbps. 500*1000 = 500kbps
  172.             //        quality=1 is lowest quality, 100 is highest quality. 
  173.             c.setQuality(cameraBitrate * 1000, cameraQuality); 
  174.              
  175.             // if no microphone, donot set the params. 
  176.             if(m == null){ 
  177.                 return; 
  178.             } 
  179.              
  180.             // The encoded speech quality when using the Speex codec. Possible values are from 0 to 10. The default value is 6. Higher numbers  
  181.             // represent higher quality but require more bandwidth, as shown in the following table. The bit rate values that are listed represent  
  182.             // net bit rates and do not include packetization overhead. 
  183.             m.encodeQuality = microEncodeQuality
  184.              
  185.             // The rate at which the microphone is capturing sound, in kHz. Acceptable values are 5, 8, 11, 22, and 44. The default value is 8 kHz  
  186.             // if your sound capture device supports this value. Otherwise, the default value is the next available capture level above 8 kHz that  
  187.             // your sound capture device supports, usually 11 kHz. 
  188.             m.rate = microRate
  189.         } 
  190.          
  191.         private var publishStream:NetStream; 
  192.         private var publishConnection:NetConnection; 
  193.         private function onMouseClickStartPublish(evt:MouseEvent):void{ 
  194.             // if published, donothing 
  195.             if(publishStream != null){ 
  196.                 return; 
  197.             } 
  198.              
  199.             this.btnStartPublish.enabled = false
  200.             this.btnStopPublish.enabled = true
  201.              
  202.             this.discoveryFmsUrl(); 
  203.              
  204.             publishConnection = new NetConnection(); 
  205.             var conn:NetConnection = publishConnection
  206.              
  207.             conn.client = {}; 
  208.             conn.client.onBWDone = function():void{}; 
  209.              
  210.             conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{ 
  211.                 trace("[Publish][connection] code:" + evt.info.code); 
  212.                  
  213.                 switch(evt.info.code){ 
  214.                     case "NetConnection.Connect.Success": 
  215.                         publishStream = new NetStream(conn); 
  216.                         // microphone and camera 
  217.                         var m:Microphone = Microphone.getMicrophone(cbMicrophone.selectedIndex); 
  218.                         // Remark: the name is the index! 
  219.                         var c:Camera = Camera.getCamera(String(cbCamera.selectedIndex)); 
  220.                         if(c == null){ 
  221.                             trace("[Publish][error] failed to open camera(name=" + String(cbCamera.selectedIndex) + "): " + cbCamera.selectedLabel, "error"); 
  222.                             cleanupPublishedStream(); 
  223.                             break; 
  224.                         } 
  225.                         else if(c.muted){ 
  226.                             trace("[Publish][error] open camera(name=" + String(cbCamera.selectedIndex) + ") failed, it's muted: " + cbCamera.selectedLabel, "error"); 
  227.                             cleanupPublishedStream(); 
  228.                             break; 
  229.                         } 
  230.                          
  231.                         buildEncodingParameters(publishStream, c, m); 
  232.                          
  233.                         publishStream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{ 
  234.                             trace("[Publish][NetStreamStatus]" + evt.info.code); 
  235.                              
  236.                             switch(evt.info.code){ 
  237.                                 case "NetStream.Publish.Start": 
  238.                                     var h264:H264VideoStreamSettings = publishStream.videoStreamSettings as H264VideoStreamSettings; 
  239.                                     trace("[Publish] video codec: " + h264.codec  
  240.                                         + ", profile=" + h264.profile 
  241.                                         + ", level=" + h264.level 
  242.                                         + ", quality=" + h264.quality 
  243.                                         + ", fps=" + h264.fps 
  244.                                         + ", gop=" + h264.keyFrameInterval 
  245.                                         + ", bandwidth=" + h264.bandwidth 
  246.                                         + ", size=" + h264.width + "x" + h264.height); 
  247.                                     break; 
  248.                                 case "NetStream.Publish.BadName": 
  249.                                     cleanupPublishedStream(); 
  250.                                     break; 
  251.                             } 
  252.                         }); 
  253.                         publishStream.publish(fmsStream); 
  254.                          
  255.                         // attach video and audio. 
  256.                         trace("[Publish][debug] start publish, using camera(name=" + String(cbCamera.selectedIndex) + "): " + c.name); 
  257.                         publishStream.attachCamera(c); 
  258.                         if(m != null && !m.muted){ 
  259.                             trace("[Publish][debug] start publish, using microphone(name=" + String(cbMicrophone.selectedIndex) + "): " + m.name); 
  260.                             publishStream.attachAudio(m); 
  261.                         } 
  262.                         restartPlayback(); 
  263.                         break; 
  264.                     case "NetConnection.Connect.Rejected": 
  265.                     case "NetConnection.Connect.Failed": 
  266.                         cleanupPublishedStream(); 
  267.                         break; 
  268.                 } 
  269.             }); 
  270.              
  271.             conn.connect(fmsUrl); 
  272.         } 
  273.         private function cleanupPublishedStream():void{ 
  274.             this.btnStartPublish.enabled = true
  275.             this.btnStopPublish.enabled = false
  276.             if(this.publishStream != null){ 
  277.                 this.publishStream.close(); 
  278.             } 
  279.             if(this.publishConnection != null){ 
  280.                 this.publishConnection.close(); 
  281.             } 
  282.             this.publishStream = null
  283.         } 
  284.          
  285.         public var stream:NetStream; 
  286.         private var conn:NetConnection; 
  287.         private var video:Video; 
  288.         private function restartPlayback():void{ 
  289.             // stream is playing, resume it. 
  290.             if(this.stream != null){ 
  291.                 this.stream.close(); 
  292.             } 
  293.              
  294.             conn = new NetConnection(); 
  295.              
  296.             conn.client = {}; 
  297.             conn.client.onBWDone = function():void{}; 
  298.             conn.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{ 
  299.                 trace("[connection] code:" + evt.info.code + " desc:" + evt.info.description); 
  300.                  
  301.                 switch(evt.info.code){ 
  302.                     case "NetConnection.Connect.Success": 
  303.                         stream = new NetStream(conn); 
  304.                         video.attachNetStream(stream); 
  305.                          
  306.                         //stream.bufferTime = 3
  307.                         stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{ 
  308.                             trace("[NetStreamStatus]" + evt.info.code + " desc:" + evt.info.description); 
  309.                         }); 
  310.                         stream.client = {}; 
  311.                         stream.client.onMetaData = function onMetadata(metadata:Object):void{ 
  312.                             var o:Object = {}; 
  313.                             for(var key:String in metadata){ 
  314.                                 o[key] = metadata[key]; 
  315.                                 trace("[metadata] " + "key=" + key + "value=" + o[key]); 
  316.                             } 
  317.                              
  318.                             if(metadata.width == undefined){ 
  319.                                 metadata.width = 10
  320.                                 trace("[warning] metadata.width is undefied, set to 10"); 
  321.                             } 
  322.                             if(metadata.height == undefined){ 
  323.                                 metadata.height = 10
  324.                                 trace("[warning] metadata.height is undefied, set to 10"); 
  325.                             } 
  326.                              
  327.                             video.width = metadata.width; 
  328.                             video.height = metadata.height; 
  329.                         }; 
  330.                          
  331.                         if(!cbIsLive.selected){ 
  332.                             stream.play(fmsStream, 0); 
  333.                         } 
  334.                         else{ 
  335.                             stream.play(fmsStream); 
  336.                         } 
  337.                         break; 
  338.                     case "NetConnection.Connect.Rejected": 
  339.                     case "NetConnection.Connect.Failed": 
  340.                         stream.close(); 
  341.                         stream = null
  342.                         break; 
  343.                 } 
  344.             }); 
  345.             conn.connect(fmsUrl); 
  346.         } 
  347.          
  348.         private function onMouseClickStopPublish(evt:MouseEvent):void{ 
  349.             this.cleanupPublishedStream(); 
  350.         } 
  351.          
  352.         private var txtUrl:TextInput; 
  353.         private var btnStartPublish:Button; 
  354.         private var btnStopPublish:Button; 
  355.         private var cbAppLevel:ComboBox; 
  356.         private var cbIsLive:CheckBox; 
  357.         private function addUrlPanel( 
  358.             panel:Sprite,  
  359.             onMouseClickStartPublish:Function, onMouseClickStopPublish:Function 
  360.         ):void{ 
  361.             var lblUrl:Label = new Label(); 
  362.             lblUrl.text = "RTMP Url:"
  363.             lblUrl.width = 50
  364.             panel.addChild(lblUrl); 
  365.              
  366.             txtUrl = new TextInput(); 
  367.             txtUrl.width = 380
  368.             txtUrl.x = lblUrl.x + lblUrl.width + 3; 
  369.             panel.addChild(txtUrl); 
  370.              
  371.             cbIsLive = new CheckBox(); 
  372.             cbIsLive.selected = true
  373.             cbIsLive.label = "Live"
  374.             cbIsLive.width = 53
  375.             cbIsLive.x = txtUrl.x + txtUrl.width + 0; 
  376.             panel.addChild(cbIsLive); 
  377.              
  378.             cbAppLevel = new ComboBox(); 
  379.             cbAppLevel.addItem({label: "1级App"}); 
  380.             cbAppLevel.addItem({label: "2级App"}); 
  381.             cbAppLevel.addItem({label: "3级App"}); 
  382.             cbAppLevel.addItem({label: "4级App"}); 
  383.             cbAppLevel.width = 70
  384.             cbAppLevel.x = cbIsLive.x + cbIsLive.width + 0; 
  385.             panel.addChild(cbAppLevel); 
  386.              
  387.             btnStartPublish = new Button(); 
  388.             btnStartPublish.label = "发布流"
  389.             btnStartPublish.width = 60
  390.             btnStartPublish.x = cbAppLevel.x + cbAppLevel.width + 3; 
  391.             btnStartPublish.addEventListener(MouseEvent.CLICK, onMouseClickStartPublish); 
  392.             panel.addChild(btnStartPublish); 
  393.              
  394.             btnStopPublish = new Button(); 
  395.             btnStopPublish.label = "停止发布"
  396.             btnStopPublish.width = 60
  397.             btnStopPublish.enabled = false
  398.             btnStopPublish.x = btnStartPublish.x + btnStartPublish.width + 3; 
  399.             btnStopPublish.addEventListener(MouseEvent.CLICK, onMouseClickStopPublish); 
  400.             panel.addChild(btnStopPublish); 
  401.         } 
  402.          
  403.         private var cbX264Profile:ComboBox; 
  404.         private var cbX264Level:ComboBox; 
  405.         private var cbX264KeyFrameInterval:ComboBox; 
  406.         private var cbCameraSize:ComboBox; 
  407.         private var cbCameraFps:ComboBox; 
  408.         private var cbCameraBitrate:ComboBox; 
  409.         private function addEncodingPanel( 
  410.             panel:Sprite 
  411.         ):void{ 
  412.             var lblX264Profile:Label = new Label(); 
  413.             lblX264Profile.text = "Profile:"
  414.             lblX264Profile.width = 38
  415.             lblX264Profile.y = 2; 
  416.             panel.addChild(lblX264Profile); 
  417.              
  418.             cbX264Profile = new ComboBox(); 
  419.             cbX264Profile.width = 72
  420.             cbX264Profile.x = lblX264Profile.x + lblX264Profile.width + 0; 
  421.             panel.addChild(cbX264Profile); 
  422.             cbX264Profile.addItem({label:"Baseline"}); 
  423.             cbX264Profile.addItem({label:"Main"}); 
  424.              
  425.             var lblX264Level:Label = new Label(); 
  426.             lblX264Level.text = "Level:"
  427.             lblX264Level.width = 32
  428.             lblX264Level.y = 2; 
  429.             lblX264Level.x = cbX264Profile.x + cbX264Profile.width + 1; 
  430.             panel.addChild(lblX264Level); 
  431.              
  432.             cbX264Level = new ComboBox(); 
  433.             cbX264Level.width = 45
  434.             cbX264Level.x = lblX264Level.x + lblX264Level.width + 1; 
  435.             panel.addChild(cbX264Level); 
  436.             var x264Levels:Array = ["1", "1b", "1.1", "1.2", "1.3", "2", "2.1", "2.2", "3", "3.1", "3.2", "4", "4.1", "4.2", "5", "5.1"]; 
  437.             for(var i:int = 0; i < x264Levels.length; i++){ 
  438.                 cbX264Level.addItem({label:x264Levels[i]}); 
  439.             } 
  440.             cbX264Level.selectedIndex = 8
  441.              
  442.             var lblX264KeyFrameInterval:Label = new Label(); 
  443.             lblX264KeyFrameInterval.text = "GOP:"
  444.             lblX264KeyFrameInterval.width = 29
  445.             lblX264KeyFrameInterval.y = 2; 
  446.             lblX264KeyFrameInterval.x = cbX264Level.x + cbX264Level.width + 1; 
  447.             panel.addChild(lblX264KeyFrameInterval); 
  448.              
  449.             cbX264KeyFrameInterval = new ComboBox(); 
  450.             cbX264KeyFrameInterval.width = 87
  451.             cbX264KeyFrameInterval.x = lblX264KeyFrameInterval.x + lblX264KeyFrameInterval.width + 1; 
  452.             panel.addChild(cbX264KeyFrameInterval); 
  453.             for(i = 0; i < 48; i++){ 
  454.                 cbX264KeyFrameInterval.addItem({label:String(i + 1) + " seconds"}); 
  455.             } 
  456.             cbX264KeyFrameInterval.selectedIndex = 3
  457.              
  458.             var lblCameraSize:Label = new Label(); 
  459.             lblCameraSize.text = "Size:"
  460.             lblCameraSize.width = 30
  461.             lblCameraSize.y = 2
  462.             lblCameraSize.x = cbX264KeyFrameInterval.x + cbX264KeyFrameInterval.width + 1; 
  463.             panel.addChild(lblCameraSize); 
  464.              
  465.             cbCameraSize = new ComboBox(); 
  466.             cbCameraSize.width = 82
  467.             cbCameraSize.x = lblCameraSize.x + lblCameraSize.width + 1; 
  468.             panel.addChild(cbCameraSize); 
  469.             var sizes:Array = ["176x144", "320x240", "352x240", "352x288", "640x480", "720x480", "720x576", "800x600", "1024x768", "1280x720", "1360x768", "1920x1080"]; 
  470.             for(i = 0; i < sizes.length; i++){ 
  471.                 cbCameraSize.addItem({label:sizes[i]}); 
  472.             } 
  473.             cbCameraSize.selectedIndex = 1
  474.              
  475.             var lblCameraFps:Label = new Label(); 
  476.             lblCameraFps.text = "FPS:"
  477.             lblCameraFps.width = 28
  478.             lblCameraFps.y = 2
  479.             lblCameraFps.x = cbCameraSize.x + cbCameraSize.width + 1; 
  480.             panel.addChild(lblCameraFps); 
  481.              
  482.             cbCameraFps = new ComboBox(); 
  483.             cbCameraFps.width = 58
  484.             cbCameraFps.x = lblCameraFps.x + lblCameraFps.width + 1; 
  485.             panel.addChild(cbCameraFps); 
  486.             var fpses:Array = ["1.00", "4.00", "5.00", "6.00", "8.00", "10.00", "12.00", "14.98", "15.00", "20.00", "24.00", "25.00", "29.97", "30.00", "59.94", "60.00"]; 
  487.             for(i = 0; i < fpses.length; i++){ 
  488.                 cbCameraFps.addItem({label:fpses[i]}); 
  489.             } 
  490.             cbCameraFps.selectedIndex = 8
  491.              
  492.             var lblCameraBitrate:Label = new Label(); 
  493.             lblCameraBitrate.text = "Bitrate:"
  494.             lblCameraBitrate.width = 40
  495.             lblCameraBitrate.y = 2
  496.             lblCameraBitrate.x = cbCameraFps.x + cbCameraFps.width + 1; 
  497.             panel.addChild(lblCameraBitrate); 
  498.              
  499.             cbCameraBitrate = new ComboBox(); 
  500.             cbCameraBitrate.width = 58
  501.             cbCameraBitrate.x = lblCameraBitrate.x + lblCameraBitrate.width + 1; 
  502.             panel.addChild(cbCameraBitrate); 
  503.             var bitrates:Array = ["10", "50", "100", "200", "350", "500", "650", "800", "950", "1000", "1200", "1500", "1800", "2000", "2500", "20000"]; 
  504.             for(i = 0; i < bitrates.length; i++){ 
  505.                 cbCameraBitrate.addItem({label:bitrates[i]}); 
  506.             } 
  507.             cbCameraBitrate.selectedIndex = 3
  508.         } 
  509.          
  510.         private var cbCamera:ComboBox; 
  511.         private var cbMicrophone:ComboBox; 
  512.         private function addCameraPanel( 
  513.             panel:Sprite 
  514.         ):void{ 
  515.             // camera 
  516.             var lblCamera:Label = new Label(); 
  517.             lblCamera.text = "Available Cameras:"
  518.             lblCamera.width = 100
  519.             panel.addChild(lblCamera); 
  520.              
  521.             cbCamera = new ComboBox(); 
  522.             cbCamera.width = 160
  523.             cbCamera.x = lblCamera.x + lblCamera.width + 3; 
  524.             panel.addChild(cbCamera); 
  525.              
  526.             var cameras:Array = Camera.names; 
  527.             for(var i:int = 0; i < cameras.length; i++){ 
  528.                 cbCamera.addItem({label:cameras[i]}); 
  529.             } 
  530.              
  531.             // microphone 
  532.             var lblMicrophone:Label = new Label(); 
  533.             lblMicrophone.text = "Available Microphones:"
  534.             lblMicrophone.width = 120
  535.             lblMicrophone.x = cbCamera.x + cbCamera.width + 10; 
  536.             panel.addChild(lblMicrophone); 
  537.              
  538.             cbMicrophone = new ComboBox(); 
  539.             cbMicrophone.width = 180
  540.             cbMicrophone.x = lblMicrophone.x + lblMicrophone.width + 3; 
  541.             panel.addChild(cbMicrophone); 
  542.              
  543.             var microphones:Array = Microphone.names; 
  544.             for(i = 0; i < microphones.length; i++){ 
  545.                 cbMicrophone.addItem({label:microphones[i]}); 
  546.             } 
  547.         } 
  548.     } 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器