0 Replies Latest reply on Jul 24, 2012 5:58 PM by lsiunsuex

    Record from webcam to f4v on FMS

    lsiunsuex

      I'm trying to build / modify an application to record from webcam and microphone, in a web browser and save it to an FMS 5.4.2 server to stream via web and iOS

       

      recording as a flv file works fine and it plays back just fine in firefox / any browser

       

      I can steam f4v files over http as filename.f4v.m3u8 and that works fine with the samples that come with FMS from my record folder (/opt/adobe/fms/applications/record/streams/)

       

      My flash web application can record to the FMS server, the file it records has the .f4v file extension, has content (i see the file size), and has time in quicktime (4 or 5 seconds - just a test) but it doesn't play - the screen is black and never starts.

       

      I know i'm right on the edge of figuring this out, I just don't know what I'm missing or whats wrong (i'm a php programmer, not action script)

       

      any ideas ?

       

      here is the code i'm working with:

       

      package com

      {

          import fl.controls.ProgressBar;

          import fl.controls.ProgressBarMode;

          import flash.display.MovieClip;

          import flash.events.Event;

          import com.NetConnector

          import flash.events.MouseEvent;

          import flash.events.TimerEvent;

          import flash.media.Camera;

          import flash.media.Microphone;

          import flash.media.Video;

          import flash.net.navigateToURL;

          import flash.net.NetConnection;

          import flash.net.NetStream;

          import flash.net.URLLoader;

          import flash.net.URLLoaderDataFormat;

          import flash.net.URLRequest;

          import flash.net.URLRequestMethod;

          import flash.net.URLVariables;

          import flash.text.TextField;

          import flash.utils.setTimeout;

          import flash.utils.Timer;

          import flash.media.H264Level;

          import flash.media.H264Profile;

          import flash.media.H264VideoStreamSettings;

          import flash.media.VideoCodec;

       

          /**

           * ...

           * @author Alexander (flash2you) < >

           */

          public class Recorder extends MovieClip

          {

              private var dataHolder:DataHolder = DataHolder.getInstance()

       

              public var layer:MovieClip

              public var activityLevel_pb:ProgressBar

              public var aguja:MovieClip

              public var aguja2:MovieClip

              public var publishButton:MovieClip

              public var timer_txt:TextField

              public var recordStatus:MovieClip

              public var recordBtn:MovieClip

       

              private var netStream:NetStream

              private var microphone:Microphone = Microphone.getMicrophone()

              private var camera:Camera = Camera.getCamera()

              public var  video:Video

       

              private var timer:Timer = new Timer(100)

              private var clockTimer:Timer = new Timer(1000)

       

              public var published:Boolean = false

       

              private var isRecording:Boolean = false

       

              private var minutero = 0;

              private var crono = 0;

              private var records = 0;

       

       

              public var settings_mc:MovieClip

              public static var recorder:Recorder

              public var settings_icon:MovieClip

       

              private var limitTimer:Timer

              public function Recorder()

              {

                  Recorder.recorder = this;

       

                  timer.addEventListener(TimerEvent.TIMER, on$timer)

                  clockTimer.addEventListener(TimerEvent.TIMER, on$clockTimer)

                  //visible = false

       

       

                  recordBtn.buttonMode = true

                  recordBtn.addEventListener(MouseEvent.CLICK , recordBtn$click)

                  recordBtn.addEventListener(MouseEvent.MOUSE_OVER, recordBtn$over)

                  recordBtn.addEventListener(MouseEvent.MOUSE_OUT, recordBtn$out)

       

                  addEventListener(Event.ADDED_TO_STAGE, onAddedToStage)

       

       

                  limitTimer = new Timer(dataHolder.timelimit * 1000);

                  limitTimer.addEventListener(TimerEvent.TIMER, onLimitTimerHandler)

              }

       

              private function onLimitTimerHandler(e:TimerEvent):void

              {

                   stopPublish()

              }

              /*

               *  when we comes to second frame

               * */

              private function onAddedToStage(e:Event):void

              {

                  removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

       

                  init()

              }

              /*

               *   function for set up camera from settings module

               * */

              public function setCamera(_camera:Camera) {

                  camera = _camera

                  addCameraSettings()

                  video.width = 1280;

                  video.height = 720;

                  video.attachCamera(camera)

                 

                  if (netStream){

                      netStream.attachCamera(camera)

                  }

              }

       

              public function setMicrophone(mic:Microphone) {

                  microphone = mic;

       

                  if (netStream){

                      netStream.attachAudio(microphone)

                  }

       

                  addMicSettings()

              }

       

              private function addMicSettings() {

                  microphone.setUseEchoSuppression(true);

                  microphone.setSilenceLevel(1)

              }

       

              private function addCameraSettings():void

              {

                  camera.setMode(1280, 720, 25);

                     camera.setLoopback(true);

                     camera.setQuality(0, 100);

                 

              }

       

              public function init() {

                  startConnect()

              }

              /*

               *  main function for connection

               * */

              private function startConnect() {

                  visible = true

       

                  timer_txt.htmlText = "<b>00:00</b>";

       

                  initCamera()

                  initMicropone()

                  var nc:NetConnection = new NetConnection()

                  nc.connect(null)

                  netStream = new NetStream(nc)

                  netStream.attachAudio(microphone)

       

                  video.attachCamera(camera)

                  layer.visible = false

       

       

                  publishButton.gotoAndStop(1);

       

       

                  activityLevel_pb.mode = ProgressBarMode.MANUAL;

       

                  recordStatus.gotoAndStop("noRecord")

       

                  timer.start()

       

       

                  connection.addEventListener(NetConnector.CONNECTED, connectionComplete)

                  connection.startConnection()

              }

       

              public function get connection():NetConnector {

                  return dataHolder.connection

              }

       

              private function on$timer(e:TimerEvent) {

                  activityLevel_pb.setProgress(microphone.activityLevel, 100)

              }

              /*

               *  when connection to your stream server done

               * */

              private function connectionComplete(e:Event = null) {

                  netStream = new NetStream(connection)

                  netStream.attachAudio(microphone)

                  netStream.attachCamera(camera)

              }

       

              /*

               *   add 0 if less then 10secs

               * */

              private function addLeading(nbr) {

                  if (nbr<10) {

                      return ("0"+Math.floor(nbr));

                  } else {

                      return (Math.floor(nbr).toString());

                  }

              }

       

              /*

               *   update visible clock, rotate arrows

               * */

              private function updateTimer() {

                  timer_txt.htmlText = "<b>"+addLeading(crono/60)+":"+addLeading(crono%60)+"</b>";

                  aguja.rotation = aguja.rotation+6;

                  if (addLeading(crono/60)>minutero) {

                      aguja2.rotation = aguja2.rotation+6;

                      ++minutero;

                  }

                  // end if

                  ++crono;

              }

       

              private function on$clockTimer(e:TimerEvent):void

              {

                  updateTimer()

              }

              private function startClockTimer() {

                  clockTimer.start()

              }

       

              /*

               *  update graphics and start recording

               * */

              private function recordBtn$click(e:MouseEvent):void

              {

                  if (!isRecording) {

                      startRecording()

                      recordStatus.gotoAndStop("record")

                      recordBtn.visible = false

                  }

              }

       

              private function recordBtn$over(e:MouseEvent):void

              {

                  if (!isRecording) {

                      this.gotoAndPlay(65);

                  }

              }

              private function recordBtn$out(e:MouseEvent):void

              {

                  if (!isRecording) {

                      this.gotoAndPlay(61);

                  }

              }

       

              private function startRecording() {

                  if (connection.connected){

                     

                     

                      netStream.publish("mp4:" + dataHolder.filename + ".f4v", "record");

                     

                     

                  }

       

                  isRecording = true

                  startClockTimer()

       

                  publishButton.gotoAndPlay(2)

                  publishButton.buttonMode = true

                  publishButton.addEventListener(MouseEvent.CLICK, publishButton$click);

       

       

                  limitTimer.start()

              }

       

              /*

               *  redirect to finishURL that was passed via flashvars

               * */

              private function publishButton$click(e:MouseEvent):void

              {

                  stopPublish()

       

                  var request:URLRequest = new URLRequest(dataHolder.finishURL)

                  navigateToURL(request, "_self")

              }

       

              private function stopPublish():void

              {

                  netStream.close();

                  connection.close();

       

                  limitTimer.stop();

                  clockTimer.stop();

       

                  isRecording = false

       

                  recordStatus.gotoAndStop("recordEnd")

       

                  updateTimer();

              }

              /*

               *  init microphone

               * */

              private function initMicropone():void

              {

                  microphone = Microphone.getMicrophone()

                  addMicSettings()

              }

              /*

               *  init camera

               * */

              private function initCamera():void

              {

                  camera = Camera.getCamera()

                  addCameraSettings()

              }

          }

      }