jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.98k stars 1.05k forks source link

Running AudioSegment.from_mp3 or audio.export ,the cmd command window always flash #698

Open 1893945 opened 2 years ago

1893945 commented 2 years ago

Steps to reproduce

Expected behavior

I used pyinstaller cteate a quiet exe, when Running AudioSegment.from_mp3 or audio.export not need to pop up the cmd command window.

Actual behavior

But when Running AudioSegment.from_mp3 or AudioSegment.export ,the cmd command window always flash

Your System configuration

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.

1893945 commented 2 years ago

add code : startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE|subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE

   p = subprocess.Popen(conversion_command, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo)

AudioSegment.export not pop up cmd window, But AudioSegment.from_mp3 pop up cmd window yet.

why?

1893945 commented 2 years ago

Problem solved.

startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE|subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE

the codes is available. AudioSegment.from_mp3 called pydub‘s utils.py, some subprocess.Pooen in utils.py, set them all “startupinfo=startupinfo”.

nariacc commented 1 year ago

Where do I add this code to? Is it in "audio_segment.py"? Thank you!

Artrajz commented 1 week ago

Thanks a lot for your solution! I found another way to modify subprocess.Popen in pydub without changing its internal files.

  1. Create patch_subprocess.py with the following content:
    
    import subprocess

class NoWindowPopen(subprocess.Popen): def init(self, *args, **kwargs): startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE

    kwargs["startupinfo"] = startupinfo
    super().__init__(*args, **kwargs)

subprocess.Popen = NoWindowPopen


2. Import `patch_subprocess` before import `pydub`

import patch_subprocess from pydub import AudioSegment