录制Flash网络摄像头FMS 4.5到Mp4会导致质量很差

时间:2014-10-12 14:54:59

标签: actionscript-3 flash h.264 flash-media-server webcam-capture

我已成功使用FMS 4.5开发人员版本将录像摄像头设置到FLV,因此我想尝试下一步录制到Mp4。我正在对视频文件进行静音保存,因为这里的目标是能够在Flash / FMS之外播放这些视频。我将程序设置为保存由FMS生成的Mp4文件,但质量很差。当捕获到移动时,我看到绿色失真,并且重度像素化。这是我的测试应用程序代码,用于在录制5秒后保存视频文件。任何人都可以指出我哪里出错了吗?非常感谢任何帮助。

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);
    }
}

}

2 个答案:

答案 0 :(得分:1)

好的,我正在回答我自己的问题。我在这里找到了答案以及要处理的工具的链接:adobe help site

您必须在使用后处理工具录制文件后转换文件,以便在其他视频播放器中查看这些文件。

编辑:VLC实际上可以播放未经处理的文件,所以我认为这首先是质量问题!

答案 1 :(得分:0)

您可以尝试更改视频流VideoStreamSettings.setQuality(bandwidth:int, quality:int)link)的质量。

您只需设置一个bandwidthquality值,并将另一个保留为0.我会尝试将带宽(以每秒字节数为单位)设置为750000 (6 Mbps),对于低于全高清的任何东西都应该足够了。

因此,在您的情况下,您可以尝试:

h264Settings.setQuality(750000, 0);