actionscript-3flashh.264flash-media-serverwebcam-capture

Recording Flash Webcam FMS 4.5 to Mp4 results in terrible quality


I have successfully setup recording webcam to FLV using FMS 4.5 developer edition, so I wanted to attempt recording to an Mp4 next. I am doing a silent save of the video file because the goal here is to be able to have these videos playable outside of Flash/FMS. I set the program up to save the Mp4 file generated by FMS, but the quality is terrible. I am seeing green distortion when movement is captured, and heavy pixelation. Here is my test application code that saves the video file after 5 seconds of recording. Can anyone please point out where I am going wrong? Any help is greatly appreciated.

package com 
{
import flash.display.*;
import flash.net.*;
import flash.utils.Timer;
import flash.events.*;
import flash.filesystem.File;
import flash.media.*;

public class Main extends MovieClip 
{
    private var nc:NetConnection;
    private var ns:NetStream;
    private var nsPlayer:NetStream;
    private var vid:Video;
    private var vidPlayer:Video;
    private var cam:Camera;
    private var mic:Microphone;

    private static const LOCAL_VIDEO:String = "myCamera";
    private static const VIDEO_FPS:uint = 30;
    private static const SAVE_FOLDER_NAME:String = "Saved_Videos";
    private static const PATH_TO_FMS:String = "C:/Program Files/Adobe/Flash Media Server 4.5";

    private var timer:Timer = new Timer(5000, 1);

    public function Main()
    {
        addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(evt:Event):void
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        nc = new NetConnection(); 
        nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); 
        nc.connect("rtmp://localhost/PublishLive/myCamera");
    }

    function onNetStatus(evt:NetStatusEvent):void
    {
        if(evt.info.code == "NetConnection.Connect.Success")
        { 
            publishCamera(); 
            displayPublishingVideo();

            timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleted);
            timer.start();
        } 
    }

    private function timerCompleted(evt:TimerEvent) 
    { 
        trace("timer completed");           

        timer.stop();

        ns.close();
        ns = null;

        var saveFile:File = new File(PATH_TO_FMS + "/applications/PublishLive/streams/" + LOCAL_VIDEO + "/" + LOCAL_VIDEO + ".mp4");
        var fileName:String = "Video" + ".mp4";

        var dir:File = File.documentsDirectory.resolvePath(SAVE_FOLDER_NAME);
        dir.createDirectory();

        var fileToSave = dir.resolvePath(fileName);

        if(fileToSave.exists)
        {
            fileToSave.deleteFile();
        }

        saveFile.copyTo(fileToSave, true);
    }

    private function publishCamera() 
    {
        var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings();
        h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_3_1);

        cam = Camera.getCamera(); 
        cam.setMode(stage.stageWidth, stage.stageHeight, VIDEO_FPS, true);
        cam.setQuality(0, 90);
        cam.setKeyFrameInterval(15);
        cam.setMotionLevel(100);

        mic = Microphone.getMicrophone(); 
        mic.setSilenceLevel(0);
        mic.rate = 11;

        ns = new NetStream(nc);     
        ns.videoStreamSettings = h264Settings;          
        ns.attachCamera(cam); 
        ns.attachAudio(mic);
        ns.publish("mp4:myCamera.mp4", "record"); 
    }

    private function displayPublishingVideo():void 
    { 
        vid = new Video();
        vid.width = stage.stageWidth;
        vid.height = stage.stageHeight;
        vid.attachCamera(cam); 
        addChild(vid);
    }
}

}


Solution

  • Ok, so I am answering my own question. I found the answer here along with the link to the tool to process: adobe help site

    You must convert the files after recording them using a post-processing tool so they can be viewed in other video players.

    Edit: VLC can actually play the unprocessed file, so I thought it was a quality issue at first!