Flash RTMP记录器490错误

时间:2014-05-21 11:12:52

标签: flash flex nginx rtmp

我有一个flv文件(请参阅随附的flex代码)来记录网络摄像头流并发布rtmp(rtmp-nginx-module)服务器。

偶尔和随机地,flv流到达几分钟而不是几秒钟,服务器490指示日志中的错误

有这种配置(或类似)的其他人有类似的问题吗?如何记录错误以查看flash帖子?

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="500" minHeight="350" creationComplete="init()" initialize="initApp()">

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.core.FlexGlobals;
            private var isRecording:Boolean;
            private var streamer:String;
            private var file:String;
            private var publishType:String;
            private var onStopRecord:String;
            private var onError:String;
            private var labelRecord:String;
            private var labelStop:String;
            private var camera:Camera;
            private var microphone:Microphone;
            private var connection:NetConnection;
            private var stream:NetStream;
            private var h264Settings:H264VideoStreamSettings;

            public function initApp():void
            {
                if (ExternalInterface.available)
                {
                    ExternalInterface.addCallback("RmtpStart", RmtpStart);    
                    ExternalInterface.addCallback("RmtpStop",  RmtpStop );    
                }
            }

            public function RmtpStart():void
            {
                if (!isRecording) {
                    isRecording = true;
                    stream.publish(file, publishType);
                    videoDisplay.attachCamera(camera);
                }
            }

            public function RmtpStop():void
            {
                if (isRecording) {
                    isRecording = false;
                    callWrapper();
                    stream.close();
                    videoDisplay.attachCamera(null);
                }
            }

            public function callWrapper():void {
                var s:String;
                if (ExternalInterface.available) {
                   var wrapperFunction:String = onStopRecord;
                   s = ExternalInterface.call(wrapperFunction,"ok");
                } else {
                   s = "Wrapper not available";
                }
            }

            public function callOnError(message:String):void {
                var s:String;
                if (ExternalInterface.available) {
                   var wrapperFunction:String = onError;
                   s = ExternalInterface.call(wrapperFunction, message);
                } else {
                   s = "Wrapper not available";
                }
            }

            private function netStatusHander(event:NetStatusEvent):void {
                switch(event.info.code) {
                    case 'NetConnection.Connect.Success':
                        stream = new NetStream(connection);
                        stream.attachCamera(camera);
                        stream.attachAudio(microphone);
                        h264Settings = new H264VideoStreamSettings();
                        h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_1_2);
                        h264Settings.setKeyFrameInterval(1);
                        stream.videoStreamSettings = h264Settings;
                        stream.bufferTimeMax = 30;
                        stream.bufferTime = 10;
                        break;
                }
            }

            private function init():void {
                isRecording = false;
                streamer = FlexGlobals.topLevelApplication.parameters.streamer;
                file = FlexGlobals.topLevelApplication.parameters.file;
                publishType = FlexGlobals.topLevelApplication.parameters.publishType;
                onStopRecord = FlexGlobals.topLevelApplication.parameters.onStopRecord;
                onError = FlexGlobals.topLevelApplication.parameters.onError;
                labelRecord = FlexGlobals.topLevelApplication.parameters.labelRecord;
                labelStop = FlexGlobals.topLevelApplication.parameters.labelStop;

                if (file == null) {
                    Alert.show('Missing flashvars: file');
                    return;
                }
                if (streamer == null) {
                    Alert.show('Missing flashvars: streamer');
                    return;
                }
                if (publishType == null) { publishType = 'record'; }
                if (labelRecord == null) { labelRecord = 'Record'; }
                if (labelStop == null) { labelStop = 'Stop'; }

                camera = Camera.getCamera();
                if (camera == null) {
                    callOnError("no camera");
                    return;
                }
                camera.addEventListener(StatusEvent.STATUS, camStatusHandler);
                camera.setMode(640, 480, 30);
                camera.setQuality(0, 90);

                microphone = Microphone.getMicrophone();
                microphone.encodeQuality = 9;
                microphone.rate = 44;
            //  microphone.framesPerPacket = 1;
                microphone.setSilenceLevel(0);

                connection = new NetConnection();
                connection.connect(streamer);
                connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHander);

                videoDisplay.attachCamera(camera);
            }

            private function camStatusHandler(event:StatusEvent):void {
                if (event.code == "Camera.Unmuted") {
                }
                if (event.code == "Camera.Muted") {
                    callOnError("camera denied");
                }
            }
        ]]>
    </fx:Script>
    <!-- TODO: Should we add layout? -->
    <mx:VideoDisplay width="100%" height="100%" id="videoDisplay"></mx:VideoDisplay>
</s:Application>

0 个答案:

没有答案