Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronized video playback among other users #1334

Closed
fredsif opened this issue Mar 16, 2018 · 4 comments
Closed

Synchronized video playback among other users #1334

fredsif opened this issue Mar 16, 2018 · 4 comments
Labels

Comments

@fredsif
Copy link

@fredsif fredsif commented Mar 16, 2018

Hi,

I would like to know if it's possible to do a synchronized playback of a playlist among other users in the same site.
As in doing some sort of "live streaming", without it being really live.

Would that need a MySQL database or is it possible to do it all in JS?

Thanks

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Mar 16, 2018

This is surely something built on top of WebTorrent instead of in it.

@fredsif

This comment has been minimized.

Copy link
Author

@fredsif fredsif commented Mar 16, 2018

Yes, I figured that it could be added on top of it.

I'm thinking something like when users are downloading a video file of a determinate playlist, at a certain point of the video, they start downloading the next one, so the playback is seamless.

When the next video starts playing, the older one stops being seeded. This is to mitigate the CDN bandwidth depending of the number of simultaneous visitors watching the playlist.

@t-mullen

This comment has been minimized.

Copy link

@t-mullen t-mullen commented Mar 16, 2018

You could roughly synchronize video playback with no scrubbing without any form of communication.

When the user loads the metadata for every video in the playlist, sum together the durations of each video (get the duration by loading it into a video element and waiting for onmetadataloaded) to get a total playlist length. Then get a UTC timestamp with (new Date()).getTime(). Modulo the timestamp by the playlist length, and that's the position to start the playlist (plus some offset if you want the playlist to start at exactly say 12:00pm EST).

Every time playback restarts, you'd need to resynchronize the video in the same way. But you should have all clients playing the same video at roughly the same time. The playlist will loop forever (since you're using a modulo), but you could specify a "start" time and "end" time that the client could respect.

If you need scrubbing/controls that's a bit more complex. I would run RPC over a separate WebRTC swarm. You could do simple flood messages if you are thinking on a small scale ~50 peers, but you'll need a proper gossip protocol if you want to scale. See rpc-stream and webrtc-swarm.

A colleague and I have been working on a similar project (synchronized video over WT), with a similar approach (timestamp for initial sync, small gossip swarm for fine control). Good luck.

This works best if you have a large number of clients with the torrent fully downloaded, otherwise you'll have the same problems as any P2P live broadcast (data will be bottlenecked through a few peers, and you'll have high churn).

@feross feross added the question label May 16, 2018
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 16, 2018

I'm closing this issue since there's no bug to fix here, but feel free to continue discussion!

@feross feross closed this May 16, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.