Skip to main content
Participant
June 20, 2011
Answered

[FMS4] record stream app generate 1kb flv

  • June 20, 2011
  • 1 reply
  • 882 views

hi all,

i've done an as3 application that record a video stream (webcam) with fms4. The problem is that the files generated have a weight of only 1kb.

where's the problem? i need help..

package {
       
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.display.BitmapData;
        import flash.display.Bitmap;
        import flash.text.TextField;
        import flash.media.Camera;
        import flash.media.Video;
        import flash.events.*;
        import flash.net.NetConnection;
        import flash.net.NetStream;
       
        public class Webcam extends Sprite {
               
                private var cam:Camera;
                private var video:Video;
                private var label:TextField;
                private var camFPS:Number=25;
                private var camW:Number  = 640;
                private var camH:Number  = 350;
                private var bandwidth:int = 0;
                private var quality:int = 80;
                private var nc:NetConnection = new NetConnection();
                private var videoStream:NetStream;  
                private var info:Object;        
               
                private var booRec:Boolean = false;
               
                public function Webcam():void {
                       
                        cam = Camera.getCamera();
                        cam.setMode(camW, camH, camFPS, true);                       
                        cam.setQuality(bandwidth, quality);
                        cam.setMotionLevel(10, 500);
                       
                        if (cam == null) {
                            label = new TextField();
                            label.text = "NO WEBCAM FOUND";
                            addChild(label);
                        } else {
                            video = new Video(camW, camH);
                            vcLocal.attachCamera(cam);
                            nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
                            nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
                            nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
                            nc.client = this;
                            nc.connect("rtmp://demo.flashmediaserver.it/video");
                            rec.addEventListener(MouseEvent.MOUSE_DOWN, goStream);
                        }
                }
               
                private function goStream(e:MouseEvent):void { 
                    if(!booRec){
                        recVideo();
                        rec.gotoAndStop(2);
                    } else {
                        stopRec();
                        rec.gotoAndStop(1);
                    }
                    booRec = !booRec;
                    function recVideo(){
                        trace("rec");
                        videoStream = new NetStream(nc);   
                        video.attachNetStream(videoStream);                          
                        videoStream.publish("2", "record");
                        //addChild(video);
                    }
                    function stopRec():void {
                        videoStream.close();
                    }
                }
               
                               
                // Switch Net Status Events
                public function netStatus(event:NetStatusEvent):void {
                    info = event.info;
                    switch (info.code) {
                        case "NetConnection.Connect.Success":
                            trace("CONNECTION SUCCES");
                            //goStream();
                            break;
                        case "NetConnection.Connect.Failed":
                            trace("CONNECTION FAILED");
                            break;
                        case "NetConnection.Connect.Rejected":
                            trace("CONNECTION REJECTED");
                            break;
                        case "NetConnection.Connect.Closed":
                            trace("CLOSED");
                            break;
                        case "NetStream.Play.Start":
                            trace ("START");
                            break;
                        default:
                            trace("Some Error @#$%!!!");
                        }
       
                }
               
                private function netSecurityError(event:SecurityErrorEvent):void {
                    trace("netSecurityError: " + event);
                }
               
                private function onAsyncError(event:AsyncErrorEvent):void {
                    trace("onAsyncError: " + event);
                }           
               
                public function onBWDone():void {
                    // Catch onBWdone errors
                }
               
               
               
        }
}

thanks in advance

Fabio

    This topic has been closed for replies.
    Correct answer

    Looks like you haven't attached any sources to the stream you're publishing to. You'd need to attach a mic or cam to start sending audio or video data.

    1 reply

    Correct answer
    June 20, 2011

    Looks like you haven't attached any sources to the stream you're publishing to. You'd need to attach a mic or cam to start sending audio or video data.

    dofooooAuthor
    Participant
    June 20, 2011

    thank u!

    the code become:

    function recVideo(){
                            trace("rec");
                            videoStream = new NetStream(nc);   
                            video.attachNetStream(videoStream);    
                            videoStream.attachCamera(cam);
                            microphone = Microphone.getMicrophone();
                            videoStream.attachAudio(microphone);
                            videoStream.publish("2", "record");
                            //addChild(video);
                        }