Adobe has finally added a new codec to the Flash Player for video capture!.The latest build includes the H.264 codec for ENCODING, meaning you can capture your local webcam from within Flash Player and broadcast a live stream to FMS without having to use a desktop app such as Flash Media Live Encoder

Encoding H.264 is actually pretty processor-intensive, and you’ll theoretically be capturing at higher quality that you would with Spark, so there may be some significant latency and dropped frames if you aren’t careful with your settings. (The API allows for Baseline or Main profiles, with levels from 1 to 5.1 for you encoding gurus out there.)

The H264VideoStreamSettings is the subclass of the VideoStreamSettings class that enables specifying video compression settings for each NetStream. All parameters (resolution, frame rate, bandwidth, etc.) are gated by Cameracapture parameters. You can use methods (setMode(), etc.) to specify desired encoder parameters and you can use the properties (width, etc.) to retrieve the actual compression parameters used. Properties will be validated once Camera is attached to NetStream object and compression has started.

Note Current implementation does not support setting properties per NetStream and Camera parameters will be used instead for each publishing NetStream.

	                        var cam:camera = Camera.getCamera();
			       	var ns:netStream = new NetStream(nc);
				ns.client = this;
				ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); 

				var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings();
				h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_5_1);
				h264Settings.setQuality(0,0);
				h264Settings.setKeyFrameInterval(15);
				h264Settings.setMode(width,height,fps);

				ns.videoStreamSettings = h264Settings;
				ns.attachCamera(cam);
				ns.publish("livestream", "live");


THe difference between H264 Profiles is that , low powered older mobile devices need a lower version of videos to play as they do not have that much processing powere in CPU, so they use H264 Baseline profile. Newer and more powerful phones support better Profile like the h264 Main profile.

Desktop and laptops can play all of them(i am 95% sure on this). For each mobile device or tablet you can find out in their specifications whihc h264 profiles theysupport. And then you need to encode your videos in that H264 profile in order for them to play on that device. Something similar with the levels. I think if you google on h264 you find more info on this.

This is the question that was in my mind and i have ask from many of my expert friends and I have post this into  forms to got the appropriate answer for this .Andy Stevenson help me to find out the appropriate answer and now  i want to share with you all.

To publish a live stream from camcorder(video camera)  we have a following requirement

1) FMLE (flash media live encorder)

2)video capture card

3) Media server (FMS ,Wowza,Red5(opensource))

4)Plug your camcorder into your PC’s Firewire port (To transfer data in the fast speed from camcorder to pc. Firewire port  is fast then the USB port)

The feed you receive from your video camera will need to be encoded to a streamable format by an encoder. Encoders take many shapes from dedicated hardware units, to PC based solutions to encoding in the cloud. You could download Flash Media Live Encoder for free and install it on a PC to get you going. If you want to connect your video camera (not webcam) to your PC, you may need to purchase a video capture card, such as Viewcast, Digital Rapids, or Blackmagic. If you want a multi- camera setup, then you wil need access to a mixing desk (plug cameras into mixing desk which is then plugged into your encoder), but a single camera can be connected straight into the encoder

The encoder then basically send the stream to a streaming server, such as Flash Media Server, or Wowza, etc, which sends it out to your target audience. The Stream is viewed in a media player, such as JW player, Flowplayer, or maybe one you create yourself flash player.

If you use your own server, then Wowza is a good bet as it is fairly cheap, especially compared to Flash Media Server and is capable of delivering to mobile devices, as well as PC base.

Red5 is another streaming server you can use. It is open source, so if finances are an issue.

The following example shows how you can use the ZipCodeValidator to validate either US or Canadian zip codes (or should that be “postal codes” for our friends from the Great White North?). It turns out that making the ZipCodeValidator “Canadian friendly” is as simple as setting the domain property, and passing a constant value from the ZipCodeValidatorDomainType class (valid constants are US_ONLY and US_OR_CANADA).

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/25/using-the-zipcodevalidator-class-to-validate-us-or-canadian-zip-codes/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.validators.ZipCodeValidatorDomainType;
        ]]>
    </mx:Script>

    <mx:ZipCodeValidator id="zipCodeValidator"
            source="{zipCode}"
            domain="{ZipCodeValidatorDomainType.US_OR_CANADA}"
            property="text"
            trigger="{button}"
            triggerEvent="click" />

    <mx:Form>
        <mx:FormHeading label="Enter shipping zip code" />
        <mx:FormItem label="Zip code:">
            <mx:TextInput id="zipCode" maxChars="10" />
        </mx:FormItem>
        <mx:FormItem>
            <mx:Button id="button" label="Validate" />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

