dev.convexstyle.net

H.264 動画の Progressive 配信

del.icio.us hatena bookmark

H.264 動画の Progressive 配信


前回のエントリーで、Flash Media Server 3 を使用した Streaming 配信に関して記述しましたが、今度はウェブディレクトリより通常の Progressive 再生をしてみたのでメモ。

前回は NetStream.play の記述は ns.play("mp4:sample.mp4"); や ns.play("mp4:sample.mov"); の様な形式で記述し Streaming 再生させていたが、Progressive 再生では NetConnection.connect(null) にして同様な記述では H.264 の動画コーデックで作成された MPEG-4 や MOV を再生できないようだ。

もろもろ調べていたら flashcomguru の記事に同様な問題で、下記の様な記述が。
"That did the trick and my mp4 files now use a naming convention of Rendition.mov.flv, even though it complained that the file can't be opened. trust me it can once you run it in a browser."

要は、.mp4 や .mov も .flv として見立てて、ファイルの拡張子を例えば sample.mp4.flv や sample.mov.flv に変更し、NetStream.play の記述を ns.play("sample.mp4.flv"); やns.play("sample.mov.flv"); に変更し、サーバにアップロードすれば動作する。
*ただし .flv の時は 拡張子を削除して ns.play("sample.mp4"); や ns.play("sample.mov"); の様に記述したいところだが、ns.play("sample.mp4"); では動作したが、ns.play("sample.mov"); では 404 エラーが返ってきた。ここら辺の挙動はどうなのか。

flashcomguru からはサンプル fla をダウンロードでき、そちらでは FLVPlayback を使用しているので、source プロパティに拡張子を変更したファイルの絶対パス(例:http://hogehoge.com/flv/sample.mov.flv)を指定して動作させている。

次の Flash Player 辺りで改善されそうな内容ですが、一時的な改善策としてこんな感じらしい。念のため、ソースは下記に。

▽ メインタイムライン
*簡潔化のためにタイムラインにソースを記述。

stop();

import flash.display.MovieClip;
import flash.events.AsyncErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.NetConnection;
import flash.net.NetStream;


/**
* ///////////////////////////////////
* アプリケーション接続関連設定
* ///////////////////////////////////
*/

/**
* NetConnection オブジェクト設定
*/
var nc:NetConnection = new NetConnection();
nc.client = new CustomClient();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNcNetStatusEvent);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onNcAsyncErrorEvent);
nc.addEventListener(IOErrorEvent.IO_ERROR, onNcIOErrorEvent);
nc.connect(null);// Progressive 再生の場合

/**
* NetConnection onStatus イベントハンドラ関数
* @param NetStatusEvent evt
* @return void
*/
function onNcNetStatusEvent(evt:NetStatusEvent):void {
switch(evt.info.code) {
case "NetConnection.Connect.Success":
trace("アプリケーションへの接続が成功しました。");
playVideo();
break;
case "NetConnection.Connect.Failed":
trace("アプリケーションへの接続が失敗しました。");
break;
case "NetConnection.Connect.Rejected":
trace("アプリケーションに接続する権限がありません。");
break;
case "NetConnection.Connect.Closed":
trace("アプリケーションへの接続が無事解除されました。");
break;
case "NetConnection.Connect.InvalidApp":
trace("アプリケーション名が無効です。");
default:
trace(evt.info.code);
break;
}
}

/**
* NetConnection AsyncErrorEvent イベントハンドラ関数
* @param AsyncErrorEvent evt
* @return void
*/
function onNcAsyncErrorEvent(evt:AsyncErrorEvent):void {
trace("AsyncErrorEvent エラー");
trace(evt.toString());
}

/**
* NetConnection IOErrorEvent イベントハンドラ関数
* @param IOErrorEvent evt
* @return void
*/
function onNcIOErrorEvent(evt:IOErrorEvent):void {
trace("IOErrorEvent エラー");
}


/**
* ///////////////////////////////////
* NetStream オブジェクト関連設定
* ///////////////////////////////////
*/

/**
* 動画再生用関数
* @return void
*/
function playVideo():void {

// メインの Video 格納用
var mainMc:MovieClip = new MovieClip();
mainMc.graphics.lineStyle(0, 0x000000, 1);
mainMc.graphics.drawRect(0, 0, 320, 240);
mainMc.x = Math.floor((this.stage.stageWidth / 2) - (mainMc.width / 2));
mainMc.y = Math.floor((this.stage.stageHeight / 2) - (mainMc.height / 2));
addChild(mainMc);

// NetStream オブジェクト作成
var ns:NetStream = new NetStream(nc);
ns.client = new CustomClient();
ns.addEventListener(NetStatusEvent.NET_STATUS, onNsNetStatusEvent);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onNsAsyncErrorEvent);


// Video オブジェクト作成
var video:Video = new Video();
video.attachNetStream(ns);
mainMc.addChild(video);


// NetStream 再生
ns.play("sample.mp4.flv");// .mp4 の Progressive 配信
ns.play("sample.mov.flv");// .mov の Progressive 配信

}


/**
* NetStream NetStatusEvent イベントハンドラ関数
* @param NetStatusEvent evt
* @return void
*/
function onNsNetStatusEvent(evt:NetStatusEvent):void {
trace(evt.info.code);
}

/**
* NetStream AsyncErrorEvent イベントハンドラ関数
* @param AsyncErrorEvent evt
* @return void
*/
function onNsAsyncErrorEvent(evt:AsyncErrorEvent):void {
trace("NetStream の非同期エラー");
trace(evt.toString());
}


▽ CustomClass

package {
	
	public class CustomClient {
		
		/**
		* onBWDone イベントハンドラ関数
		* @return void
		*/
		public function onBWDone():void {
			trace("onBWDone");
		}
		
		/**
		* onMetaData イベントハンドラ関数
		* @param Object infoObj
		* @return void
		*/
		public function onMetaData(infoObj:Object):void {
			trace("onMetaData");
		}
		
		/**
		* onPlayStatus イベントハンドラ関数
		* @param Object infoObj
		* @return void
		*/
		public function onPlayStatus(infoObj:Object):void {
			trace("playStatus");
		}
		
	}
	
}


【開発環境】
Flash CS3 Professional


【参考サイト】
flashcomguru

この記事関連する書物 from Amazon.co.jp

トラックバック

このエントリーのトラックバックURL:
http://www.convexstyle.net/mt/mt-tb.cgi/54

コメントを投稿

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)