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

Problems to play mkv and mp4 video format #1621

Closed
ChrisMichaelPerezSantiago opened this issue Apr 27, 2019 · 1 comment
Closed

Problems to play mkv and mp4 video format #1621

ChrisMichaelPerezSantiago opened this issue Apr 27, 2019 · 1 comment

Comments

@ChrisMichaelPerezSantiago
Copy link

@ChrisMichaelPerezSantiago ChrisMichaelPerezSantiago commented Apr 27, 2019

What version of WebTorrent?
"webtorrent": "^0.103.1"

What operating system and Node.js version?

  • operating sistem: windows 10
  • Nodejs Version: v10.15.3

What browser and version? (if using WebTorrent in the browser)

  • Chrome, last version

What did you expect to happen?

  • Be able to play any mp4 and mkv video.

What actually happened?

  • I'm trying to play some mkv format video using some magnetlink but nothing happens. Im using the file.appendTo('.log') to achieve video playback. It even only works with the mp4 format, specifically with the Sintel video, which is an example on the webtorrent.io page. With other video mp4 it does not work, except with the one of Sintel

Any help will be more than grateful.

Source Code

const concat = require('concat-stream');
const dragDrop = require('drag-drop/buffer');
const WebTorrent = require('webtorrent');
const moment = require('moment');
const prettierBytes = require('prettier-bytes');
const throttle = require('throttleit');
const util = require('./util');
const downloadAs = require('./zip');
var MediaElementWrapper = require('mediasource');
const client = new WebTorrent();

localStorage.debug = '*';

//const FAKE = ['b560a21ebfead8f6feb54706f41f459f819c0ae5'];

function createElem (tagName) {
  var elem = document.createElement(tagName)
  elem.controls = true
  elem.autoplay = true // for chrome
  elem.play() // for firefox
  document.body.appendChild(elem)
  return elem
}

client.on('error', util.warning);

dragDrop('body' , (files) =>{
  client.seed(files , onTorrent);
});

init();
function init(){
  document.querySelector('form').addEventListener('submit', function (e) {
    e.preventDefault()
    var torrentId = document.querySelector('form input[name=torrentId]').value
    util.log('Adding ' + torrentId)
    client.add(torrentId, onTorrent)
  });
}


//onHashChange()
//window.addEventListener('hashchange', onHashChange)
//function onHashChange () {
//  var hash = decodeURIComponent(window.location.hash.substring(1)).trim()
//  if (hash !== ''){
//    downloadTorrent(hash)
//  }
//}
//
//
//function downloadTorrent(id){
//  var fake = FAKE.some(function(infohash){
//    return id.indexOf(infohash) >= 0
//  });
//  if(fake){
//    util.log('File not found');
//  }else{
//    util.log('Downloading torrent from ' + id);
//    client.add(id , onTorrent)
//  }
//}


var _Torrent;
function onTorrent(torrent){
  _Torrent = torrent;
  torrent.on('warning' , util.warning);
  torrent.on('error' , util.error);
  
  util.log('Got torrent metadata!')
  util.log(
    'Torrent info hash: ' + torrent.infoHash + ' ' +
    '<a href="' + torrent.magnetURI + '" target="_blank">[Magnetlink]</a> ' +
    '<a href="' + torrent.torrentFileBlobURL + '" target="_blank" download="' + torrent.name + '.torrent">[Download .torrent]</a>'
  );

  torrent.on('download', throttle(updateSpeed, 250))
  torrent.on('upload', throttle(updateSpeed, 250))
  setInterval(updateSpeed, 5000)
  updateSpeed()
  
   // Render all files into to the page
   torrent.files.forEach(function (file) {
    file.appendTo('.log')
  })


  //var file = torrent.files.find(function (file){
  //  return file.name.endsWith('.mp4')
  //});
  //
  //file.appendTo('.log');
  
}

function updateSpeed(){
  var progress = (100 * _Torrent.progress).toFixed(1);
  
  var rem;
  if(_Torrent.done){
    rem = 'Done.';
  }else{
    rem = moment.duration(_Torrent.timeRemaining / 1000, 'seconds').humanize()
    rem = rem[0].toUpperCase() + rem.substring(1) + ' remaining.'
  }

  util.updateSpeed(
    '<b>Peers:</b> ' + _Torrent.numPeers + ' ' +
    '<b>Progress:</b> ' + progress + '% ' +
    '<b>Download speed:</b> ' + prettierBytes(client.downloadSpeed) + '/s ' +
    '<b>Upload speed:</b> ' + prettierBytes(client.uploadSpeed) + '/s ' +
    '<b>ETA:</b> ' + rem
  );

  // fix download zip
  // downloadAs.zip(_Torrent);
}
@ChrisMichaelPerezSantiago ChrisMichaelPerezSantiago changed the title Problems to play mkv video format Problems to play mkv and mp4 video format Apr 27, 2019
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 5, 2019

From the WebTorrent FAQ:

Why does browser downloading not work? I see no peers!

It does work! But you can't just use any random magnet uri or .torrent file. The torrent must be seeded by a WebRTC-capable client, i.e. WebTorrent Desktop, Vuze, webtorrent-hybrid, Playback, instant.io, or βTorrent.

In the browser, WebTorrent can only download torrents that are explicitly seeded to web peers via a WebRTC-capable client. Desktop torrent clients need to support WebRTC to connect to web browsers.

@feross feross closed this May 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2019
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
2 participants
You can’t perform that action at this time.