Flash Actionscript 3 getCamera bizarre discrepancies and artefacts on video - actionscript-3

We're using the Actionscript getCamera() API to access and stream the camera over RTMP. I'm not sure if anyone's come across this but depending on the browser we get some really strange effects on the camera input. In some cases the camera shows stretched and often in Firefox is shows central with a green bar on the right.
Is is possible to access the camera as cropped 16:9 on all browsers?
var videoWidth:Number = 427;
var videoHeight:Number = 240;
camera = Camera.getCamera();
// here are all the quality and performance settings
if (camera != null)
{
camera.setMode(videoWidth, videoHeight, videoFrameRate, false); // false gives framerate priority apparently?? http://www.flash-communications.net/technotes/setMode/index.html
camera.setQuality(videoBitrate, videoQuality);
camera.setKeyFrameInterval(2);
}
else
{
sourceVideoLabel.text = "No Camera Found\n";
}
In Chrome:
In Firefox:

Related

How to Improve FLVPlayback - Reduce Choppy Video

I have a 1920x1080 video playing inside a flash project with the same dimensions, using Firefox. The project is using CC2015, Latest Flash Player, Latest FF. I should note that this project is using locally stored videos.
I'm using AS3, FLVPlayback component, and the videos have been compressed (by production).
Heres the code that uses the playback component
function playVideoByString(source: String): void {
hideTheButtons();
attractTimer.stop();
movie_container = new MovieClip();
addChild(movie_container);
movie_container.x = 0;
movie_container.y = 0;
launchVideo(movie_container, source);
}
function launchVideo(vBox, vFile): void {
attractTimer.stop();
flvPlayer = new FLVPlayback();
flvPlayer.source = vFile;
flvPlayer.skinAutoHide = true;
flvPlayer.skinBackgroundColor = 0x000000;
flvPlayer.width = 1920;
flvPlayer.height = 1080;
flvPlayer.autoRewind = false;
cuePt.time = 0.9;
cuePt.name = "ASpt1";
cuePt.type = "actionscript";
flvPlayer.addASCuePoint(cuePt);
vBox.addChild(flvPlayer);
// adding listeners in here
flvPlayer.addEventListener(MetadataEvent.CUE_POINT, cp_listener);
flvPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, completeHandler);
}
Playback is experiencing some degradation in the form of what looks like frames dropping, or "stutter." The animations look glass smooth when the MP4 is opened in Firefox and played back using FFs player. They also look fine when played in QuickTime (obviously). The video is 30FPS, as is the Flash Project, though from what I understand, FLVPlayback will use the videos encoded frame rate regardless of Flash's FPS.
Is there anything I can do to improve the video playback, and possibly smooth the videos out without loosing quality?

Unable to free my webcam in Actionscript 3.0

To free my webcam I'm using
onScrenVideo.attachCamera(null)
where onScreenVideo is a Video object.
However, this just doesn't seem to work. Even after this line executes, the webcam light remains ON.
I have scoured the Internet for a solution to this problem and everyone seems to be unanimous that this is the only way to turn the webcam off (for example : Close webcam usage via actionscript), however, this just doesn't seem to be working for me.
Can anyone help?
Thanks
Edit: Adding relevant code.
All the variables are declared previously. Here's the code to set up the Camera and attach it to the video.
testCurrCam = Camera.getCamera();
onScreenVideo = new Video(240, 180);
onScreenVideo.smoothing = true;
onScreenVideo.x = 0;
onScreenVideo.y = 0;
addChild(onScreenVideo);
testCurrCam.setQuality(0, 70);
testCurrCam.setMode(640, 480, 10);
onScreenVideo.attachCamera(testCurrCam);
And here's a function which is called by Javascript using ExternalInterface. The call works perfectly fine, because I've checked using an alert box after the if condition.
private function stopCam(): void {
if (contains(onScreenVideo)) {
onScreenVideo.attachCamera(null);
this.removeChild(onScreenVideo);
onScreenVideo = null;
testCurrCam = null;
} else
return;
}

Programmatically zooming the AudioVideoCaptureDevice?

