Skip to content

fix: transcode audio to MP3 instead of stream-copy in ffmpeg#119

Open
sweetmantech wants to merge 2 commits intomainfrom
fix/ffmpeg-wav-to-mp3-transcode
Open

fix: transcode audio to MP3 instead of stream-copy in ffmpeg#119
sweetmantech wants to merge 2 commits intomainfrom
fix/ffmpeg-wav-to-mp3-transcode

Conversation

@sweetmantech
Copy link
Copy Markdown
Contributor

@sweetmantech sweetmantech commented Mar 31, 2026

Summary

  • ffmpeg -c copy fails when input is WAV with .mp3 extension (common with Slack uploads)
  • Replace with -c:a libmp3lame -q:a 2 to transcode any audio format to MP3

Context

User-attached audio from Slack can be WAV files. The pipeline saves them as .mp3 but ffmpeg detects the actual codec (pcm_s16le) and refuses to stream-copy into an MP3 container.

Test plan

  • 209/209 tests pass
  • E2E: Upload WAV file via Slack → verify video renders successfully

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Audio clipping has been updated to re-encode segments with improved quality settings during upload, replacing the previous stream copying method for better consistency.

WAV files with .mp3 extension cause ffmpeg -c copy to fail with
"Invalid audio stream" because PCM audio can't be stream-copied
into an MP3 container. Use libmp3lame transcoding instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Warning

Rate limit exceeded

@sweetmantech has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 6 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 6 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aca0229f-b80a-46c6-88e4-b4c5d4bd8e48

📥 Commits

Reviewing files that changed from the base of the PR and between b32f8ca and 6b9824c.

📒 Files selected for processing (1)
  • src/tasks/createContentTask.ts
📝 Walkthrough

Walkthrough

Modified FFmpeg command in audio clipping functionality to re-encode audio segments as MP3 with libmp3lame encoder at quality level 2, replacing the previous stream copy approach. The overall function flow and interface remain unchanged.

Changes

Cohort / File(s) Summary
Audio Processing Configuration
src/content/generateAudioVideo.ts
Updated FFmpeg audio clipping parameters from -c copy (no re-encoding) to -c:a libmp3lame -q:a 2 (MP3 re-encoding with quality level 2).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hops with glee, the audio flows,
From copy-paste to libmp3 prose,
Quality level two, a cleaner sound,
Where MP3 magic now is found! 🎵

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: switching from stream-copy to MP3 transcoding in ffmpeg, which is the primary fix for handling WAV files misnamed as MP3.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ffmpeg-wav-to-mp3-transcode

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

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/content/generateAudioVideo.ts (1)

106-114: ⚠️ Potential issue | 🔴 Critical

Ensure libmp3lame encoder is available in the FFmpeg build before deployment.

The code change now explicitly requires the libmp3lame encoder (-c:a libmp3lame), but it is not available in the current runtime environment. The clipping function will fail at runtime with an "Unknown encoder" error. Either add libmp3lame to the FFmpeg build, use a different encoder that is available, or re-evaluate the transcoding approach.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/content/generateAudioVideo.ts` around lines 106 - 114, The ffmpeg
invocation in generateAudioVideo.ts explicitly requests the libmp3lame encoder
in the execFileAsync call (args include "-c:a", "libmp3lame"), which will fail
if that encoder isn't present; either update the runtime FFmpeg build to include
libmp3lame or change the encoder argument to one available in your environment
(e.g., "aac" or "libopus") and ensure clippedPath/extension and any downstream
consumers match the chosen codec; update the execFileAsync call, related
variable handling (inputPath, clippedPath) and deployment/docs to reflect the
chosen encoder so runtime failures are avoided.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/content/generateAudioVideo.ts`:
- Around line 106-114: The ffmpeg invocation in generateAudioVideo.ts explicitly
requests the libmp3lame encoder in the execFileAsync call (args include "-c:a",
"libmp3lame"), which will fail if that encoder isn't present; either update the
runtime FFmpeg build to include libmp3lame or change the encoder argument to one
available in your environment (e.g., "aac" or "libopus") and ensure
clippedPath/extension and any downstream consumers match the chosen codec;
update the execFileAsync call, related variable handling (inputPath,
clippedPath) and deployment/docs to reflect the chosen encoder so runtime
failures are avoided.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d62c363-55b9-4b43-9c47-d6057a3ab47a

📥 Commits

Reviewing files that changed from the base of the PR and between d974928 and b32f8ca.

📒 Files selected for processing (1)
  • src/content/generateAudioVideo.ts

10 minutes was too short — WAV transcoding + lipsync video generation
can exceed 10 min for larger audio files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant