Skip to content

fix(audio): map webm and mp4 container mime types to audio extensions - #1030

Open
mrmorgan-i wants to merge 1 commit into
prism-php:mainfrom
mrmorgan-i:fix/audio-container-mime-extensions
Open

fix(audio): map webm and mp4 container mime types to audio extensions#1030
mrmorgan-i wants to merge 1 commit into
prism-php:mainfrom
mrmorgan-i:fix/audio-container-mime-extensions

Conversation

@mrmorgan-i

Copy link
Copy Markdown

Description

finfo reports browser MediaRecorder output as video/webm, since WebM is a container format. That isn't in GeneratesAudioFilename's match list, so it falls through to default => 'mp3' and the file gets uploaded as audio.mp3 with WebM bytes inside it. OpenAI fails to parse it with:

OpenAI Error [400]: invalid_request_error - Audio file might be corrupted or unsupported

Same thing happens with video/mp4, which is what Safari's MediaRecorder produces.

This adds the container types to the existing match list. The default => 'mp3' fallback is unchanged, along with the three tests covering it.

Related to #981. That issue covers the audio/x-wav alias, and #1001 handles it at the Media layer, which makes sense for aliases that are for sure audio. video/webm is different because it's a truthful mime type, and normalizing it in Media would break genuine video input such as Gemini's. So this only touches the audio filename helper, and the two changes shouldn't conflict.

wishborn added a commit to Particle-Academy/prism that referenced this pull request Aug 12, 2026
Upstream PR by @mrmorgan-i. Browsers report the CONTAINER type, so an
audio-only MediaRecorder clip arrives as video/webm or video/mp4 and was
being written out as audio.mp3 — the wrong extension on every browser
recording, which providers then reject or mis-transcode.

Applied upstream's mapping (video/mp4, video/ogg, video/webm) plus one gap
it does not cover: MediaRecorder attaches codec parameters, so the very
mime types this fix targets arrive as "audio/webm;codecs=opus" and fell
straight through to the mp3 default anyway. The mime type is now reduced to
its bare type and lowercased before matching, so the fix works on real
browser output rather than only on the canonical strings.
@wishborn

Copy link
Copy Markdown

@mrmorgan-i — this is now released in the maintained fork (particle-academy/prism v0.112.0), which is a drop-in for prism-php/prism.

Your mapping went in as-is, plus one gap it didn't cover: MediaRecorder attaches codec parameters, so the very types this targets arrive as audio/webm;codecs=opus and still fell through to the mp3 default. The mime type is now reduced to its bare form before matching, so it works on real browser output.

Thanks for the fix.

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.

2 participants