Anybody know how to programmatically zoom the AudioVideoCaptureDevice in Windows Phone 8?
I am using AudioVideoCaptureDevice (and yes, I want that specific device so I can control the VideoTorchMode property). I can't for the life of me figure out the zooming though. I am painting a Canvas using a VideoBrush mapped to the AudioVideoCaptureDevice. I'd like to implement Pinch-Zoom or even a simple +/- button to Zoom the camera.
What am I missing?
I'm not familiar with any API in WP8 that would allow you to programmetically set the zoom on a PhotoCaptureDevice/AudioVideoCaptureDevice. My theory is that you can do it manually by implementing your own Pinch-to-zoom functionality and making sure that region is focused.
For information on how to Focus on a region using WP8 Camera APIs see Nokia's Camera Explorer. The core of what you're looking for can be found on this architectural guide under "tap-to-focus".
private async void videoCanvas_Tap(object sender, GestureEventArgs e)
{
System.Windows.Point uiTapPoint = e.GetPosition(VideoCanvas);
if (_focusSemaphore.WaitOne(0))
{
// Get tap coordinates as a foundation point
Windows.Foundation.Point tapPoint = new Windows.Foundation.Point(uiTapPoint.X, uiTapPoint.Y);
double xRatio = VideoCanvas.ActualWidth / _dataContext.Device.PreviewResolution.Width;
double yRatio = VideoCanvas.ActualHeight / _dataContext.Device.PreviewResolution.Height;
// adjust to center focus on the tap point
Windows.Foundation.Point displayOrigin = new Windows.Foundation.Point(
tapPoint.X - _focusRegionSize.Width / 2,
tapPoint.Y - _focusRegionSize.Height / 2);
// adjust for resolution difference between preview image and the canvas
Windows.Foundation.Point viewFinderOrigin = new Windows.Foundation.Point(displayOrigin.X / xRatio, displayOrigin.Y / yRatio);
Windows.Foundation.Rect focusrect = new Windows.Foundation.Rect(viewFinderOrigin, _focusRegionSize);
// clip to preview resolution
Windows.Foundation.Rect viewPortRect = new Windows.Foundation.Rect(0, 0, _dataContext.Device.PreviewResolution.Width, _dataContext.Device.PreviewResolution.Height);
focusrect.Intersect(viewPortRect);
_dataContext.Device.FocusRegion = focusrect;
// show a focus indicator
FocusIndicator.SetValue(Shape.StrokeProperty, _notFocusedBrush);
FocusIndicator.SetValue(Canvas.LeftProperty, uiTapPoint.X - _focusRegionSize.Width / 2);
FocusIndicator.SetValue(Canvas.TopProperty, uiTapPoint.Y - _focusRegionSize.Height / 2);
FocusIndicator.SetValue(Canvas.VisibilityProperty, Visibility.Visible);
CameraFocusStatus status = await _dataContext.Device.FocusAsync();
if (status == CameraFocusStatus.Locked)
{
FocusIndicator.SetValue(Shape.StrokeProperty, _focusedBrush);
_manuallyFocused = true;
_dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters,
AutoFocusParameters.Exposure & AutoFocusParameters.Focus & AutoFocusParameters.WhiteBalance);
}
else
{
_manuallyFocused = false;
_dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None);
}
_focusSemaphore.Release();
}
}
Here's how to implement your own pinch-to-zoom functionality in WP8 # Pinch To Zoom functionality in windows phone 8
One thing I'd add to the pinch-to-zoom code sample in your case is a Clip specification on a parent control to make sure you're not accidentally rendering images tens or hundreds of times bigger then the screen and killing your app's performance.

AS3 FLVPlayback occasionally stuck in buffering on launch

I've got a Flash CS6 FLA with an instance of the FLVPlayback component (2.5.0.26) and an instance of the Progress Bar component on the stage, loading an external FLV.
I'm trying to preload a specific percentage of video before playing.
When hosted on a server, the video launches and plays as expected 80% of the time, but 20% of the time the video gets stuck in a buffering state on launch (blank area where video should be), and I can't get it to play through AS3 or by clicking the play button on the skin controls. Oddly, if I refresh the browser when it's stuck I see a glimpse of the video before the page reloads and then plays the video as expected.
I've tested on a Mac (Lion) in Chrome, Firefox, and Safari and had the same results.
The video problem gets worse if I limit my bandwidth using SpeedLimit.
Any suggestions would be greatly appreciated.
Code:
public class SimpleVideoLoad extends MovieClip {
var isLoaded:Boolean = false;
public function SimpleVideoLoad() {
// constructor code
loadVideo();
}
function loadVideo():void
{
my_FLVPlybk.x = 0;
my_FLVPlybk.y = 0;
my_FLVPlybk.width = 743;
my_FLVPlybk.height = 300;
my_FLVPlybk.source = "CARSdotCOM_OLD.flv";
//preloader component
pb.source = my_FLVPlybk;
pb.addEventListener(ProgressEvent.PROGRESS, progressHandlerPB);
}
//progress bar component
function progressHandlerPB(event:ProgressEvent):void {
var percentOfVideoLoaded = pb.percentComplete;
if (percentOfVideoLoaded>10 && isLoaded == false){
isLoaded = true;
my_FLVPlybk.play();
}
}
}

