{"id":17399263,"url":"https://github.com/feross/mediasource","last_synced_at":"2025-04-04T23:09:16.546Z","repository":{"id":51105059,"uuid":"41263083","full_name":"feross/mediasource","owner":"feross","description":"MediaSource API as a node.js Writable stream","archived":false,"fork":false,"pushed_at":"2021-05-23T19:05:41.000Z","size":1084,"stargazers_count":138,"open_issues_count":3,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T22:14:03.390Z","etag":null,"topics":["browser","javascript","mediasource","nodejs","stream","streaming","streams","video"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feross.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-23T19:08:02.000Z","updated_at":"2025-01-06T01:42:50.000Z","dependencies_parsed_at":"2022-09-05T06:41:51.541Z","dependency_job_id":null,"html_url":"https://github.com/feross/mediasource","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmediasource","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmediasource/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmediasource/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fmediasource/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/mediasource/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261612,"owners_count":20910108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","javascript","mediasource","nodejs","stream","streaming","streams","video"],"created_at":"2024-10-16T15:14:25.473Z","updated_at":"2025-04-04T23:09:16.517Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","readme":"# mediasource [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[travis-image]: https://img.shields.io/travis/feross/mediasource/master.svg\n[travis-url]: https://travis-ci.org/feross/mediasource\n[npm-image]: https://img.shields.io/npm/v/mediasource.svg\n[npm-url]: https://npmjs.org/package/mediasource\n[downloads-image]: https://img.shields.io/npm/dm/mediasource.svg\n[downloads-url]: https://npmjs.org/package/mediasource\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### MediaSource API as a node.js Writable stream\n\n[![Sauce Test Status](https://saucelabs.com/browser-matrix/mediasource.svg)](https://saucelabs.com/u/mediasource)\n\nStream video/audio into a `\u003cvideo\u003e` or `\u003caudio\u003e` tag by attaching node.js Writable streams.\n\nThis package is used by [WebTorrent](http://webtorrent.io) (along with other approaches)\nto support media streaming.\n\n## install\n\n```\nnpm install mediasource\n```\n\n## usage\n\n```js\nvar MediaElementWrapper = require('mediasource')\n\nfunction createElem (tagName) {\n  var elem = document.createElement(tagName)\n  elem.controls = true\n  elem.autoplay = true // for chrome\n  elem.play() // for firefox\n  document.body.appendChild(elem)\n  return elem\n}\n\nvar elem = createElem('video')\n\nvar readable = // ... get a readable stream from somewhere\nvar wrapper = new MediaElementWrapper(elem)\n// The correct mime type, including codecs, must be provided\nvar writable = wrapper.createWriteStream('video/webm; codecs=\"vorbis, vp8\"')\n\nelem.addEventListener('error', function () {\n  // listen for errors on the video/audio element directly\n  var errorCode = elem.error\n  var detailedError = wrapper.detailedError\n  // wrapper.detailedError will often have a more detailed error message\n})\n\nwritable.on('error', function (err) {\n  // listening to the stream 'error' event is optional\n})\n\nreadable.pipe(writable)\n\n// media should start playing now!\n```\n\n### advanced usage\n\n`wrapper.createWriteStream()` can be called multiple times if different tracks (e.g. audio and video) need to\nbe passed in separate streams. Each call should be made with the correct mime type.\n\nInstead of a mime type, an existing MediaSourceStream (as returned by `wrapper.createWriteStream()`) can be\npassed as the single argument to `wrapper.createWriteStream()`, which will cause the existing stream to be\nreplaced by the newly returned stream. This is useful when you want to cancel the existing stream\nand replace it with a new one, e.g. when seeking.\n\n### should one use this package?\n\nNaively using this package will not work for many video formats, nor will it support\nseeking. For an approach that is more likely to work for all video files, and\nsupports seeking, take a look at\n[videostream](https://github.com/jhiesey/videostream).\n\nOr for a package that tries multiple approaches, including `videostream` and this\npackage (`mediasource`), as well as a Blob API (non-streaming) approach, and works\nfor many non-video file types, consider\n[render-media](https://github.com/feross/render-media).\n\n### options\n\n#### opts.bufferDuration\n\nSpecify how many seconds of media should be put into the browser's buffer before applying backpressure.\n\n### errors\n\nHandle errors by listening to the `'error'` event on the `\u003cvideo\u003e` or `\u003caudio\u003e` tag.\n\nSome (but not all) errors will also cause `wrapper.detailedError` to be set to an error value that has\na more informative error message.\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fmediasource","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Fmediasource","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fmediasource/lists"}