Skip to content

Commit 102d4a3

Browse files
authored
Merge pull request #336 from mhy-max/main
fix: av-recorder closing video/audio track export error
2 parents 93f9787 + 5780270 commit 102d4a3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.changeset/mean-grapes-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@webav/av-recorder': patch
3+
---
4+
5+
fix: av-recorder closing video/audio track export error #335

packages/av-recorder/src/av-recorder.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,20 @@ function startRecord(
242242
let stopEncodeVideo: TClearFn | null = null;
243243
let stopEncodeAudio: TClearFn | null = null;
244244

245+
const [hasVideoTrack, hasAudioTrack] = [
246+
opts.streams.video != null,
247+
opts.streams.audio != null && opts.audio != null,
248+
];
249+
245250
const recoder = recodemux({
246-
video: { ...opts.video, bitrate: opts.bitrate ?? 3_000_000 },
247-
audio: opts.audio,
251+
video: hasVideoTrack
252+
? { ...opts.video, bitrate: opts.bitrate ?? 3_000_000 }
253+
: null,
254+
audio: hasAudioTrack ? opts.audio : null,
248255
});
249256

250257
let stoped = false;
251-
if (opts.streams.video != null) {
258+
if (hasVideoTrack) {
252259
let lastVf: VideoFrame | null = null;
253260
let autoInsertVFTimer = 0;
254261
const emitVf = (vf: VideoFrame) => {
@@ -290,7 +297,7 @@ function startRecord(
290297
};
291298
}
292299

293-
if (opts.audio != null && opts.streams.audio != null) {
300+
if (hasAudioTrack) {
294301
stopEncodeAudio = autoReadStream(opts.streams.audio, {
295302
onChunk: async (ad: AudioData) => {
296303
if (stoped) {

0 commit comments

Comments
 (0)