使用ffmpeg-python结合cv2视频流和pyaudio音频流

使用ffmpeg-python结合cv2视频流和pyaudio音频流

我想使用我的相机和麦克风来获取实时视频和音频流,并使用 ffmpeg 将它们结合起来。所以我用 python 编写它。这是我的代码。

import os,pyaudio,cv2,ffmpeg 
p=pyaudio.PyAudio() 
vid = cv2.VideoCapture(0) 
aud = p.open(format=pyaudio.paInt16, channels=2, rate=44100, input=True, frames_per_buffer=1024) 
vidstream = vid.read()[1] 
audstream = aud.read(1024) 
ffmpeg.concat(vidstream, audstream, v=1, a=1).output('finished_video.mp4').run() 

这是错误:

Traceback (most recent call last): 
File "/home/pi/Desktop/ffmpegtest.py", line 13, in ffmpeg.concat(vidstream, audstream, v=1, a=1).output('finished_video.mp4').run() 
File "/home/pi/.local/lib/python3.9/site-packages/ffmpeg/_filters.py", line 399, in concat return FilterNode(streams, concat.name, kwargs=kwargs, max_inputs=None).stream() 
File "/home/pi/.local/lib/python3.9/site-packages/ffmpeg/nodes.py", line 266, in init super(FilterNode, self).init( File "/home/pi/.local/lib/python3.9/site-packages/ffmpeg/nodes.py", line 202, in init self.__check_input_types(stream_map, incoming_stream_types) 
File "/home/pi/.local/lib/python3.9/site-packages/ffmpeg/nodes.py", line 172, in __check_input_types 
raise TypeError( 
TypeError: Expected incoming stream(s) to be of one of the following types: ffmpeg.nodes.FilterableStream; got <class 'numpy.ndarray'>

我理解的很好,是不是意味着我要转换视频和音频的类型?我该怎么办?

相关内容