{"id":13430945,"url":"https://github.com/feross/capture-frame","last_synced_at":"2025-06-28T14:36:06.834Z","repository":{"id":54822630,"uuid":"68336152","full_name":"feross/capture-frame","owner":"feross","description":"Capture video screenshot from a `\u003cvideo\u003e` tag (at the current time)","archived":false,"fork":false,"pushed_at":"2020-08-18T21:18:04.000Z","size":659,"stargazers_count":115,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-02T05:38:46.496Z","etag":null,"topics":["browser","canvas","capture","frame","javascript","screenshot","video"],"latest_commit_sha":null,"homepage":"","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":"2016-09-15T22:26:20.000Z","updated_at":"2024-02-12T00:58:12.000Z","dependencies_parsed_at":"2022-08-14T03:50:51.766Z","dependency_job_id":null,"html_url":"https://github.com/feross/capture-frame","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fcapture-frame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fcapture-frame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fcapture-frame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Fcapture-frame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/capture-frame/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232810831,"owners_count":18579929,"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","canvas","capture","frame","javascript","screenshot","video"],"created_at":"2024-07-31T02:00:59.189Z","updated_at":"2025-01-07T02:22:49.043Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# capture-frame [![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/capture-frame/master.svg\n[travis-url]: https://travis-ci.org/feross/capture-frame\n[npm-image]: https://img.shields.io/npm/v/capture-frame.svg\n[npm-url]: https://npmjs.org/package/capture-frame\n[downloads-image]: https://img.shields.io/npm/dm/capture-frame.svg\n[downloads-url]: https://npmjs.org/package/capture-frame\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### Capture video screenshot from a `\u003cvideo\u003e` tag (at the current time)\n\n[![Sauce Test Status](https://saucelabs.com/browser-matrix/capture-frame.svg)](https://saucelabs.com/u/capture-frame)\n\nWorks in the browser with [browserify](http://browserify.org/)! This module is used by [WebTorrent Desktop](http://webtorrent.io/desktop).\n\n## install\n\n```\nnpm install capture-frame\n```\n\n## usage\n\n### simple example\n\n```js\nconst captureFrame = require('capture-frame')\n\nconst frame = captureFrame('.video') // Buffer that contains .png file data\n\n// show the captured video frame in the DOM\nconst image = document.createElement('img')\nimage.width = frame.width\nimage.height = frame.height\nimage.src = window.URL.createObjectURL(new window.Blob([frame.image]))\ndocument.body.appendChild(image)\n```\n\n### complete example\n\n```js\nconst captureFrame = require('capture-frame')\n\nconst video = document.createElement('video')\nvideo.addEventListener('canplay', onCanPlay)\n\nvideo.volume = 0\nvideo.autoplay = true\nvideo.muted = true // most browsers block autoplay unless muted\nvideo.setAttribute('crossOrigin', 'anonymous') // optional, when cross-domain\nvideo.src = 'http://example.com/test.mp4'\n\nfunction onCanPlay () {\n  video.removeEventListener('canplay', onCanPlay)\n  video.addEventListener('seeked', onSeeked)\n\n  video.currentTime = 2 // seek 2 seconds into the video\n}\n\nfunction onSeeked () {\n  video.removeEventListener('seeked', onSeeked)\n\n  const frame = captureFrame(video)\n\n  // unload video element, to prevent memory leaks\n  video.pause()\n  video.src = ''\n  video.load()\n\n  // show the captured image in the DOM\n  const image = document.createElement('img')\n  image.width = frame.width\n  image.height = frame.height\n  image.src = window.URL.createObjectURL(new window.Blob([frame.image]))\n  document.body.appendChild(image)\n}\n```\n\n## api\n\n### `frame = captureFrame(video, [format])`\n\nCapture a video frame the the video tag specified by `video`. This can be a\nreference to a video element in the page, or a string CSS selector. This must\nrefer to a video element.\n\nOptionally, specify a `format` for the image to be captured in. Must be one of\n\"png\", \"jpeg\", or \"webp\".\n\nThe returned object, `frame`, has three properties:\n\n#### `frame.image`\n\nThe captured image, as a `Buffer`.\n\n#### `frame.width`\n\nThe captured image's width, as a `number`.\n\n#### `frame.height`\n\nThe captured image's height, as a `number`.\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fcapture-frame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Fcapture-frame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Fcapture-frame/lists"}