2012-03-16 4 views
0

asp.net 스크립트를 사용하여 어떤 부분이나 섹션에서 mp4 비디오를 스트리밍하는 동안 문제가 있습니다. 시작에서 mp4 비디오를 스트리밍 할 때 스크립트가 잘 작동하지만 시작 지점을 선택하려는 경우 스트리밍에 실패했습니다. 내가 ASP.NET을 사용하는 프로 그래 시브 Mp4 스트리밍

if (filename.EndsWith(".mp4") && filename.Length > 2) 
{ 
    FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); 
    // Sample logic to calculate approx length based on starting time. 
    if (context.Request.Params["starttime"] != null && context.Request.Params["d"] != null) 
    { 
     double total_duration = Convert.ToDouble(context.Request.Params["d"]); 
     double startduration = Convert.ToDouble(context.Request.Params["starttime"]); 
     double length_sec = (double)fs.Length/total_duration; // total length per second 
     seekpos = (long)(length_sec * startduration); 
    } 
    if (seekpos==0) 
    { 
     position = 0; 
     length = Convert.ToInt32(fs.Length); 
    } 
    else 
    { 
     position = Convert.ToInt32(seekpos); 
     length = Convert.ToInt32(fs.Length - position); 
    } 
    // Add HTTP header stuff: cache, content type and length   
    context.Response.Cache.SetCacheability(HttpCacheability.Public); 
    context.Response.Cache.SetLastModified(DateTime.Now); 
    context.Response.AppendHeader("Content-Type", "video/mp4"); 
    context.Response.AppendHeader("Content-Length", length.ToString()); 
    if (position > 0) 
    { 
     fs.Position = position; 
    } 
    // Read buffer and write stream to the response stream 
    const int buffersize = 16384; 
    byte[] buffer = new byte[buffersize]; 

    int count = fs.Read(buffer, 0, buffersize); 
    while (count > 0) 
    { 
     if (context.Response.IsClientConnected) 
     { 
      context.Response.OutputStream.Write(buffer,0, count); 
      context.Response.Flush(); 
      count = fs.Read(buffer, 0, buffersize); 
     } 
     else 
     { 
      count = -1; 
     } 
    } 
    fs.Close(); 
} 

을 사용하고

샘플 스크립트가 나는 문제는 내가 그것을 제거하면, 비디오 여전히 재생할 수 있지만, 시작 의 경우 (위치> 0) { FS, 다음 줄에 생각합니다. 위치 = 위치; } 는 위치>

0 어떤 일이 나를 도와 줄 수 추구하는 경우, 스트림이 인식 할 수없는 때문에되는 위치를 찾아 추적 FLV 스트리밍에 사용되는 같은 MP4 헤더를 시작있을 수 있습니다.

감사합니다.

+1

FileStream에서의 위치 설정이 텍스트 파일에서만 작동하기 때문에 일부 플레이어 (실버 라이트 또는 플래시)를 고려해야 할 수도 있습니다. mp4에서 일할 수있는 아주 작은 기회. – mslliviu

+0

문제는 예를 들어 jwplayer와 같은 플래시 플레이어를 클릭하면 스트리밍 스크립트로 시작 시간이 전송되지만 스트리밍 스크립트는 mp4의 경우 요청 된 위치의 콘텐츠를 보낼 수 없으며 플래시 flv의 경우 작동합니다. http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Internet-Information-Services-IIS7-Version2를 구현하는 동안 작동하지만 http 스크립트를 통해 직접 작업하는 것이 좋습니다. . – irfanmcsd

답변

0

Content-Length를 파일 길이로 설정했지만 파일의 일부만 보냅니다.

또한 비디오를 이렇게 나눌 수는 없다고 생각합니다. 파일 위치를 I- 프레임의 시작 부분으로 설정해야한다고 생각합니다. 이는 MP4 파일을 구문 분석하여 가장 가까운 I를 찾는 것입니다. 원하는 시간에 프레임을 만들고 바이트 위치로 파일 위치를 설정 한 다음 거기에서 스트리밍을 시작합니다.

관련 문제