5

I have a built a streaming web server for loading a video. I have also setup a simple html page with a video tag that requests the video content.

The initial request has a header like as:

Range:bytes=0-

On my server I am setting the end of the range to:

Range:bytes=0-100000

This works and the html player requests the next part of the content with the header of:

Range:bytes=100001-

Which then returns the rest of the content.

How do I get the html video tag to request the correct ranges.

Charles Bryant
  • 995
  • 2
  • 18
  • 30
  • does your video have the MOOV atom (metadata) at the start of the file to tell the ` – Offbeatmammal Jan 08 '18 at 19:11
  • No probably not, I will go investigate, thanks – Charles Bryant Jan 08 '18 at 19:16
  • I used ffmpeg to move the metadata to the start of the file, this has enabled scrubbing over the whole video. – Charles Bryant Jan 08 '18 at 23:55
  • so, all good? If so, I'll make my comment an answer if that's okay – Offbeatmammal Jan 09 '18 at 00:39

2 Answers2

5

You don’t make the browser request the “correct” range. The browser requests the ranges it needs. The server must respond to the range requests it makes correctly.

szatmary
  • 29,969
  • 8
  • 44
  • 57
  • Yes this is how I see it now. However looking at youtube requests they request lots of much smaller packages so I assume that is custom functionality for them, although I do not think there is a use case for me to do that. – Charles Bryant Jan 09 '18 at 20:31
  • If you use media source extensions, you can fragment the video any way you like. – szatmary Jan 10 '18 at 00:34
2

To provide the information that the video element needs, you'll want the metadata for the frames to be at the start of the file. This is contained in the MOOV atom, and can be repositioned at the start in an MP4 video (so it's read when the file is initially opened) using something like ffmpeg. This will allow the video element to correctly request start and end points, rather than just start and hoping for the end...

./ffmpeg -y -i SourceFile.mp4 -c:a copy -c:v copy -movflags faststart DestFile.mp4

This will simply relocate the MOOV atom without any additional transcoding (the -c:a copy and -c:v copy simply copy the audio and video without change)

Offbeatmammal
  • 7,970
  • 2
  • 33
  • 52
  • 1
    This was about the best solution I could come up with and seems to enable all the functionality I wanted, but does not actually chang the byte range requested – Charles Bryant Jan 09 '18 at 20:27