{"id":460,"date":"2010-11-08T13:10:58","date_gmt":"2010-11-08T10:10:58","guid":{"rendered":"http:\/\/blog.denivip.ru\/?p=460"},"modified":"2013-08-05T14:12:44","modified_gmt":"2013-08-05T10:12:44","slug":"ambilight-effect-in-flash-video-player","status":"publish","type":"post","link":"http:\/\/blog.denivip.ru\/index.php\/2010\/11\/ambilight-effect-in-flash-video-player\/?lang=en","title":{"rendered":"Ambilight effect in Flash Video Player"},"content":{"rendered":"<p style=\"text-align:center;\"><a href=\"http:\/\/blog.denivip.ru\/wp-content\/uploads\/2010\/11\/1235713141_philips-cinema_21-9.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.denivip.ru\/wp-content\/uploads\/2010\/11\/1235713141_philips-cinema_21-9.jpg\" alt=\"\" title=\"Ambilight TV\" width=\"440\" height=\"297\" class=\"aligncenter size-full wp-image-454\" srcset=\"http:\/\/blog.denivip.ru\/wp-content\/uploads\/2010\/11\/1235713141_philips-cinema_21-9.jpg 440w, http:\/\/blog.denivip.ru\/wp-content\/uploads\/2010\/11\/1235713141_philips-cinema_21-9-300x202.jpg 300w\" sizes=\"(max-width: 440px) 100vw, 440px\" \/><\/a><\/p>\n<p>Flash video players become more interesting and complex, and almost as functional as home video systems. We wrote some time ago about DVR, dynamic bitrate and other functions (how to implement them in your player &#8212; not yet available in english at the moment). Now we will talk about implementing beautiful dynamic background lights like it made in Philips TV sets.<br \/>\n<!--more--><br \/>\nIn order to make this design feature we need a little bit of ActionScript 3 programming and several minutes of Flash Media Server configuring. We will go through the process by creating simple OSMF video player with Ambilight effect applied. First of all let&#8217;s discuss mechanics: ambilight effect is getting done by applying Blur filter with big distortion (x and y) to the video screen. Blurred image is placed behind real video screen and blurred edges look like ambilight effect from video screen. Simple and nice.<br \/>\n<strong>Flash Media Server<\/strong><br \/>\nIn order to apply Flash filters (i.e. Blur filter) to video stream Flash Media Server should give such permission. The permission gives access to the BitmapData of video frames from Flash video players. Responsible for the feature parameter is called VideoSampleAccess. You should enable it in Application.xml configuration file (probably you will find some template for that in file already). Sample config code:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:540px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/><\/div><\/td><td><div class=\"text codecolorer\">&amp;lt;Client&amp;gt;<br \/>\n&amp;lt;Access&amp;gt;<br \/>\n&amp;lt;VideoSampleAccess enabled=&quot;true&quot;&amp;gt;\/&amp;lt;\/VideoSampleAccess&amp;gt;<br \/>\n&amp;lt;\/Access&amp;gt;<br \/>\n&amp;lt;\/Client&amp;gt;<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>The value &#171;\/&#187; gives access to all applications video data.<br \/>\n<strong>Flash Player<\/strong><br \/>\nAfter this we are ready to develop simple video player. OSMF could help us to make this in less than an hour. Simplest video player code provided below:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:540px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/><\/div><\/td><td><div class=\"text codecolorer\">\/\/ Import Ambilight class<br \/>\nimport com.video.effects.Ambilight;<br \/>\n\/\/ Create video stream connection<br \/>\nvar resource:StreamingURLResource = new StreamingURLResource(&quot;rtmp:\/\/FMS_ip\/vod\/content.f4v&quot;);<br \/>\nvar loader:NetLoader = new NetLoader();<br \/>\nvar videoElement = new VideoElement(resource, loader);<br \/>\nvar mediaPlayer:MediaPlayer = new MediaPlayer();<br \/>\nmediaPlayer.media = videoElement;<br \/>\n\/\/ Add video screen to the stage and position it<br \/>\nvar container:MediaContainer = new MediaContainer();<br \/>\ncontainer.width = 800;<br \/>\ncontainer.x = 110;<br \/>\ncontainer.y = 110;<br \/>\naddChild(container);<br \/>\n\/\/ Link video screen to video source<br \/>\ncontainer.addMediaElement(videoElement);<br \/>\n\/\/ Apply Ambilight video effect to video screen only<br \/>\nvar amb:Ambilight = new Ambilight(container);<br \/>\n\/\/ Add Ambilight video effect to the stage<br \/>\naddChild(amb);<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>In the code above there are only two lines of difference from the sample OSMF video player. These are Ambilight object construction and adding it to the Stage. You could download Ambilight class <a onclick=\"_gaq.push(['_trackEvent', 'download', 'ambilight', 'en'])\" href=\"http:\/\/blog.denivip.ru\/sources\/Ambilight.as\">here<\/a>.<br \/>\nAmbilight class is really simple and pretty well commented. It implements algorithm below.:<\/p>\n<ul>\n<li>During construction it creates BitmapData object where later it draws blurred copy of video screen<\/li>\n<li>Reorders display objects in order to make blurred copy of video screen lay below real video screen (it gets video screen in constructor parameters)<\/li>\n<li>Adds event listener to ENTER_FRAME event in order to update ambilight effect every frame<\/li>\n<li>Every time it enters new frame it copies real video screen image, blurs it, apply ColorTransform to make it more realistic<\/li>\n<\/ul>\n<p>During design development, pay attention that ambilight effect looks better on dark background. It should be mentioned that Ambilight effect is very CPU intensive (image filter every frame) that&#8217;s why that sometime it is better to disable this feature (on netbooks as example). When entering FullScreen video mode you should manually disable Ambilight effect beacuase even invisible it will consume a lot of CPU.<br \/>\n<strong>Demo<\/strong><br \/>\nYou may check how such an effect could look like for Avatar video trailer <a href=\"http:\/\/blog.denivip.ru\/demos\/ambilight\/airplayer.html\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Flash video players become more interesting and complex, and almost as functional as home video systems. We wrote some time ago about DVR, dynamic bitrate and other functions (how to implement them in your player &#8212; not yet available in english at the moment). Now we will talk about implementing beautiful dynamic background lights like [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,12],"tags":[82,23,16,515,83],"_links":{"self":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts\/460"}],"collection":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/comments?post=460"}],"version-history":[{"count":21,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts\/460\/revisions"}],"predecessor-version":[{"id":654,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/posts\/460\/revisions\/654"}],"wp:attachment":[{"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/media?parent=460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/categories?post=460"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.denivip.ru\/index.php\/wp-json\/wp\/v2\/tags?post=460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}