|
7 | 7 | body { |
8 | 8 | background-color: #333; |
9 | 9 | color: #fff; |
| 10 | + font-size: large; |
10 | 11 | } |
| 12 | + |
| 13 | + a { |
| 14 | + color: #0099ff; /* Light blue */ |
| 15 | + } |
| 16 | + |
| 17 | + a:hover { |
| 18 | + color: #00ccff; /* Slightly lighter blue */ |
| 19 | + } |
| 20 | + |
| 21 | + ul, p { |
| 22 | + margin-top: 6px; |
| 23 | + margin-bottom: 6px; |
| 24 | + } |
| 25 | + |
11 | 26 | </style> |
12 | 27 | </head> |
13 | 28 | <body> |
| 29 | +<p> |
| 30 | + Proof of concept that loads a video file and uses WebCodecs to convert it to a |
| 31 | + <code><a href="https://www.w3.org/TR/mediacapture-streams/#mediastream">MediaStream</a></code> where it can be set as a |
| 32 | + VideoElement <code>srcObject</code> or sent to a WebRTC <code>RTCPeerConnection</code> |
| 33 | +</p> |
| 34 | + Notes: |
| 35 | + <ul> |
| 36 | + <li><a href="https://github.com/gpac/mp4box.js">mp4box.js</a> is used for demuxing.</li> |
| 37 | + <li>Doesn't include a buffer management system to keep audio & video in sync</li> |
| 38 | + <li>Only works if the source file contains a single audio and video track</li> |
| 39 | + </ul> |
| 40 | +</p> |
| 41 | +<p> |
| 42 | + See <a href="https://webrtcHacks.com">webrtcHacks</a> for more details and commentary. |
| 43 | +</p> |
| 44 | +<p> |
| 45 | + Heavily inspired by the <a href="https://github.com/w3c/webcodecs">W3C WebCodecs</a> work and their <a |
| 46 | + href="https://w3c.github.io/webcodecs/samples/audio-video-player/audio_video_player.html">Audio and Video Player |
| 47 | + sample</a>. |
| 48 | + Video "<a href="https://peach.blender.org/">Big Buck Bunny</a>" by Blender Foundation, used under <a |
| 49 | + href="https://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>. |
| 50 | +</p> |
14 | 51 | <button>Play Big Buck Bunny</button> |
15 | 52 | <input type="file" id="videoFile" accept="video/*"> |
16 | 53 | <br/> |
|
21 | 58 | const video = document.querySelector('video'); |
22 | 59 |
|
23 | 60 | // Assumes file has both audio and video tracks |
24 | | - const videoTrackGenerator = new MediaStreamTrackGenerator({ kind: 'video' }); |
25 | | - const audioTrackGenerator = new MediaStreamTrackGenerator({ kind: 'audio' }); |
| 61 | + const videoTrackGenerator = new MediaStreamTrackGenerator({kind: 'video'}); |
| 62 | + const audioTrackGenerator = new MediaStreamTrackGenerator({kind: 'audio'}); |
26 | 63 |
|
27 | 64 | const stream = new MediaStream([videoTrackGenerator, audioTrackGenerator]); |
28 | 65 | video.srcObject = stream; |
29 | 66 |
|
30 | | - function start(file){ |
| 67 | + function start(file) { |
31 | 68 | bbbButton.disabled = true; |
32 | 69 | fileButton.disabled = true; |
33 | 70 |
|
|
39 | 76 | worker.postMessage({file, videoWriter, audioWriter}, [videoWriter, audioWriter]); |
40 | 77 | } |
41 | 78 |
|
42 | | - bbbButton.onclick = ()=> start('../BigBuckBunny_360p30.mp4'); |
43 | | - fileButton.onchange = ()=> start(fileButton.files[0]); |
| 79 | + const videoUrl = '../BigBuckBunny_360p30.mp4'; |
| 80 | + // const videoUrl = "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4"; // works |
| 81 | + bbbButton.onclick = () => start(videoUrl); |
| 82 | + fileButton.onchange = () => start(fileButton.files[0]); |
44 | 83 |
|
45 | 84 | </script> |
46 | 85 | </body> |
|
0 commit comments