Seamless transition between two videos

[SIZE=“4”]Question[/SIZE]

How can I have seamless transitions between videos in a playlist? My video is chunked up into 10 second segments (for reasons that are out of the scope of this question). Currently, the transition is not smooth. Sometimes there is a short flicker of blackness and other times there is a gap in the audio. It’s unpredictable which one will occur.

The problem is not with the video encoding. I have tried both FFMPEG and Flash Media Encoder to chunk up my video. When repackaged back into one whole video, it plays fine in VLC Media Player.

[SIZE=“4”]Live example[/SIZE]

Here is an example of two chunks played back to back.

[LIST]
[]Demo: http://levichi.com/flashPlaylist/Seamless.html
[
]FLA: http://levichi.com/flashPlaylist/Seamless.fla
[*]AS: http://levichi.com/flashPlaylist/Seamless.as
[/LIST]

[SIZE=“4”]Code[/SIZE]

This is a bare-bones program that illustrates my issue. It only plays two chunks. My actual code is generalized to work with a huge array of video chunks.


import Seamless;
var s:Seamless = new Seamless(stage);


package
{
	import flash.net.*;
	import flash.events.*;
	import flash.media.*;
	import flash.display.*;

	public class Seamless
	{    
		private var vid:Video;            
		private var vidStream0:NetStream;
		private var vidStream1:NetStream;
		
		public function Seamless(container:Stage)
		{
			var vidConnection0:NetConnection = new NetConnection();
			var vidConnection1:NetConnection = new NetConnection();

			vidConnection0.connect(null);
			vidConnection1.connect(null);

			this.vidStream0 = new NetStream(vidConnection0);
			this.vidStream1 = new NetStream(vidConnection1);

			var monitor:Object = new Object();
			monitor.onMetaData = this.onMetaData;
			monitor.onCuePoint = this.onCuePoint;

			vidStream0.client = monitor;
			vidStream1.client = monitor;
		
			this.vidStream0.addEventListener(NetStatusEvent.NET_STATUS, this.transitionToVid1);
			this.vidStream1.addEventListener(NetStatusEvent.NET_STATUS, this.pauseVid1);
			
			this.vid = new Video(960, 540);
			this.vid.attachNetStream(this.vidStream0);
			container.addChild(this.vid);
			
			this.vidStream0.play("2.flv");
			this.vidStream1.play("3.flv");
		}
		
		/**
		 * When video 0 reaches it's end, it needs to tell video 1 to start playing.
		 */
		private function transitionToVid1(event:NetStatusEvent):void
		{
			if (event.info.code == "NetStream.Play.Stop") {
				this.vidStream0.removeEventListener(NetStatusEvent.NET_STATUS, this.transitionToVid1);
				this.vid.clear();
				this.vid.attachNetStream(this.vidStream1);
				this.vidStream1.resume();
			}
		}
		
		/**
		 * Pause video 1 after it has been initiated, so it can buffer while video 0
		 * is playing.
		 */
		private function pauseVid1(event:NetStatusEvent):void
		{
			if (event.info.code == "NetStream.Play.Start") {
				this.vidStream0.removeEventListener(NetStatusEvent.NET_STATUS, this.pauseVid1);
				this.vidStream1.pause();
			}
		}
		
		/**
		 * Required to prevent runtime errors when the video spits out meta data at 
		 * certain places times.
		 */
		private function onMetaData(info:Object):void {
			//trace("duration:", info.duration);
		}
		
		/**
		 * Requried to prevent runtime errors when the video hits cuepoints at certain
		 * places.
		 */
		private function onCuePoint(info:Object):void {
			//trace("cuepoint:", info.parameters.text);
		}
	}
}