使用python的live mp3 ffmpeg编码器出错

时间:2014-09-16 06:01:59

标签: python windows python-2.7 ffmpeg subprocess

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

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 ::处理输入时找到的数据无效

我的ffmpeg和录音工作正常。 我该如何解决这个问题?

0 个答案:

没有答案