Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ffmpeg operate directly on temp file #162

Merged
merged 2 commits into from
Jan 30, 2025
Merged

Conversation

ramen
Copy link
Contributor

@ramen ramen commented Jan 29, 2025

In an attempt to figure out why .m4a files were resulting in empty transcripts, I tried running ffmpeg via the command line, and it had no problem converting it to a .wav file with the audio intact. My understanding is that the main reason .m4a files are different is that their metadata gets stored at the end of the file. Since our load_audio function was piping audio into ffmpeg, I think this was defeating ffmpeg's file format detection; it had no file extension since it was reading from stdin, and it could not determine the file type by looking at the beginning of the stream.

I tried passing the filename instead of a file stream into the ffmpeg library, and sure enough, .m4a files are detected and handled properly. Since we use temp files to pass the audio from the web service to the worker, we're already guaranteed to have a file on disk for our use cases. So, I adapted load_audio to accept either a file object or a filename string, and made our web service pass the filename instead. Fixes #160

@ramen ramen requested a review from mikeylove January 29, 2025 23:20
Copy link
Contributor

@mikeylove mikeylove left a comment

Choose a reason for hiding this comment

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

wondering if it's maybe worth considering just making load_audio take a string file path only? nice to do both, i only got a little mixed up in wrapping my head around the few different places in that method that accounted for both argument types. 🤔

that aside, 🚢

@ramen
Copy link
Contributor Author

ramen commented Jan 30, 2025

wondering if it's maybe worth considering just making load_audio take a string file path only? nice to do both, i only got a little mixed up in wrapping my head around the few different places in that method that accounted for both argument types. 🤔

It's true that we only need the file path version at this point, but I'm not really a fan of APIs that only work with files on disk. I'll clean up the logic a bit so hopefully it's not so hard to follow.

@mikeylove
Copy link
Contributor

It's true that we only need the file path version at this point, but I'm not really a fan of APIs that only work with files on disk. I'll clean up the logic a bit so hopefully it's not so hard to follow.

that little change made a big difference 🎸

@ramen
Copy link
Contributor Author

ramen commented Jan 30, 2025

that little change made a big difference 🎸

🙌 Thanks!

@ramen ramen merged commit 7973361 into main Jan 30, 2025
2 checks passed
@ramen ramen deleted the ffmpeg-direct-file-access branch January 30, 2025 16:19
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.

[bug]: Processing .m4a files results in empty transcript
2 participants