{"id":30208356,"url":"https://github.com/diffusionstudio/webcodecs-scroll-sync","last_synced_at":"2025-08-15T19:04:43.149Z","repository":{"id":309224409,"uuid":"1035407095","full_name":"diffusionstudio/webcodecs-scroll-sync","owner":"diffusionstudio","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-10T13:33:04.000Z","size":9,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-10T17:45:16.863Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/diffusionstudio.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-10T10:31:40.000Z","updated_at":"2025-08-10T14:49:09.000Z","dependencies_parsed_at":"2025-08-10T17:45:18.317Z","dependency_job_id":"b8d9a2ba-7393-426b-a3a9-cfd199e6f383","html_url":"https://github.com/diffusionstudio/webcodecs-scroll-sync","commit_stats":null,"previous_names":["diffusionstudio/webcodecs-scroll-sync"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/diffusionstudio/webcodecs-scroll-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffusionstudio%2Fwebcodecs-scroll-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffusionstudio%2Fwebcodecs-scroll-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffusionstudio%2Fwebcodecs-scroll-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffusionstudio%2Fwebcodecs-scroll-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diffusionstudio","download_url":"https://codeload.github.com/diffusionstudio/webcodecs-scroll-sync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diffusionstudio%2Fwebcodecs-scroll-sync/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270278774,"owners_count":24557204,"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","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-08-13T17:25:11.711Z","updated_at":"2025-08-14T18:03:10.688Z","avatar_url":"https://github.com/diffusionstudio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webcodecs-scroll-sync\n\nA video decoder that synchronizes video playback with scroll position using the WebCodecs API.\n\n## Dependencies\n\nThis project requires **mediabunny** as a dependency:\n\n```bash\nnpm install mediabunny\n```\n\n## Files Overview\n\n- `decoder.ts` - Core `FrameDecoder` class that handles video decoding and buffering\n- `canvas.tsx` - React component example showing integration with scroll events\n- `utils.ts` - Utility functions (assertion helper)\n\n## Basic Usage\n\n### 1. Initialize the Decoder\n\nThe `FrameDecoder` must be initialized with a video URL:\n\n```javascript\nimport { FrameDecoder } from './decoder';\n\nconst frameDecoder = new FrameDecoder();\n\n// Initialize with video URL\nawait frameDecoder.init('https://example.com/your-video.mp4');\n```\n\n### 2. Seek to Video Position\n\nUse the `seek()` method to jump to specific video positions based on scroll:\n\n```javascript\n// Seek to 50% through the video\nframeDecoder.seek(0.5);\n\n// Get current frame for rendering\nconst currentFrame = frameDecoder.frame;\n```\n\n### 3. Render Frames\n\nDraw the current frame to a canvas:\n\n```javascript\nconst canvas = document.getElementById('myCanvas');\nconst ctx = canvas.getContext('2d');\n\nconst drawFrame = () =\u003e {\n  ctx.clearRect(0, 0, canvas.width, canvas.height);\n  frameDecoder.drawFrame(ctx, canvas.width, canvas.height);\n  requestAnimationFrame(drawFrame);\n};\n\ndrawFrame();\n```\n\n## React Example\n\nThe included `canvas.tsx` demonstrates a complete React implementation with scroll synchronization:\n\n```jsx\nimport { Canvas } from './canvas';\n\nfunction App() {\n  return (\n    \u003cdiv\u003e\n      \u003cCanvas src=\"https://example.com/your-video.mp4\" /\u003e\n      {/* Your scrollable content */}\n    \u003c/div\u003e\n  );\n}\n```\n\n## Framework Agnostic Usage\n\nWhile `canvas.tsx` shows a React example, the core decoder can be used with any JavaScript framework:\n\n### Vanilla JavaScript\n```javascript\nimport { FrameDecoder } from './decoder';\n\nconst decoder = new FrameDecoder();\nawait decoder.init('your-video-url.mp4');\n\nwindow.addEventListener('scroll', () =\u003e {\n  const scrollFraction = window.scrollY / (document.documentElement.scrollHeight - window.innerHeight);\n  decoder.seek(scrollFraction);\n});\n```\n\n## Key Features\n\n- **Efficient Buffering**: Maintains optimal frame buffer based on current playback position\n- **Smooth Seeking**: Binary search algorithms for fast frame lookup\n- **Memory Management**: Automatic cleanup of unused video frames\n- **Bidirectional Playback**: Optimized for both forward and backward seeking\n- **High Performance**: Uses WebCodecs API for hardware-accelerated video decoding\n\n**Note**: The required buffer range is highly dependent on the density of keyframes in your video footage. Videos with more frequent keyframes will perform better with this decoder.\n\n## Browser Support\n\nRequires browsers with WebCodecs API support:\n- Chrome 94+\n- Edge 94+\n- Opera 80+\n- Firefox 130+\n- Safari 16.4+\n\n(Firefox for Andriod is not supported)\n\n## Cleanup\n\nAlways call `destroy()` when done to free resources:\n\n```javascript\n// Cleanup when component unmounts or page unloads\nframeDecoder.destroy();\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiffusionstudio%2Fwebcodecs-scroll-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiffusionstudio%2Fwebcodecs-scroll-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiffusionstudio%2Fwebcodecs-scroll-sync/lists"}