The major issue that i realize in adobe flex large application is the initial loading time.Sometime when .swf file size is large then Flex take a lot of time for loading at the client side and this effect the user experience.

But don’t worry Adobe give us some alternate to resolve this problem.I will give you only brief introduction is as follow

1) Modular applications

Modules are SWF files that can be loaded and unloaded by an application. They cannot be run independently of an application, but any number of applications can share the modules.

Modules let you split your application into several pieces, or modules. The main application, or shell, can dynamically load other modules that it requires, when it needs them. It does not have to load all modules when it starts, nor does it have to load any modules if the user does not interact with them. When the application no longer needs a module, it can unload the module to free up memory and resources.

Modular applications have the following benefits:

  • Smaller initial download size of the SWF file.
  • Shorter load time due to smaller SWF file size.
  • Better encapsulation of related aspects of an application. For example, a “reporting” feature can be separated into a module that you can then work on independently.
  • Modules are similar to Runtime Shared Libraries (RSLs) in that they separate code from an application into separately loaded SWF files. Modules are much more flexible than RSLs because modules can be loaded and unloaded at run time and compiled without the application.

click here to see example and more information about the Modules application

2) Runtime Shared Libraries

Another way to reduce the size of your applications’ SWF files is by externalizing shared assets into stand-alone files that can be separately downloaded and cached on the client. These shared assets can be loaded and used by any number of applications at run time, but are transferred only once to the client. These shared files are known as Runtime Shared Libraries or RSLs.

When multiple applications share a core set of components or classes, clients can download those assets only once as an RSL rather than once for each application. The RSLs are persisted on the client disk so that they do not need to be transferred across the network a second time. The resulting file size for the applications can be reduced. The benefits increase as the number of applications that use the RSL increases.

Applications built with Flex support the following types of RSLs:

  • Framework RSLs — Libraries of components and framework classes that all applications can share. Framework RSLs are precompiled for you. Adobe provides hosted, signed framework RSLs that you can link to from any application that has internet access. For more information, see Using the framework RSLs.
  • Standard RSLs — A library of custom classes created by you to use across applications that are in the same domain. Standard RSLs are stored in the browser’s cache. For more information, see About standard RSLs.
  • Cross-domain RSLs — A library of custom classes, like standard RSLs, with the difference being that they can be loaded by applications in different domains and sub-domains. Cross-domain RSLs are stored in the browser’s cache. For more information, see About cross-domain RSLs.

You can create your own RSLs from custom libraries. You do this by using either the Adobe® Flex® Builder’s™ Build Project option for your Flex Library Project or the compc command-line compiler.

To add 3D capabilities to your map, you simply need to make the following changes to your code:

  • Import the com.google.maps.Map3D, com.google.maps.View, and com.google.maps.geom.Attitude classes.
  • Instead of extending a Map object, extend a Map3D object.
  • Within the map’s MAP_PREINITIALIZE event, set the map’s view to VIEWMODE_PERSPECTIVE
  • Optionally, you can also set an initial attitude for the map to display at an oblique angle. The attitude defines the angle of the map in several directions.

The following code displays a map of New York City, but uses a 3D map and initializes it with an oblique angle:

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:s=”library://ns.adobe.com/flex/spark”
xmlns:mx=”library://ns.adobe.com/flex/mx” >
<fx:Declarations>
<!– Place non-visual elements (e.g., services, value objects) here –>
<maps:Map3D xmlns:maps=”com.google.maps.*”
mapevent_mappreinitialize=”onMapPreinitialize(event)”
mapevent_mapready=”onMapReady(event)”
id=”map”
sensor=”false” key=”your_api_key” />
</fx:Declarations>

<fx:Script>
<![CDATA[
import com.google.maps.LatLng;
import com.google.maps.Map3D;
import com.google.maps.MapEvent;
import com.google.maps.MapMouseEvent;
import com.google.maps.MapOptions;
import com.google.maps.MapType;
import com.google.maps.View;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.controls.NavigationControl;
import com.google.maps.geom.Attitude;

private function onMapPreinitialize(event:MapEvent):void {
var myMapOptions:MapOptions = new MapOptions;
myMapOptions.zoom = 12;
myMapOptions.center = new LatLng(40.756054, -73.986951);
myMapOptions.mapType = MapType.NORMAL_MAP_TYPE;
myMapOptions.viewMode = View.VIEWMODE_PERSPECTIVE;
myMapOptions.attitude = new Attitude(20,30,0);
this.map.setInitOptions(myMapOptions);
}

private function onMapReady(event:MapEvent):void {
this.map.addControl(new NavigationControl());
}
]]>

