IvRRimUm
IvRRimUm

Reputation: 1834

Receive chunks of video and play them in browser

Base idea: I am creating an app. In which user chooses local file(mp4) in input field(type="file") and then streams the video to other user. I am thinking to manipulate the file in javascript. And send it chunk by chunk to another user via(datachannels webRTC) then just play it on the other side chunk by chunk.

I understand that i can "assemble" the chunks using - MediaSource API

Questions: How can i split the video in chunks using javascript? I have been googling for a while i can't seem to find a library( maybe i am googling wrong keywords? ).

Thanks!

Upvotes: 5

Views: 4998

Answers (3)

Endless
Endless

Reputation: 37786

What wouldn't be more awesome then using WebTorrent to share the video got everything you need... uses WebRTC...

Upvotes: 1

Endless
Endless

Reputation: 37786

Another thing i might think you are interested in is File streaming...

To get a ReadableStream from a blob you could use the hackish why of doing

stream = new Response(blob).body
reader = stream.getReader()
reader.read().then(chunk => spread(chunk)) 

Another cool library otherwise you can use to stream the blob Is by using Screw-FileReader

Upvotes: 1

Endless
Endless

Reputation: 37786

Use blob#slice to split the video

// simulate a file
blob = new Blob(['ab'])
chunk1 = blob.slice(0, 1)
chunk2 = blob.slice(1, 2)

console.log(blob.size)
console.log(chunk1.size)
console.log(chunk2.size)

Upvotes: 4

Related Questions