2

I have a videodisplay (spark) and camera.

     public var camera:Camera;
     ...
     livePreview.source = getDynamicStreamingVideoSource();
     camera.setMode(camWidth, camHeight, 15);
     livePreview.videoObject.attachCamera(camera);
     ...
     <s:VideoDisplay id="livePreview" ... />

On some situation, somewhere in my code, I tried to programmatically resize both by calling camera.setMode(newWidth, newHeight) and setting livePreview.width = newWidth, livePreview.height = newHeight. This doesnt work well from what I've seen. livePreview resizes to the new width and height BUT not the camera, at least partially. for example, the orig size is 250, 250 and if i set 500 (W) and 250 (H) as the new size, the camera video will appear squished horizontally but the physical width stays at 250. now here is the catch, if i set livePreview.scaleMode to "stretch", the camera video will display the video exactly the way i want it to (undistorted, correct size, ratio intact).

Now unto my real problem: this doesn't work well performance-wise. the "stretch" really shows you it is stretching the video, taking at least a second to do it. too slow. i want it to work instantaneously w/o any effect. i also don't understand why does it need to be stretched when I'm specifying the correct width and same as the videoDisplay width. am I missing here?

StephenNYC
  • 1,234
  • 3
  • 12
  • 29
  • I don't understand. Why are you capturing the camera (which is 4:3 or 16:9 etc) and trying to make it display at a 1:1 or 2:1 ratio? – Jason Reeves Nov 03 '12 at 22:48
  • Well I'm doing it because it was letting me :P if I specify a square region into setMode(), it displays a square. anyway ive thought about it, I think im just gonna cheat to get the desired result. – StephenNYC Nov 06 '12 at 13:46
  • Just an update: My workaround for this is not to resize the video at all but "cut" portions out of the captured image and also masking the portions thats not supposed to be part of the sliced bitmap. – StephenNYC Feb 22 '13 at 23:17

1 Answers1

0

I stumbled across something in the book ActionScript 3.0 Cookbook (recipe 16.6, pg 398-399). I won't quote much directly, to respect copyright, but here's a summary. I hope it is what you're looking for:

I don't know if you actually created a Video object (or if you can), but the book says that the dimensions at which a video plays back depend on the width and height properties of the Video object.

var video:Video = new Video(160, 120);
//Now we change the dimensions of the video to scale it up to twice the size.
video.width = 320;
video.height = 240;

Though I don't have any direct experience working with Camera objects, I would imagine that if you were to create a Video object from the Camera object (I don't even know how to do that, or if you can...another question, perhaps,) then you could directly adjust the dimensions of the video.

What it sounds like is going on right now is that the video display object is trying to show a higher resolution than is available, thus, it is pixelating the video. It would be like trying to display a postage stamp-sized video full screen on a tablet computer...there isn't enough actual pixel data there, so the pixels themselves are enlarged.

You would have to find a way to directly resize the video itself, not just the videoDisplay container.

I don't know if this helps, especially since I'm no video expert, but maybe this'll give you some ideas...?

EDIT: I found how to get the video from the camera (from another SO Question!), so here is my full recommended code for scaling up the video:

var camera:Camera = Camera.getCamera();
//You'll want to set the camera's quality and mode.

//Get video from camera.
var video:Video = new Video(160,120);
video.attachCamera(camera);

//Size up video to 320x240.
video.width = 320;
video.height = 240;

//Now, connect the video to the LivePreview object, 
//instead of connecting the camera and the preview directly.

One last recommendation...try getting the input from the camera at the highest resolution you will want and scale DOWN, not up. That'll preserve quality.

The code is untested, so it'll probably need tweaking. All the same, I hope this gets you started on solving your problem!

Community
  • 1
  • 1
CodeMouse92
  • 6,840
  • 14
  • 73
  • 130