AS3: Is it possible to capture stage elements or bitmap data into a netstream?

大城市里の小女人 提交于 2019-12-23 17:27:28

问题


I'm looking at the netstream documentation. but can't really glean if appendBytes() can really take arbitrary data. Could I really just take arbitrary bitmap data (as a byte array) and append the frame to stream (presumably before sending it to a FMS to save a file)? I think I am wrong: it's only useful for dynamic streaming. I know that it is possible to grab a webcam feed and directly encode video via FMS. But say I wanted to add some overlays before encoding, is that even possible in Flash? I.e. Can you dynamically generate netStream objects in Flash, or is the only thing you can do is draw bitmap data from a netStream and not vice-versa?

Basically the goal is to manipulate video and audio much like Movie Masher and save out actual video files directly. Movie Masher actually saves out single frames to the server for later conversion.

I've heard that FP11 has native H264 Encoding-- so the'spec' question: Could the final netStream be encoded in-browser then uploaded to the server over HTTP, or is FMS still a requirement? I'm looking at this realtime encoder demo, but I'm not sure if they're just using FMS as a filedump, or if it's part of the process.

There's an open source project for encoding FLV, it uses ByteArrayFlvEncoder which allows you to encode raw ByteArrays. Is there an equivalent for H264?


回答1:


According to the documentation, it does not seem possible to use the native encoder because you cannot leverage both NetStream.publish() and NetStream.appendBytes() at the same time :

A NetStream can either publish a stream or play a stream, it cannot do both. To publish a stream and view the playback from the server, create two NetStream objects.

In other words, it seems like there is no way to send custom data to FMS over a NetStream object.

So, you could :

  1. Attach the camera to a Video object
  2. Apply a series of effects to it w/ pixel manipulation
  3. Send the pixel data for later encoding to a server over a socket, or use the AS3 encoder you mentioned to save a baked FLV as a file (on the user's computer or on the server)



回答2:


appendBytes on the NetStream class used in conjunction with the NetStreamAppendBytesAction class.

Sample code : Ref demo : http://www.bytearray.org/?p=1689

// retrieve the FLV stream
var bytes:ByteArray = event.currentTarget.data;
// put the NetStream class into Data Generation mode
netstream.play(null);
// before appending new bytes, reset the position to the beginning
netstream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
// append the FLV video bytes
netstream.appendBytes(bytes);


来源:https://stackoverflow.com/questions/12326337/as3-is-it-possible-to-capture-stage-elements-or-bitmap-data-into-a-netstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!