简体   繁体   English

如何确定HTTP范围请求的开始和结束字节(nodejs + mongodb)

[英]How to determine HTTP range request start & end bytes (nodejs + mongodb)

I wonder if it is possible to determine the start & end bytes in HTTP range requests or let the browser somehow know where to start and let it use some user defined chunk size or so. 我想知道是否有可能确定HTTP范围请求中的开始和结束字节,或让浏览器以某种方式知道从哪里开始并让它使用一些用户定义的块大小左右。 I have a file in my database and it is split into multiple chunks, each chunk is 2 MB. 我的数据库中有一个文件,它被分成多个块,每个块大小为2 MB。

eg. 例如。 20 MB file => 10 chunks 20 MB文件=> 10个块

When the browser starts downloading the file (video file), I have studied Chrome, it firsts checks the 'range=bytes 0-' byte range and if the server sucessfully responds with the 'right' bytes and 206 headers back, then it sends another request for the end bytes of the file eg 'range=bytes 1900000-' , 当浏览器开始下载文件(视频文件)时,我研究过Chrome,它首先检查'range=bytes 0-'字节范围,如果服务器成功响应'right'字节和206标头,那么它发送另一个对文件结束字节的请求,例如'range=bytes 1900000-'

It just checkes if your server responds well for the partial response 它只检查您的服务器是否响应部分响应

On the serverside I have coded my app so that it will send 2 MB partials if you ask it nicely to it :) 在服务器端我已经编写了我的应用程序,以便它会发送2 MB部分,如果你很好地问它:)

What I want the browser to do 我想要浏览器做什么

range=bytes 0-'

range=bytes 2000000-4000000 bytes'

range=bytes 4000000-6000000 bytes'

But if you ask a partial which doesnt fit in a 2mb chunk it will give an error. 但是如果你问一个不适合2mb块的部分,它会给出一个错误。 Or it will just not play from the right position for a audio/video file. 或者它不会从音频/视频文件的正确位置播放。

range=bytes 2500000-4000000 bytes'

range=bytes 0-1000000 bytes'

this will give an error because I cannot start to send from a part of a chunk. 这会产生错误,因为我无法开始从块的一部分发送。 Otherwise I have to slice my chunks and do some buffer operations. 否则我必须切片我的块并做一些缓冲操作。 But I want to keep it clean. 但我想保持清洁。 If this is possible please let me know. 如果可以,请告诉我。

I am assuming that you are streaming an mp4 file? 我假设您正在播放mp4文件? Different parts (boxes) of the mp4 have different purposes, its not possible to jump to a random position in the file and start playing without out first identifying the location of each frame by preloading the index (moov). mp4的不同部分(框)具有不同的目的,不可能跳转到文件中的随机位置并开始播放而不首先通过预加载索引(moov)来识别每个帧的位置。 The moov can be at the beginning, or end of a file, so the browser MAY need the end of the of file first. moov可以位于文件的开头或结尾,因此浏览器可能需要首先结束文件。 It can determine this by starting from the beginning, and looking for the moov, if it is not at the start, there will be a pointer to the location of the next box. 它可以通过从头开始,并查找moov来确定这一点,如果它不在开头,则会有一个指向下一个框位置的指针。 It can leap frog through the file until it finds the index. 它可以跳过文件中的青蛙,直到它找到索引。 Once the moov header is downloaded, The browser will know the EXACT byte offset and size of every single frame in the video, and can jump around the file as you seek. 下载moov标题后,浏览器将知道视频中每个帧的精确字节偏移和大小,并且可以在搜索时跳转到文件。 This is all possible because the browser knows how to parse mp4 natively. 这一切都是可能的,因为浏览器知道如何本地解析mp4。 TLDR. TLDR。 No, your solution will not work. 不,您的解决方案无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM