How to record on Adobe Media Server~
I use Adobe Flash Media Server. I would like to use it to record video stream pushed me, and looked at the statistics may need to change the Adobe Flash Media Server inside the main.asc file, I tried to change some, but did not succeed, I need your help, thanks.
This is my code:
-----------------------------------------------------------------------------------------
application.onPublish = function(clientObj, streamObj)
{
// a race can happen during republish. if onPublish is called
// before onUnpublish, we need to wait for onUnpublish to
// complete before calling onPublish for the new stream.
if (streamObj.publishing == true)
{
// onUnpublish has not been called yet
//trace("Unpublish pending...");
streamObj.publishingClient = clientObj; // save and call onPublish later
return;
}
streamObj.publishing = true;
trace("onPublish : " + streamObj.name);
var queryString = streamObj.publishQueryString;
var liveEventName = streamObj.name;
var audioStreamSrc = "";
var audioStreamName = "";
var videoStreamSrc = "";
var videoStreamName = "";
var recordMode = "append";
//trace("queryString["+queryString+"] stream["+streamObj.name+"]");
if (queryString == undefined || (queryString.localeCompare("") == 0)) {
/* Did not find query string so use the streamname as the event id */
trace("Query string not specified. Using StreamName["
+streamObj.name+"] as eventname");
} else {
/* Looking for name value pair adbe-live-event in the query string. If specified, use event name based on it. Otherwise, it is a single stream so you don't need to configure Event.xml and Manifest.xml */
var nvpairs = new LoadVars();
nvpairs.decode(queryString);
for (var nv in nvpairs) {
var nval = nvpairs[nv];
/*trace("nv["+nv+"]=val["+nval+"]");*/
if (nv.localeCompare("adbe-live-event")==0) {
liveEventName = nval;
/*trace("live event set to["+liveEventName+"]");*/
}
else if (nv.localeCompare("adbe-audio-stream-src") == 0)
{
audioStreamSrc = nval;
}
else if (nv.localeCompare("adbe-audio-stream-name") == 0)
{
audioStreamName = nval;
}
else if (nv.localeCompare("adbe-video-stream-src") == 0)
{
videoStreamSrc = nval;
}
else if (nv.localeCompare("adbe-video-stream-name") == 0)
{
videoStreamName = nval;
}
else if (nv.localeCompare("adbe-record-mode") == 0)
{
recordMode = nval;
}
}
}
var s = Stream.get("f4f:" + streamObj.name);
if (s == undefined )
return;
if ((s.liveEvent != undefined)&&(s.liveEvent != "")&&(s.liveEvent != liveEventName)) {
trace("Rejecting publish from client: "+clientObj.ip +" as stream: "+streamObj.name+
" is already assigned to event: ["+s.liveEvent +"]");
application.disconnect(clientObj);
return;
}
s.onStatus = function(info)
{
this.trace(info.code);
}
s.liveEvent = liveEventName;
trace("Stream name is: " + streamObj.name + " and live event is: "+s.liveEvent);
s.play(streamObj.name,-1,-1);
if (!s.record(recordMode))
{
s.trace("record failed.");
}
application.s[streamObj.name] = s;
// check if audio only stream is desired
if (audioStreamName != "")
{
// if no stream src specified, use this stream
if (audioStreamSrc == "")
{
audioStreamSrc = streamObj.name;
}
if (audioStreamSrc == streamObj.name)
{
//trace("Creating audio only stream " + audioStreamName + " from " + audioStreamSrc);
var a = Stream.get("f4f:" + audioStreamName);
a.onStatus = function(info)
{
this.trace(info.code);
}
a.receiveAudio = true;
a.receiveVideo = false;
a.liveEvent = liveEventName;
a.play(audioStreamSrc, -1, -1);
if (!a.record(recordMode))
{
a.trace("record failed.");
}
application.a[streamObj.name] = a;
}
}
// check if video only stream is desired
if (videoStreamName != "")
{
// if no stream src specified, use this stream
if (videoStreamSrc == "")
{
videoStreamSrc = streamObj.name;
}
if (videoStreamSrc == streamObj.name)
{
//trace("Creating video only stream " + videoStreamName + " from " + videoStreamSrc);
var v = Stream.get("f4f:" + videoStreamName);
v.onStatus = function(info)
{
this.trace(info.code);
}
v.receiveAudio = false;
v.receiveVideo = true;
v.liveEvent = liveEventName;
v.play(videoStreamSrc, -1, -1);
if (!v.record(recordMode))
{
v.trace("record failed.");
}
application.v[streamObj.name] = v;
}
}
}
