我正在尝试制作一个让用户录制视频消息的网络应用程序。我正在努力获得最好的质量(即使这意味着很长的上传时间)。我设法让录音与ns.publish("livestream", "live");
服务器代码看起来像这样:
Client.prototype.startRecord = function( source, destination ) {
trace("recording Stream: " + source + " to: " + destination);
this.newStream = Stream.get(destination);
this.fileRecording = destination;
trace(this.fileRecording);
if (this.newStream)
{
this.newStream.onStatus = function (info) {
//trace(info.code );
if (info.code == "NetStream.Play.PublishNotify") {
trace("start recording");
this.record();
}
}
this.newStream.play(source)
}
}
Client.prototype.stopRecord = function() {
trace("stopping Recording");
this.newStream.record(false);
this.newStream.play(false);
}
Client.prototype.getFiles = function() {
var fileRecord = new File("/streams/_definst_/"+this.fileRecording+".flv");
if (fileRecord.exists)
{
return this.fileRecording;
}
return "error recording";
}
application.onConnect = function(clObj) {
this.acceptConnection(clObj);
}
问题是质量不是很好。我尝试使用ns.publish("livestream", "record");
,但它在服务器上制作了 2 个文件并且质量没有提高,有什么建议吗?如果您需要,我也可以上传客户端代码。
客户端代码:
import flash.media.*;
import flash.events.*;
import flash.net.*;
import flash.utils.getTimer;
var vid:Video;
var mic:Microphone;
var cam:Camera;
var fileListObj:Object = {};
var ns:NetStream;
var nc:NetConnection;
var recordingName:String;
initCamera();
function initCamera ():void
{
if (Camera.isSupported)
{
cam = Camera.getCamera();
cam.setMode (800, 480, 24);
//cam.setQuality(0, 90);
vid = new Video(cam.width,cam.height);
vid.attachCamera (cam);
if (Microphone.isSupported)
{
mic = Microphone.getEnhancedMicrophone();
}
this.addChildAt (vid, 1);
vid.x = (800 - vid.width) >> 1;
vid.y = (480 - vid.height) >> 1;
initConnection();
}
else
{
trace ("no camera");
}
}
function initConnection ():void
{
nc = new NetConnection();
nc.addEventListener (NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener (AsyncErrorEvent.ASYNC_ERROR, function (event:AsyncErrorEvent):void {trace("error");});
nc.connect ("rtmp://adrian7.srfms.com/nabCapture");
}
function recordVideo (event:MouseEvent):void
{
if (record_mc.label == "Record")
{
record_mc.label = "Stop Record";
var currentTime:Date = new Date();
recordingName = "myRecording"+getTimer()+""+currentTime.time;
nc.call ("startRecord", new Responder(startPublish), "livestream", recordingName);
}
else
{
record_mc.enabled = false;
record_mc.label = "Record";
nc.call ("stopRecord", null);
ns.close();
nc.call ("getFiles", new Responder(onResultFileListObj, null));
}
}
function startPublish (result:Object):void
{
ns.publish("livestream", "live");
}
function netStatusHandler (event:NetStatusEvent):void
{
//trace (event.info.code);
if (event.info.code == "NetConnection.Connect.Success")
{
ns = new NetStream(nc);
ns.attachCamera (cam);
if (mic)
{
ns.attachAudio(mic);
}
record_mc.enabled = true;
record_mc.addEventListener (MouseEvent.CLICK, recordVideo);
}
}
function onResultFileListObj (resultObj:Object):void
{
if (String(resultObj) != "error recording")
{
recordingName = String(resultObj);
see_mc.enabled = true;
see_mc.addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.labs.adrian281990.com/fms_demo1/index.php?id=" + recordingName), "_self");
});
}
}