24 tháng 6, 2009

I record a stream from Flash Media Encoder

How can I record a stream from Flash Media Encoder on Flash Media Server 2?

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.

0 Ý kiến:

Blog Hoc Tap :)) Blog Hoc Tap ;)) Blog Hoc Tap ;;) Blog Hoc Tap :D Blog Hoc Tap ;) Blog Hoc Tap :p Blog Hoc Tap :(( Blog Hoc Tap :( Blog Hoc Tap :X Blog Hoc Tap =(( Blog Hoc Tap :-o Blog Hoc Tap :-/ Blog Hoc Tap :-* Blog Hoc Tap 8-} Blog Hoc Tap :)] Blog Hoc Tap ~x( Blog Hoc Tap :-t Blog Hoc Tap b-( Blog Hoc Tap :-L Blog Hoc Tap x( Blog Hoc Tap =))

Đăng ý kiến của bạnBlog Hoc Tap

Đây là Web Blog dùng để "Ghi lại" trong quá trình làm việc và học tập. Bạn có thể đăng ý kiến để Đóng góp, Xây dựng, Trao đổi, Học tập với tôi. Cảm ơn bạn đã ghé qua web blog của tôi.
Bạn có thể sử dụng các biểu tượng cảm xúc trong bài "ý kiến" bằng cách gõ ký tự bên phải của mỗi biểu tượng.
Thân chàoBlog Hoc Tap

BlogWeb: tạo từ Blog của Google
Nội dung: lấy từ nhiều Nguồn khác nhau.
Mục đích: note lại bài Hướng dẫn hay và Đáng đọc.
Kết quả: nghiện Internet Nặng.
Tương lại: xuống lỗ Vẫn Nghiện nếu không có ai giúp.
Blog Web của: Trí Dũng đến từ Việt Nam - Liên kết đến trang Blog Cá Nhân
Tôi biết (^_^)
Thông tin về Tác giả. Chi Tiết
Sử dụng (FireFox | Google Chrome on Ubuntu) để xem tốt nhất. Học Nhiều Hơn Tại Đây
©2009 Google Blogger - HuuNguyen's Home