Skip to content

fix(recording): preserve mic companion audio in editor/export#280

Merged
webadderall merged 1 commit intowebadderallorg:mainfrom
meiiie:fix/microphone-companion-audio
Apr 20, 2026
Merged

fix(recording): preserve mic companion audio in editor/export#280
webadderall merged 1 commit intowebadderallorg:mainfrom
meiiie:fix/microphone-companion-audio

Conversation

@meiiie
Copy link
Copy Markdown
Collaborator

@meiiie meiiie commented Apr 19, 2026

Pull Request Template

Description

Fix recordings where the source video already contains audio but the microphone is saved as a companion sidecar file. The editor and export pipeline were dropping the mic track in that case, so microphone audio never appeared in playback or final exports.

Motivation

Issue #250 reports that the microphone companion file exists on disk but is ignored by the editor/export pipeline. The companion-audio resolver returned no fallback sources whenever the video had any embedded audio stream, which hid separated microphone tracks from native and browser recording layouts.

Type of Change

  • New Feature
  • Bug Fix
  • Refactor / Code Cleanup
  • Documentation Update
  • Other (please specify)

Related Issue(s)

Screenshots / Video

N/A (backend audio pipeline fix)

Testing Guide

  • npx vitest --run electron/ipc/recording/diagnostics.test.ts src/lib/mediaTiming.test.ts
  • Regression coverage verifies:
    1. companion files are used when the video has no embedded audio
    2. embedded source audio is preserved and the mic companion is added when both exist

Checklist

  • I have performed a self-review of my code.
  • I have added any necessary screenshots or videos.
  • I have linked related issue(s) and updated the changelog if applicable.

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for audio fallback path detection with various audio stream scenarios.
  • Bug Fixes

    • Improved audio source detection to correctly identify embedded audio in videos and select appropriate fallback audio paths accordingly.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 19, 2026

📝 Walkthrough

Walkthrough

This change adds comprehensive test coverage for getCompanionAudioFallbackPaths functionality and updates its logic to properly detect and handle embedded versus companion microphone audio based on ffmpeg probe results. The function now filters paths appropriately based on whether the video contains embedded audio.

Changes

Cohort / File(s) Summary
Test Suite for Audio Path Detection
electron/ipc/recording/diagnostics.test.ts
New Vitest test suite with two scenarios: validates function behavior when ffmpeg detects only video stream (no embedded audio) and when audio stream is present (embedded audio exists).
Audio Fallback Path Resolution Logic
electron/ipc/recording/diagnostics.ts
Import reordering and updated getCompanionAudioFallbackPaths implementation: now filters and deduplicates mic companion paths when embedded audio exists, or returns deduplicated usable paths when no embedded audio is detected.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

Checked

Poem

🐰 Hopping through audio streams with care,
Mic paths detected in the air,
Embedded or separate, we now know,
Tests verify the proper flow! 🎵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing a bug where microphone companion audio was being dropped during editor and export operations.
Description check ✅ Passed The description comprehensively covers the purpose, motivation, type of change, related issues, testing guidance, and includes all key checklist items completed.
Linked Issues check ✅ Passed The PR directly addresses issue #250 by fixing the companion-audio resolver to include mic companion files when embedded audio exists, resolving the reported bug of missing microphone audio in editor and exports.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the audio companion file handling logic and adding comprehensive test coverage; no extraneous modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
electron/ipc/recording/diagnostics.test.ts (1)

70-134: Consider adding coverage for the "embedded audio, no mic companion" branch.

The two tests nicely cover the happy paths, but the new branch at diagnostics.ts lines 135–137 — where embedded audio is detected and the only companion is .system.wav (no mic), causing the function to return [] — is not exercised. Given that this branch silently drops the system sidecar, a regression test would make the contract explicit and guard against future re-introductions of the original bug.

🧪 Suggested additional test sketch
it("returns an empty array when embedded audio exists but no mic companion is present", async () => {
	const videoPath = path.join(tempRoot, "recording.mp4");
	const systemPath = path.join(tempRoot, "recording.system.wav");

	await Promise.all([
		fs.writeFile(videoPath, "video"),
		fs.writeFile(systemPath, "system"),
	]);

	execFileMock.mockImplementation((_f, _a, _o, callback: ExecFileCallback) => {
		const error = new Error("ffmpeg probe found embedded audio") as Error & { stderr?: string };
		error.stderr = "Stream `#0`:1: Audio: aac";
		callback(error, "", error.stderr);
	});

	const { getCompanionAudioFallbackPaths } = await import("./diagnostics");
	await expect(getCompanionAudioFallbackPaths(videoPath)).resolves.toEqual([]);
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@electron/ipc/recording/diagnostics.test.ts` around lines 70 - 134, Add a new
test exercising the branch in getCompanionAudioFallbackPaths where embedded
audio is detected but only the .system.wav companion exists: create video and
system sidecar files (use tempRoot), mock execFileMock to call back with stderr
"Stream `#0`:1: Audio: aac" (to simulate embedded audio), import
getCompanionAudioFallbackPaths from "./diagnostics", and assert the call
resolves to an empty array; name it something like "returns an empty array when
embedded audio exists but no mic companion is present" so it clearly covers the
diagnostics.ts embedded-audio-without-mic branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@electron/ipc/recording/diagnostics.test.ts`:
- Around line 70-134: Add a new test exercising the branch in
getCompanionAudioFallbackPaths where embedded audio is detected but only the
.system.wav companion exists: create video and system sidecar files (use
tempRoot), mock execFileMock to call back with stderr "Stream `#0`:1: Audio: aac"
(to simulate embedded audio), import getCompanionAudioFallbackPaths from
"./diagnostics", and assert the call resolves to an empty array; name it
something like "returns an empty array when embedded audio exists but no mic
companion is present" so it clearly covers the diagnostics.ts
embedded-audio-without-mic branch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 54aae8a6-88e4-468a-a634-331ab952fdec

📥 Commits

Reviewing files that changed from the base of the PR and between daf99c0 and cf67648.

📒 Files selected for processing (2)
  • electron/ipc/recording/diagnostics.test.ts
  • electron/ipc/recording/diagnostics.ts

@webadderall webadderall merged commit bfe0cbe into webadderallorg:main Apr 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microphone audio recorded but not available in editor or export

2 participants