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

Calling AudioSegment.export() with an integer bitrate causes Python subprocess exception #784

Open
rwmnau opened this issue Mar 23, 2024 · 1 comment

Comments

@rwmnau
Copy link

rwmnau commented Mar 23, 2024

Steps to reproduce

from pydub import AudioSegment
audio:AudioSegment = AudioSegment.from_file("./anyAudioFile.wav")
audio.export(out_f="./anyAudioFile.mp3", format="mp3", bitrate=50049) # using str(50049) instead works as expected

Expected behavior

Calling AudioSegment.export() with a bitrate value set to an integer (like 50049) should work as expected.

Actual behavior

This integer is passed directly to the Python subprocess.execute_child as an argument and throws an exception ("TypeError: expected str, bytes or os.PathLike object, not int") since the arguments collection only supports those types and doesn't know how to process an int. The .export() definition says it accepts any type for the bitrate parameter, and then extends the args collection for ffmpeg with that parameter in whatever type it's given. Python subprocess.execute_child then throws an exception because it doesn't allow an int arg.

Workaround

This issue can be worked around by converting the bitrate to a string before calling AudioSegment.export(), but this isn't clear in the documentation and could be enforced through the method definition. I'm passing an audio stream from pytube, which hands the bitrate back as an int by default, so it's something developers have to know to do.

Your System configuration

  • Python version: 3.11.4
  • Pydub version: 0.25.1
  • ffmpeg or avlib?: ffmpeg
  • ffmpeg/avlib version: 6.1.1-full_build-www.gyan.dev
  • Windows 11 x64 (23H2, Build 22631.3296)
  • VS Code 1.87.2
  • Running code within Flask 3.0.2

Is there an audio file you can include to help us reproduce?

Any audio file seems to produce this issue, it's a problem running the ffmpeg command with an integer parameter when Python expects all parameters to be strings/bytes/path.

@rwmnau
Copy link
Author

rwmnau commented Mar 25, 2024

I created a PR for this fix - not sure if I did this correctly and if there's something I missed, please let me know and I'll read and follow the guidance.

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

No branches or pull requests

1 participant