I record a stream from Flash Media Encoder
I actually get a lot of questions concerning FME but since I don't use it much myself (it crashes on my main computer and won't start) I usually don't have much of an answer. This also tells me two things about this piece of software that Adobe has pushed out, that is that it's getting attention because it encodes video with on2's vp6 codec and people like that because the quality is better. The second is that if I'm getting so many questions, there must be a lack of docs out there. Oh well, gives me something to write I guess.
Anyways, the deal here is that a lot of people want to record on FMS2 instead of just saving the FLV locally and then uploading some huge honking file to their server.
The way to do that is actually relatively simple. Surprisingly enough.
In this case we need to have the server side of the application watch for when a certain stream is published. The only drawback with this is that we have to actually hard code in the stream name on the server side. I suppose that isn't so bad though.
First up is writing the server side code. We have to get the stream that we want to record to. This can be anything really, for the time being I'll just call it "recordvid". Notice it's all in lower case, this is a best practice in the case that you ever have to move to a unix server from windows because unix servers are case sensitive and it's easy to not play the file based on incorrect case.
So we start the application as so:
application.onAppStart = function(){
//get the stream to record to here
this.recordStream = Stream.get("recordvid");
//keep an eye on the status of the stream, we'll need this to see what's happening with the stream
this.recordStream.onStatus = function(info){
for(var i in info){
trace("i: " + i + " info[i] " + info[i]);
}
}
this.recordStream.play("vid", -1, -1);
this.recordingStream = false;
}
That's it for now. Now just publish a stream from FME that is called "vid". It should show you the following in the FMS2 admin panel:
i: level info[i] status
i: code info[i] NetStream.Play.PublishNotify
i: description info[i] vid is now published.
i: details info[i]
As you can see, you can capture the event of when the video file is being published. From this point, you just call the record function:
application.recordStream.record();
When you stop publishing to the server, you'll get this trace of the information object:
: level info[i] status
i: code info[i] NetStream.Play.UnpublishNotify
i: description info[i] vid is now unpublished.
i: details info[i]
So you can see when you should stop recording. Which is done like this:
application.recordStream.record(false);
That's about it.
Nhận xét
Đăng nhận xét