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

Reading audio requires a copy #237

Closed
maelp opened this issue Nov 29, 2017 · 0 comments · Fixed by #262
Closed

Reading audio requires a copy #237

maelp opened this issue Nov 29, 2017 · 0 comments · Fixed by #262

Comments

@maelp
Copy link

maelp commented Nov 29, 2017

Steps to reproduce

AudioSegment.from_file()

Expected behavior

It should load the audio efficiently

Actual behavior

It copies all the audio to a temporary file, then converts the temporary file to wav in a second temporary file, then load the wav

input_file = NamedTemporaryFile(mode='wb', delete=False)

This can be needed if we give a file descriptor as input to the from_file method, but for the common case where the input is a filename, it should be used without copying in a first temporary file

Your System configuration

  • Python version:
  • Pydub version:
  • ffmpeg or avlib?:
  • ffmpeg/avlib version:

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

You can include the audio file in this issue - just put it in a zip file and drag/drop the zip file into the github issue.

antlarr added a commit to antlarr/pydub that referenced this issue Mar 23, 2018
…m_file

Rename from_file to from_file_using_temporary_files just in case there's
any case in which the new from_file doesn't work (I couldn't find any,
but just in case, I guess it would be nice to keep it maybe as
deprecated).

Add a new from_file function that does all the reading on memory with
pipes, not using any temporary file, which is faster and doesn't wear
down disks for heavy usages.

The new from_file function reads the input file and passes it to ffmpeg
using a pipe and then reads ffmpeg output using another pipe directly
to memory.

Since wav files have the file length in the header and ffmpeg can't
write it since it's working on a stream, we modify the resulting raw data
from ffmpeg before reading it using the standard method.

Fixes jiaaro#237
Might also fix jiaaro#209
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 a pull request may close this issue.

1 participant