I'm building a very simple publisher for the webcam in Flash. I want to select a camera and send the stream to a RTMP URL, basically:
Camera camera = Camera.getCamera();
NetStream ns = new NetStream(connection);
ns.attachCamera(camera);
ns.publish("stream name");
Now, I know I can set a mode on the camera, like this:
camera.setMode(320, 240, 25);
But what I really would like to do is to set a mode such as 360 x 480 (not the same aspect ratio as the camera is recording) and have Flash crop the image for me. Is there a way to do that?
Edit: I know Flash Media Live Encoder can do this, but I would like to do it in the browser.
According to the ActionScript docs for Camera.setMode, there is an optional fourth parameter that sounds interesting, favorArea
. From the docs:
favorArea:
Boolean
(default =true
) — Specifies whether to manipulate the width, height, and frame rate if the camera does not have a native mode that meets the specified requirements. The default value istrue
, which means that maintaining capture size is favored; using this parameter selects the mode that most closely matcheswidth
andheight
values, even if doing so adversely affects performance by reducing the frame rate. To maximize frame rate at the expense of camera height and width, passfalse
for thefavorArea
parameter.
But it defaults to true and it doesn't seem to make what I want (I want to crop the image of each frame, throw away some data, and stream the rest).
From what I can see, you cannot.
To crop or otherwise transform, you need to get raw video. Presence of Camera.setKeyInterval, Camera.setQuality with bandwidth parameter and a read-only NetStream.videoSetting that is null until a camera is connected suggests that all the compression is handled by Camera object internally while NetStream only transfers it as-is. Similarly, Adobe Flash Platform - Working with video has no word about either transformations or compressing/decompressing video streams as data (flash.media.VideoCodec is a mere enumeration).
Unlike this, Media Live Encoder does just that: decode the stream from camera (which needs to be in one of supported formats), optionally transform and then re-encode it.
And finally, I see browser as somewhat misplaced a location for a full-featured streaming server! It's a job for a daemon!