最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Receive chunks of video and play them in browser - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 4

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)

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...

发布评论

评论列表(0)

  1. 暂无评论