AS3.0: boosting .flv volume by hacking the NetStream object out of FLVPlayback

Use Case
You’re handed an AS3.0 project that’s been built by someone else and that developer used the FLVPlayback component to play multiple videos. All’s worked OK in the past, but suddenly, you get 1 video, already in .FLV format and it’s volume is way lower than all the rest of the videos. The client’s going to notice, everybody knows this much. When you ask the logical question: why not just send the file back to the video editor and have her boost the volume in After Effects or Audacity? You’re told no, it’s too late, the video budget’s been spent already and nobody caught the problem during video assets QA.

Lucky for them, you can use AS3.0 to boost the volume of a video with low sound quality.

This is easier to do with custom video players because by default, the FLVPlayback component doesn’t give you any sort of getNetStream() method. Thanks to a good Developer at Firefly there’s a way to grab the NetStream from FLVPlaback. Once we have it, you combine it with a SoundTransform instance and you’re good to go.

package com.yourpackage.path
{
	//...
	import flash.media.SoundTransform;	
	import flash.net.NetStream;
    import flash.display.Sprite; 
    import fl.video.FLVPlaback; 

	public class MyPlayer extends Sprite 
	{
		private var videoSound:SoundTransform = new SoundTransform();
		private var ns:NetStream;
        private var vidPlayer:FLVPlaback = new FLVPlaback();
		//...
	
		public MyPlayer()
		{
			//...
			//used for NetStream capture
			idPlayer.addEventListener(VideoEvent.STATE_CHANGE, onVideoStateChange);
			//...
		
			boostVolume();
		}
	
		// grab the NetStream using the evt.vp index
		public function onVideoStateChange(e:VideoEvent)
		{
			ns = vidPlayer.getVideoPlayer(e.vp).netStream;
		}
	
		public function boostVolume():void
		{			
			videoSound.volume = 2.4;
			ns.soundTransform = videoSound;
		}
	
		public function normalizeSound():void
		{
			videoSound.volume = 1;
			ns.soundTransform = videoSound;
		}
		
	    //...
	} 
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s