如何从python通过管道将openCV和PyAudio传输到ffmpeg streaming youtube rtmp。错误消息如下:没有这样的筛选器:‘管道:1’管道:1:无效参数
下面是我的代码:
导入模块
import cv2
import subprocess
import pyaudio音频
p = pyaudio.PyAudio()
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
for i in range(0, numdevices):
if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name'))
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
# Stream Audio data here
# data = stream.read(CHUNK)视频
rtmp = r'rtmp://a.rtmp.youtube.com/live2/key'
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = 30此处为命令参数
command = ['ffmpeg',
'-y',
'-f', 'rawvideo',
'-pixel_format', 'bgr24',
'-video_size', "{}x{}".format(width, height),
'-framerate', str(fps),
'-i', 'pipe:0',
'-re',
'-f', 'lavfi',
'-i', 'pipe:1',
'-c:v', 'libx264',
'-c:a', 'aac',
'-vf', 'format=yuv420p',
'-f', 'flv',
rtmp]Create subprocess to ffmpeg命令
pipe = subprocess.Popen(command, shell=False, stdin=subprocess.PIPE
)
while cap.isOpened():
success, frame = cap.read()
if success:
if cv2.waitKey(1) & 0xFF == ord('q'):
break
pipe.stdin.write(frame.tostring())
pipe.stdin.write(stream.read(CHUNK))音频停止
stream.stop_stream()
stream.close()
p.terminate()视频停止
cap.release()
pipe.terminate()谢谢
发布于 2021-08-22 13:38:57
我已经成功地使用CreateNamePipe创建了视频,并使用标准输入创建了音频。
PIPE_NAME = r'\\.\pipe\VideoPipe'
video_pipe = win32pipe.CreateNamedPipe(
PIPE_NAME,
win32pipe.PIPE_ACCESS_OUTBOUND,
win32pipe.PIPE_TYPE_BYTE | win32pipe.PIPE_READMODE_BYTE | win32pipe.PIPE_WAIT,
1, 65536, 65536,
0,
None)https://stackoverflow.com/questions/68527762
复制相似问题