diff --git a/dev/live.html b/dev/live.html
index bdd2fc2..d21faec 100644
--- a/dev/live.html
+++ b/dev/live.html
@@ -19,7 +19,7 @@
button.addEventListener('click', async () => {
const stream = await navigator.mediaDevices.getDisplayMedia({ video: true, audio: false });
const videoTrack = stream.getVideoTracks()[0];
- const audioTrack = null;//stream.getAudioTracks()[0];
+ const audioTrack = stream.getAudioTracks()[0];
const output = new Mediabunny.Output({
target: new Mediabunny.BufferTarget(),
@@ -29,7 +29,7 @@
let audioSource = null;
if (videoTrack) {
videoSource = new Mediabunny.MediaStreamVideoTrackSource(videoTrack, {
- codec: 'avc',
+ codec: 'vp9',
bitrate: Mediabunny.QUALITY_MEDIUM,
sizeChangeBehavior: 'passThrough',
});
@@ -40,13 +40,13 @@
}
if (audioTrack) {
audioSource = new Mediabunny.MediaStreamAudioTrackSource(audioTrack, {
- codec: 'mp3',
+ codec: 'opus',
bitrate: Mediabunny.QUALITY_MEDIUM
});
audioSource.errorPromise.catch((d) => console.log("Hello!!???", d));
- //output.addAudioTrack(audioSource);
+ output.addAudioTrack(audioSource);
}
await output.start();
diff --git a/src/media-source.ts b/src/media-source.ts
index c3b4604..05eb4e6 100644
--- a/src/media-source.ts
+++ b/src/media-source.ts
@@ -1076,6 +1076,8 @@ export class MediaStreamVideoTrackSource extends VideoSource {
private _lastVideoFrame: VideoFrame | null = null;
/** @internal */
private _timerHandle: UnthrottledTimerHandle | null = null;
+ /** @internal */
+ private _videoElement: HTMLVideoElement | null = null;
/** A promise that rejects upon any error within this source. This promise never resolves. */
get errorPromise() {
@@ -1160,12 +1162,13 @@ export class MediaStreamVideoTrackSource extends VideoSource {
while (now - lastFrameTime > 1000 / frameRate) {
lastFrameTime += 1000 / frameRate;
const timestamp = firstVideoFrameTimestamp + frameCount / frameRate;
- const clone = new VideoFrame(this._lastVideoFrame, {
+
+ const frame = new VideoFrame(this._videoElement ?? this._lastVideoFrame, {
timestamp: 1e6 * timestamp,
duration: 1e6 / frameRate,
});
- addVideoFrame(clone, now);
+ addVideoFrame(frame, now);
}
};
@@ -1298,8 +1301,44 @@ export class MediaStreamVideoTrackSource extends VideoSource {
};
mediaStreamTrackProcessorWorker!.addEventListener('message', this._workerListener);
+ } else if (frameRate !== null) {
+ // No MediaStreamTrackProcessor support at all (e.g. Firefox), but we have a frame rate, so we can
+ // manually sample from a hidden