-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
New video containers #405
Comments
I'd like to support all video containers and formats. But this is not trivial. Right now, we use the videostream package to provide support for MP4. That would be the place to look at adding support, or you could write (or convince someone to write) a new package that we could use in WebTorrent. |
@feross I just know that MediacenterJS supports
Or am I off-topic? |
@HLFH mediacenterjs seems to be using ffmpeg (see https://github.com/jansmolders86/mediacenterjs/blob/master/lib/transcoding/desktop.js#L54) so that won't do it in the browser. |
Yeah, I'm holding out for the day that @jhiesey adds MKV support to |
https://github.com/strukturag/libde265.js might be useful |
this looks good https://github.com/RSATom/WebChimera.js |
"libvlc binding" no |
We just need a package that can parse the MKV container format. |
This is really an issue for |
My workaround for being able to stream Applied the answer of http://stackoverflow.com/a/24977085 to this case: var WebTorrent = require("webtorrent");
var http = require("http");
var fs = require("fs");
var url = require("url");
var path = require("path");
// Normal torrent handling as before.
var magnet = "your-magnet-here";
var client = new WebTorrent();
client.add(magnet, function (torrent) {
var file = torrent.files[number];
// You can still do this for MP4 video's.
//file.appendTo('#player',function(err, elem){
// console.log(err)
//});
// .. But for other formats we're using this.
var server = http.createServer(function(req, res) {
// The absolute path to the local video file.
var localFile = torrent.path + "/" + file.path;
// We only handle stream requests.
if (req.url != "/stream.mkv" && req.url != "/stream.avi" && req.url != "/stream.mp4") {
return res.writeHead(404, {"Content-Type": "text/plain"});
res.end();
}
fs.stat(localFile, function (err, stats) {
if (err) {
if (err.code == "ENOENT") {
return res.writeHead(404, {"Content-Type": "text/plain"});
} else {
// For some reason we can't stat the file.
return res.writeHead(500, {"Content-Type": "text/plain"});
}
res.end(err);
}
var range = req.headers.range;
if (!range) {
// Invalid range requested by client. The HTML5 video player
// should do this by itself.
return res.writeHead(416, {"Content-Type": "text/plain"});
}
// Calculate position to stream.
var positions = range.replace(/bytes=/, "").split("-");
var start = parseInt(positions[0], 10);
var total = stats.size;
var end = positions[1] ? parseInt(positions[1], 10) : total - 1;
var chunksize = (end - start) + 1;
// Write headers for the stream.
res.writeHead(206, {
"Content-Range": "bytes " + start + "-" + end + "/" + total,
"Accept-Ranges": "bytes",
"Content-Length": chunksize,
"Content-Type": "video/mp4"
});
// Start the stream.
var stream = fs.createReadStream(localFile, { start: start, end: end })
.on("open", function() {
stream.pipe(res);
}).on("error", function(err) {
res.end(err);
});
})
}).listen(8888);
// Here goes the magic. Append this in your client.
$("body").append('<video controls autoplay src="http://localhost:8888/stream.mp4"></video>');
}); I'm not sure if Chrome even cares if the video is delivered with
(This applies to #796 as well) Cheers, |
@lesander You can simplify your code a lot because WebTorrent already has a built-in local http server that you can use from Node. Here's an example: var client = new WebTorrent()
var magnetURI = 'magnet: ...'
client.add(magnetURI, function (torrent) {
// create HTTP server for this torrent
var server = torrent.createServer()
server.listen(port) // start the server listening to a port
// visit http://localhost:<port>/ to see a list of files
// access individual files at http://localhost:<port>/<index> where index is the index
// in the torrent.files array
// later, cleanup...
server.close()
client.destroy()
}) 👍 |
I see that webtorrent desktop asks to open avi files in an external player, because it is not a supported container. |
@stoufa88 Yes. All file formats supported by Chrome's video player. |
This could be done with WebChimera.js |
Seconded on WebChimera.js . Why do all the work when VLC did it and we have a good binding?
VLC isn't required. Just use WebChimera-prebuilt |
This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue. |
Many torrents contains files with mkv and avi extension and coded by H.264 and other supported codec. Now I get error below, when trying to append video tag with source
My code is
Can you add avi and mkv containers? Thanks!
The text was updated successfully, but these errors were encountered: