私はシーク位置からMP4ビデオをストリーミング中に問題に直面しています。開始から適切にストリーミング。ストリームMP4ビデオASP.NETのシーク位置から
最初の問題は、mp4ビデオがjwプレーヤーのFlash Player経由でストリーミングされていることです。ときにタイムバー上のユーザーがクリックビデオの他の部分からMP4ビデオのストリーミングを開始するには、JWプレイヤーは、時間情報とともに例えば
http://[url]/stream/mp4.ashx?file=Madagascar3-trailer-48861c.mp4&start=53.71
を開始PARAMをお送りしますだからjwplayerからのストリーミングのMP4を模索する時間間隔を送信します。
シークがバイトで開始されるため、次のコードを使用して、およその時間間隔をバイトに変換しています。
double total_duration = Convert.ToDouble(context.Request.Params["d"]);
double startduration = Convert.ToDouble(context.Request.Params["start"]);
double length_sec = (double)size/total_duration; // total length per second
start = (long)(length_sec * startduration);
は、ここで私が求めて位置例えば53.71
private void ChunkDownload(string fullpath, HttpContext context)
{
long size, start, end, length, fp = 0;
using (StreamReader reader = new StreamReader(fullpath))
{
size = reader.BaseStream.Length;
start = 0;
end = size - 1;
length = size;
double total_duration = Convert.ToDouble(context.Request.Params["d"]);
double startduration = Convert.ToDouble(context.Request.Params["start"]);
double length_sec = (double)size/total_duration; // total length per second
start = (long)(length_sec * startduration);
context.Response.AddHeader("Accept-Ranges", "0-" + size);
long anotherStart = start;
long anotherEnd = end;
// End bytes can not be larger than $end.
anotherEnd = (anotherEnd > end) ? end : anotherEnd;
// Validate the requested range and return an error if it's not correct.
if (anotherStart > anotherEnd || anotherStart > size - 1 || anotherEnd >= size)
{
context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size);
throw new HttpException(416, "Requested Range Not Satisfiable");
}
start = anotherStart;
end = anotherEnd;
length = end - start + 1; // Calculate new content length
fp = reader.BaseStream.Seek(start, SeekOrigin.Begin);
context.Response.StatusCode = 206;
}
// Notify the client the byte range we'll be outputting
context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size);
context.Response.AddHeader("Content-Length", length.ToString());
context.Response.WriteFile(fullpath, fp, length);
context.Response.End();
}
からストリーミングを開始するために使用しています完全なサンプルコードです。しかし、それはどちらかのプレイヤーが直接ストリームのURLをチェックするなど、有効なMP4ストリームを認識することができませんでした。
誰でもこの問題を解決するのに役立ちますか?
ファイルのヘッダーを再送信してから位置を要求しなければならないと思います。デコーダは圧縮設定を認識できず、ストリームを処理することができません。ちょうど私の意見。 – ppumkin