rails / marcel

Find the mime type of files, examining file, filename and declared type
Apache License 2.0
386 stars 67 forks source link

Fix audio/webm files #58

Closed kiskoza closed 3 years ago

kiskoza commented 3 years ago

Hi. Recently I encountered a bug using Active Storage when I recorded some audio in a Chrome browser (only supported mimetype is audio/webm), uploaded it to the server and got it back as video/webm - which broke the frontend logic to show it in an audio player instead of a video player. During my investigation I found this gem and noticed that it doesn't know anything about audio/webm.

In the WebM Project docs, you can find the following information:

That means a video webm file should contain at least one video stream (but don't need to check for audios) and an audio webm file should contain at least one audio stream (but should not have any video streams - this rule should be after the video's). I added these rules to the tables.rb file with a new sample file for audio/webm

Is there anything else I need to add regarding these changes?

kiskoza commented 3 years ago

Thanks for the feedback, I added my changes to custom.xml and regenerated the tables (got the same result, but the new line for audio/webm moved to the audios) and force pushed all of it in one commit.

We should mention this rake task in a contribution guide to help future contributors, it was easier to make the changes there now I'm aware of this file :smile:

ClearlyClaire commented 2 years ago

This seems to break some webm files, for instance this one, presumably because the V_VP8 string appears after 4096 bytes.

kiskoza commented 2 years ago

hi @ClearlyClaire . thanks for raising this issue. I think we should scan the whole file for the signatures as the webm's container format doesn't have a strict order for the contained streams.

@gmcgibbon what do you think? is there a way to scan the whole file?