Skip to content

Commit

Permalink
Merge pull request #336 from mhy-max/main
Browse files Browse the repository at this point in the history
fix: av-recorder closing video/audio track export error
  • Loading branch information
hughfenghen authored Dec 6, 2024
2 parents 93f9787 + 5780270 commit 102d4a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-grapes-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@webav/av-recorder': patch
---

fix: av-recorder closing video/audio track export error #335
15 changes: 11 additions & 4 deletions packages/av-recorder/src/av-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,20 @@ function startRecord(
let stopEncodeVideo: TClearFn | null = null;
let stopEncodeAudio: TClearFn | null = null;

const [hasVideoTrack, hasAudioTrack] = [
opts.streams.video != null,
opts.streams.audio != null && opts.audio != null,
];

const recoder = recodemux({
video: { ...opts.video, bitrate: opts.bitrate ?? 3_000_000 },
audio: opts.audio,
video: hasVideoTrack
? { ...opts.video, bitrate: opts.bitrate ?? 3_000_000 }
: null,
audio: hasAudioTrack ? opts.audio : null,
});

let stoped = false;
if (opts.streams.video != null) {
if (hasVideoTrack) {
let lastVf: VideoFrame | null = null;
let autoInsertVFTimer = 0;
const emitVf = (vf: VideoFrame) => {
Expand Down Expand Up @@ -290,7 +297,7 @@ function startRecord(
};
}

if (opts.audio != null && opts.streams.audio != null) {
if (hasAudioTrack) {
stopEncodeAudio = autoReadStream(opts.streams.audio, {
onChunk: async (ad: AudioData) => {
if (stoped) {
Expand Down

0 comments on commit 102d4a3

Please sign in to comment.