jiaaro / pydub

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

Decoding failed. ffmpeg returned error code: 1 #666

Open bearcatjamboree opened 2 years ago

bearcatjamboree commented 2 years ago

Steps to reproduce

engine = pyttsx3.init()
engine.setProperty('voice', "com.apple.speech.synthesis.voice.{}".format(args.voice))
engine.setProperty("rate", 200)
engine.save_to_file(dict['text'], "{}/tmp{:05d}.wav".format(tmpdirname, int(dict['counter'].strip())))
engine.runAndWait()

del(engine)

source = AudioSegment.from_file("{}/tmp{:05d}.wav".format(tmpdirname, int(dict['counter'].strip())), format="wav")

Expected behavior

File should be readable by AudioSegment so the frame can be padded to a specific length so SRT and WAV are the same length and align with video frames.

Actual behavior

Decoding failed. ffmpeg returned error code: 1

Your System configuration

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

Yes I have provided two zip files: the original and one I was able to manually decode without errors using the following ffmpeg command:

ffmpeg -i "tmp00001.wav" -f wav -bitexact -acodec pcm_s16le -ar 22050 -ac 1 "ffmpeg00001.wav"

tmp00001.wav.zip

ffmpeg00001.wav.zip

bearcatjamboree commented 2 years ago

By the way, this is what is produced by the subprocess call:

subprocess.call(['ffmpeg', '-y', '-f', 'wav', '-i', '/var/folders/fh/6zywpfcj2w71vq7z8fjf81240000gn/T/tmpdvgbzvv_/tmp00140.wav', '-acodec', 'pcm_s16le', '-vn', '-f', 'wav', '-'])

Is the problem the fact that -f wav is passed twice? When I issue this command, it seems to work:

ffmpeg -i tmp00001.wav -acodec pcm_s16le -vn -y -f wav -

bearcatjamboree commented 2 years ago

If I change the code in audio_segement.py starting at line 698 as follows:

    conversion_command = [cls.converter]
    #conversion_command = [cls.converter,
    #                      '-y',  # always overwrite existing files
    #                      ]

    # If format is not defined
    # ffmpeg/avconv will detect it automatically
    if format:
        pass
        #conversion_command += ["-f", format]

And add the '-y' to the last statement (line 760):

    conversion_command += ["-y", "-"]

I don't getting the error any more. I'm not sure if that would be universal to ffmpeg and libav but the way ffmpeg is called does appear to be an issue here.