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!
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!
Share Improve this question edited Nov 1, 2016 at 18:32 Aᴍɪʀ 7,8033 gold badges40 silver badges54 bronze badges asked Nov 1, 2016 at 18:31 IvRRimUmIvRRimUm 1,8343 gold badges22 silver badges42 bronze badges3 Answers
Reset to default 4Use 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)
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
What wouldn't be more awesome then using WebTorrent to share the video got everything you need... uses WebRTC...