基於flash的web視頻對講直播測試

因爲項目的需求,要在web上實現視頻通話的需求。
現成的方案有WebRTC,基於瀏覽器的成熟方案,可是這個方案和公司項目需求有幾個點衝突。
後來考慮到基於flash的方案。
參考雷神的博客 simplest_as3_rtmp_streamer
http://blog.csdn.net/leixiaohua1020/article/details/43936141web

本機軟件環境Win7_64位下,IE11,Flash Builder 4.7, ffplay播放
攝像頭採用羅技C930e,麥克風用攝像頭自帶的。
服務器採用SRSv2.0_r2瀏覽器

編碼採用ActionScript3腳本語言,flash.media.Video採集視頻,flash.media.Microphone採集音頻,
flash.net.NetConnection鏈接srs服務器,flash.net.NetStream推流。服務器

測試在局域網內視頻通話。
視頻採集分辨率爲1280*720 30fps 200Kbps H264編碼。
音頻採用44100採樣率 單聲道 40kbps nellymoser編碼。
局域網內測試延遲以下:ide

   

代碼改寫自雷神博客,服務器採用srs,特此感謝雷神,感謝Winlin。oop

 1 package {
 2     import flash.display.MovieClip;
 3     import flash.events.NetStatusEvent;
 4     import flash.media.Camera;
 5     import flash.media.H264Level;
 6     import flash.media.H264Profile;
 7     import flash.media.H264VideoStreamSettings;
 8     import flash.media.Microphone;
 9     import flash.media.SoundCodec;
10     import flash.media.Video;
11     import flash.net.NetConnection;
12     import flash.net.NetStream;
13     
14     public class media extends MovieClip
15     {
16         private var nc:NetConnection;
17         private var ns:NetStream;
18         private var nsPlayer:NetStream;
19         private var vid:Video;
20         private var vidPlayer:Video;
21         private var cam:Camera;
22         private var mic:Microphone;
23         
24         private var screen_w:int=384;
25         private var screen_h:int=216;
26         
27         public function media()
28         {
29             nc = new NetConnection();
30             nc.client = {};
31             nc.client.onBWDone = function():void {};
32             nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
33             nc.connect("rtmp://192.168.100.168/testas3/");
34             trace("NetConnection !!!");
35         }
36         
37         private function onNetStatus(event:NetStatusEvent):void{
38             trace(event.info.code);
39             if(event.info.code == "NetConnection.Connect.Success"){
40                 publishCamera();
41                 displayPublishingVideo();
42             }
43         }
44         
45         private function publishCamera(): void{
46             
47             //Cam
48             cam = Camera.getCamera();
49             cam.setMode(1280, 720, 30);  
50             cam.setKeyFrameInterval(30);
51             cam.setQuality(200000, 90); 
52             
53             var x264profile:String = H264Profile.MAIN; // H264Profile.BASELINE;
54             var x264level:String = H264Level.LEVEL_4_1;
55             var h264setting:H264VideoStreamSettings = new H264VideoStreamSettings();  
56             h264setting.setProfileLevel(x264profile, x264level); 
57             
58             //Mic
59             mic = Microphone.getMicrophone();
60             mic.codec = SoundCodec.NELLYMOSER;//SoundCodec.SPEEX
61             mic.setLoopBack(false);
62             mic.gain=55;
63             mic.setUseEchoSuppression(true);
64             mic.rate = 44;  
65 
66             ns = new NetStream(nc);
67             ns.client = {};
68             ns.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void {
69                 trace ("NetStream: code=" + evt.info.code);
70                 // TODO: FIXME: failed event.
71             });
72             
73             //H.264 Setting
74             ns.videoStreamSettings = h264setting; 
75             ns.attachCamera(cam);
76             ns.attachAudio(mic);
77             ns.publish("1111", "live");
78         }
79         
80         private function displayPublishingVideo():void {
81             vid = new Video(screen_w, screen_h);
82             vid.x = 20; 
83             vid.y = 20;
84             vid.attachCamera(cam);
85             addChild(vid);
86         }
87     }
88 }
View Code
相關文章
相關標籤/搜索