gpt4 book ai didi

Python FFMPEG AttributeError : 'Popen' object has no attribute 'proc'

转载 作者:行者123 更新时间:2023-12-03 00:39:28 34 4
gpt4 key购买 nike

我正在开发一个从音频流中学习的 tensorflow 项目。我正在尝试打开一个音频文件并使用 FFMPEG 将数据存储在一个数组中。我正在关注教程 here

我的代码如下所示:

import subprocess as sp
FFMPEG_BIN = "ffmpeg"
try:
if image_file != 'train/rock/.DS_Store':
command = [FFMPEG_BIN,
'-i', image_file,
'-f', 's16le',
'-acodec', 'pcm_s16le',
'-ar', '44100',
'-ac', '2',
'output.png']
pipe = sp.Popen(command, stdout=sp.PIPE, bufsize=10**8)
# pipe = sp.Popen(command, stdout=sp.PIPE)
raw_audio = pipe.proc.stdout.read(88200*4)

但我得到了错误:
AttributeError: 'Popen' object has no attribute 'proc'

最佳答案

我正在使用 ffmpegpyaudio .这段代码对我有用。

import pyaudio   
import subprocess as sp
import numpy
command = [ 'ffmpeg',
'-i', "Filename", # I used a url stream
'-loglevel','error',
'-f', 's16le',
'-acodec', 'pcm_s16le',
'-ar', '44100', # ouput will have 44100 Hz
'-ac', '2', # stereo (set to '1' for mono)
'-']
pipe = sp.Popen(command, stdout=sp.PIPE, bufsize=10**8)
p = pyaudio.PyAudio() #PyAudio helps to reproduce raw data in pipe.
stream = p.open(format = pyaudio.paInt16,
channels = 2,
rate = 44100,
output = True)
while True:
raw_audio = pipe.stdout.read(44100*2) #get raw data
stream.write(raw_audio) # reproduce
# Convert raw data in array with numpy
audio_array = numpy.fromstring(raw_audio, dtype="int16")
audio_array = audio_array.reshape((len(audio_array)/2,2))
stream.stop_stream()
stream.close()

在ubuntu中你可以安装 pyaudio和:
sudo apt-get install python-pyaudio python3-pyaudio 

或者
pip install pyaudio 

关于Python FFMPEG AttributeError : 'Popen' object has no attribute 'proc' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358480/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com