How to loop FLV seamlessly

I am playing looped FLVs in the "standard way":
netstream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
...
public function onStatus(item:Object):void {
if (item.info.code == "NetStream.Play.Stop") {
if (loop) netstream.seek(0);
}
When played through Flash CS 5.5 authoring tool (Test Movie or Debug Movie), the videos loop seamlessly. But! When played in the browser or standalone debug Flash player (both v.11.2.202.233) there is an abnormal pause of about 1 sec before the video "rewinds".
Is this a bug with the latest Flash player?
For People who have the same issue, try changing the aforementioned code to this:
public function onStatus(item:Object):void {
if (item.info.code == "NetStream.Buffer.Empty") {
if (loop) netstream.seek(0);
}
It will get rid of the flicker. If you listen to "NetStream.Play.Stop", it will cause a flicker.
You don't need to embed anything. This works just fine on IOS, Android and PC.
This is a known bug with Flash Player 11+ and AIR 3+. Bug report is here, and you should upvote & : https://bugbase.adobe.com/index.cfm?event=bug&id=3349340
Known workarounds that will create a seamless loop:
1) Embed the video in the SWF. Not ideal, and not possible in some cases.
2) Create dual NetSteam objects and switch between them. An example of the event fired when ns1, the first of two NetStreams objects, reaches it's end:
if (e.info.code == "NetStream.Play.Stop"){
vid.attachNetStream(ns2);
ns2.resume();
activeNs = ns2;
ns1.seek(0);
ns1.pause();
}
Replace ns1 with ns2 on the other event listener. A useless duplication of objects and handlers, but there you go.
3) Use AIR 2.x / Flash Player 10.x (not really a solution at all, except for Linux users)
We noticed this on the transition from Flash 10 to to Flash 11. Flash 10 loops seamlessly, but Flash 11 has a ~1 second stall when calling seek(0) from NetStream.Play.Stop.
Embedding the media in the SWF is not an option for us.
The following code provides a more seamless loop - still not perfect, but much better.
var mStream:NetStream;
var mDuration:Number;
...
addEventListener(Event.ENTER_FRAME, onEnterFrame);
...
function onEnterFrame(e:Event):void
{
if( mStream.time > (mDuration-0.05) )
{
if( mLooping )
{
mStream.seek(0);
}
}
}
function onMetaData(info:Object)
{
mDuration = info.duration;
}
Hope it helps.
I seem to have achieved this using an FLVPlayback component along with a few tips.
What's more, it's running seamlessly on desktop, iPhone 4S and 3GS! (via an AIR app)
_videoFLV = new FLVPlayback();
_videoFLV.fullScreenTakeOver = false;
_videoFLV.autoPlay = false;
_videoFLV.autoRewind = true;
_videoFLV.isLive = false;
_videoFLV.skin = null;
_videoFLV.y = 150;
_videoFLV.bufferTime = .1;
_videoFLV.width = 320;
_videoFLV.height = 320;
_videoFLV.addEventListener(MetadataEvent.CUE_POINT, video_cp_listener, false, 0, true);
_videoFLV.source = "includes/10sec.flv";
addChild(_videoFLV);
With the listener function...
function video_cp_listener(eventObject:MetadataEvent):void {
if (eventObject.info.name == "endpoint") {
_videoFLV.seek(0);
_videoFLV.play();
}
}
Importantly I think you must set the width and height to match your flv file. i.e. no scaling whatsoever.
The flv has a cue point named 'endpoint' added 1 frame before the end of the file (assuming your start and end frame are the same this will be required).I added this using Adobe Media Encoder.
The only way to loop an flv seamlessly is to embed inside the swf. It is converted to a MovieClip and you then handle it with play(), stop(), nextFrame(), prevFrame() etc.
When embedding in Flash Authoring tool (dragging flv file on stage), make sure that you select:
"Embed FLV in SWF..."
Symbol Type : "Movie clip"
All checked : "Place instance on stage", "Expand timeline...", "Include audio"