流的MP4视频从寻求在ASP.NET中的位置位置、视频、NET、ASP

2023-09-04 23:31:49 作者:我是姜屎屎~

我现在面临的问题,同时流的MP4视频,从寻求位置。它正确地从开始流。

I am facing problem while streaming mp4 video from seek position. Its streaming properly from start.

第一个问题是,而MP4视频通过流媒体播放器JW Flash播放器。当时间条用户点击,开始从视频的其他部分流MP4视频,JW播放器会发出启动参数随着时间的信息,例如

First problem is while mp4 video is streaming via jw player flash player. When user click on time bar to start streaming mp4 video from any other part of video, jw player will send start param along with time information e.g

http://[url]/stream/mp4.ashx?file=Madagascar3-trailer-48861c.mp4&start=53.71

所以jwplayer发送时间间隔,以寻求从MP4流。

So jwplayer send time interval to seek mp4 streaming from.

我使用下面的code到约时间间隔转换为字节寻求将开始通过字节。

I am using the following code to convert approx time interval to bytes as seek will start via bytes.

 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);

下面是完整的示例codeI正在使用,开始从寻求位置,例如流53.71

Here is complete sample code i am using to start streaming from seek position e.g 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();

}

但它没有认识到为有效MP4流或者通过播放器或直接检查流网址。

But it failed to recognize as valid mp4 stream either by player or checking stream url directly.

谁能帮我解决这个问题。

Can anyone help me to fix this issue.

推荐答案

同意,你不能只寻求一个这样的MP4 / M3U8文件。

Agreed, you cannot just seek an mp4/m3u8 file like that.

但我认为你找不到解决方法:对于这一点,我们有资深的iPhone开发人员和外聘顾问在我的iPhone开发团队反复试验,我们花了这么多的资源,但问题仍没有解决。

But I think you cannot find the solution or workaround for this, we have senior iPhone developers and external consultant in my iPhone development team for trial and error, we spend so many resources but the problem still cannot fix.