Find bytes range of webm video for specified segment

2.2k Views Asked by At

I have a Video in webm format (like video.webm the duration is 60 seconds)
I want to get specified segment of video (i.e split video) with http header range (Range: 100-200).
In an other word :
I want to get a section of video (e.g. from second 4 to 12) but i don't want to use any converter like ffmpeg. i want to send http request to server & get specified range of webm file.

Can i use this method (http range header)?

Thanks

1

There are 1 best solutions below

5
On BEST ANSWER

Since the source is non-live it should have a Cues block. I think one way to do it is to fetch the start of the file to get to the MetaSeek information which will point you to the Cues box.

Parsing the Cues will give the CueTime, CueTrack, CueClusterPosition, CueBlockNumber etc. You can use the information to find the clusters that you need.

Take a look at the file with mkvinfo in verbose level 3 to see how it's organized (mkvinfo -v -v -v input.webm).

Example output:

+ Cues at 3441
| + Cue point at 3447
|  + Cue time: 0.000s at 3449
|  + Cue track positions at 3452
|   + Cue track: 1 at 3454
|   + Cue cluster position: 3911 at 3457
| + Cue point at 3461
|  + Cue time: 0.600s at 3463
|  + Cue track positions at 3467
|   + Cue track: 1 at 3469
|   + Cue cluster position: 3911 at 3472
|   + Cue block number: 42 at 3476
| + Cue point at 3480
|  + Cue time: 3.520s at 3482
|  + Cue track positions at 3486
|   + Cue track: 1 at 3488
|   + Cue cluster position: 3911 at 3491
|   + Cue block number: 241 at 3495

You can also find the Matroska specifications here. WebM is a subset, see the specs here.

Update: I found an example on how to use HTTP Range request to download a cluster here. It uses the Media Source Extension Tools to dump the WebM info in JSON.