</fx:Script>

</s:Application>

Note that you will need an API key (either within the hosted HTML file or the SWF itself) to get this map to display.

Click here to get Google Maps API key.

Using Google Maps in a Flex project

Posted: 5th July 2011 by Manpreet Patil in Flex Tips
Tags: ,

The following example shows how you can embed a Google map into a Flex/ActionScript 3.0 project.

Full code after the jump.

Before getting started, you need to first get an API key from Google and then download the mapping component and put it in your /libs/ folder in your Flex Builder 3 project:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/03/using-google-maps-in-a-flex-project/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Script>
        <![CDATA[
            import com.google.maps.LatLng;
            import com.google.maps.Map;
            import com.google.maps.MapEvent;
            import com.google.maps.controls.MapTypeControl;
            import com.google.maps.controls.PositionControl;
            import com.google.maps.controls.ZoomControl;
            import com.google.maps.services.ClientGeocoder;
            import com.google.maps.services.GeocodingEvent;
            import com.google.maps.services.GeocodingResponse;
            import com.google.maps.services.Placemark;
            import mx.controls.Alert;
            import mx.events.ResizeEvent;

            private var googleMap:Map;
            private var geocoder:ClientGeocoder;

            private function init():void {
                googleMap = new Map();
                googleMap.key = APP_ID;
                googleMap.addEventListener(MapEvent.MAP_READY, googleMap_mapReady);
                googleMap.setSize(new Point(mapContainer.width, mapContainer.height));
                googleMap.addControl(new ZoomControl());
                googleMap.addControl(new MapTypeControl());

                mapContainer.addChild(googleMap);
            }

            private function geocoder_geocodingSuccess(evt:GeocodingEvent):void {
                var result:Placemark = GeocodingResponse(evt.response).placemarks[0];
                googleMap.setCenter(result.point, 13);
            }

            private function geocoder_geocodingFailure(evt:GeocodingEvent):void {
                Alert.show("Unable to geocode address: " + evt.name);
            }

            private function googleMap_mapReady(evt:MapEvent):void {
                geocoder = new ClientGeocoder();
                geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, geocoder_geocodingSuccess);
                geocoder.addEventListener(GeocodingEvent.GEOCODING_FAILURE, geocoder_geocodingFailure);
                geocoder.geocode(textInput.text);
            }

            private function button_click(evt:MouseEvent):void {
                geocoder.geocode(textInput.text);
            }

            private function mapContainer_resize(evt:ResizeEvent):void {
                if (googleMap) {
                    googleMap.setSize(new Point(mapContainer.width, mapContainer.height));
                }
            }
        ]]>
    </mx:Script>

    <mx:String id="APP_ID" source="appid.txt" />

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="Address:"
                    direction="horizontal">
                <mx:TextInput id="textInput"
                        text="601 Townsend St, San Francisco, CA 94103" />
                <mx:Button id="button"
                        label="Submit"
                        click="button_click(event);" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:UIComponent id="mapContainer"
            width="100%"
            height="100%"
            resize="mapContainer_resize(event);" />

</mx:Application>

For more information and examples, see the “Google Maps API for Flash homepage”.

• if you are using a window then here in the following path

C:\Program Files\Adobe\Adobe Flash Builder 4\sdks4.5.0\frameworks\libsplayer

HERE create a folder name with flash player version like  ”10.0 ” and place a “playerglobal.swc” file into this folder.
and in the flash builder goto following option
project–>properties–>flex compiler
here set the flash player version like 10.0.0

Basically we have seen in flex sdk 4 and sdk 4.5, when we compile the flex code  lot of unused file is also embedded into the .swf file  . These unused file increases the  .swf file size  that mean when we will use this .swf file then this will take lot of time for load that we have normally seen.

For solve this problem follow the following steps.

1) In flash builder 4 or 4.5  click on the Item”project” in menu bar

2)select option “Export” release Build”

3)new window will be open here you can give the name of the export “release build folder” By default  name of release folder is bin-release. click on finish.

You can use this  release folder same as the bin-debug folder.here .swf file size is 45 to 50 % less then the bin-debug folder .swf file.

Comparison table

