在使用python的现场mp3 ffmpeg编码器错误

我有一个像下面的代码。 我想录制声音,并使用ffmpeg实时将每个wav帧转换为mp3格式

import pyaudio,sys import subprocess command = ['ffmpeg', '-y','-f','wav' , '-i', '-', '-f', 'mp3', '-'] process = subprocess.Popen(command, stdin=subprocess.PIPE) p = pyaudio.PyAudio() CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 1024*10 RECORD_SECONDS = 2 stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) mp3 = open("mp3.mp3",'wb') for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) recording_mp3, errordata = process.communicate(data) mp3.write(recording_mp3) 

现在我的代码产生错误

pipe ::处理input时发现无效的数据

我的ffmpeg和录音工作正常。 我怎样才能解决这个问题?

Solutions Collecting From Web of "在使用python的现场mp3 ffmpeg编码器错误"