Feature

Flash Media Server(FMIS 4)

Wowza Media
Server 2

Red5

Protocols supported RTMP
RTMPT
RTMPS
RTMPE
RTMPTE
RTMP
RTMPT
RTMPS
RTMPE
RTMPTE
RTMP
RTMPT
RTMPS
RTMPE
RTMPTE
Developer edition 10 Connections (Free) 10 Connections (Free) Free
Pricing $4500 $995 Free(Open Source)
Supported Platforms Microsoft® Windows Server® 2003 with Service Pack 2 or Windows Server 2008
Linux® Red Hat® 4 or 5.2
Runs as a 32-bit software on both 32- and 64-bit operating systems.
Windows
Mac OS X
Linux
Solaris
Unix
64-bit Support on all
Windows
Debian/Ubuntu
Mac OSX
WAR
Gentoo
Audio / Video Streaming (live and on-demand) FLV
H.264FLV
MP3
AAC, LC-AAC, HE-AAC
Speex
FLV
H.264FLV
MP3
AAC, LC-AAC, HE-AAC
Speex
(On Demmand)
FLV
MP3
F4V
MP4
AAC
M4A(Live)
Sorenson
VP6
h.264
Nelly Moser
MP3
Speex
AAC
NSV
Multi Client/ Multi Protocol Streaming Flash (RTMP) Flash (RTMP)
iPhone (HTTP Streaming)
Silverlight (Smooth Streaming)
QucikTime/3GPP (RTSP/RTP)
IPTV (MPEG-TS)
Flash (RTMP)
Recording H.264/AAC to FLV container
MPEG-4
H.264/AAC to FLV container
H.264/AAC to MP4 (Quicktime) container
FLV Only
Action Method Format 3 (AMF3) AMF3 AMF3 AMF
Server Side AS2 Java Java

Speex vs Nellymoser

Posted: 12th June 2011 by Manpreet Patil in Video Streaming
Tags: , ,

License type: Nellymoser is closed format codec whereas Speex is opensource which means that files created using speex can be decoded or encoded without any licence requirement.

What is speex :Speex is a new audio codec introduced in flash player 10 and above. It overcomes many limitations of old Nellymoser codec. This new codec will provide better audio quality using less bandwidth. Speex can be used for both kind of communication , through Flash Media Server or P2P.Speex is opensource so it can be decoded or converted to any format unlike nellymoser .


Speex Description: 
Speex encoder and decoder are present in flash player 10 and above. Speex compression is controlled by setting encodeQuality. Encode quality can be set using 11 quality levels 0(Lowest) – 10(Highest).Default value is 6. Speex encoder for flash works in constant bit-rate (CBR) . Speex is designed for Voice over IP (VoIP) which means it provides high quality speech at low bit rate.

Flash Player Requirement: Nellymoser works from Flash player 6 onwards whereas Speex requires atleast Flash Player 10. Although speex works with flash player 10 but there is a audio disturbance bug on listener end which was fixed in version 10,0,22,87.So player 10,0,22,87 and above is recommended.

Quality: Speex is optimised for speech so better quality is expected from speex as compared to our old Nellymoser codec.

Bandwidth Requirement: Speex delivers better quality than Nellymoser using less bandwidth as compared to speex.our tests revealed that the quality with nellymoser becomes usable at 8(16kbps) where as in case of speex it is 3 (9.80 kbps).The highest quality in Speex uses 42.2 kbps thats half of the bandwidth being used by nellymoser which is 88.2

Encode Quality: Speex provides more flexibilityby giving 11 levels of quality to choose from (0-10).0 is lowest and 10 is highest audio quality. Nellymoser gives 5 settings(5,8,11,22,44) ,5 is lowest and 44 is highest quality.Remember more is the quality higher is the bandwidth requirement which may lead to choppy sound when sufficient bandwidth is not available.

Speex

Speex Quality , Bandwidth and filesize table
Quality (encodeQuality) Required bandwidth in kbps Per minute file size in KB
0 3.95 28.9
1 5.75 42.1
2 7.75 56.7
3 9.80 71.7
4 12.8 93.7
5 16.8 123.0
6 20.6 150.8
7 23.8 174.3
8 27.8 203.6
9 34.2 250.4
10 42.2 309.0


Nellymoser

Quality(mic.rate)                                                 Required bandwidth in kbps

5                                                                                                11.025
8                                                                                                  16
11                                                                                                22.05
22                                                                                               44.1
44                                                                                                 88.2