我尝试在Windows上使用带ffmpeg的Python将rawVideo(一个numpy数组)流式传输到Twitch。但是大约100帧之后,我就卡住了。
我的子流程参数:
command = [
"ffmpeg.exe",
'-f', 'rawvideo',
'-vcodec','rawvideo',
'-s', '480x640',
'-pix_fmt', 'rgb24',
'-r', '30',
'-i', '-',
'-vcodec', 'libx264',
'-b:v' , '5M',
'-acodec', 'aac',
'-b:a', '256k',
'-r','30',
'-f', 'flv', 'rtmp://live-fra.twitch.tv/app/%removed for stackoverflow%'
]
[...]
pipe = subprocess.Popen( command, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
发送帧:
frames = 0
frame = np.zeros((480, 640, 3))
#print(pipe,dir(pipe))
while 1:
try:
pipe.stdin.write(frame.tobytes()) # < gets stuck here after ~100 frames
frames += 1
print("frame_send", frames)
except Exception as e:
out, ffmpeg_error = pipe.communicate()
print("error:" , ffmpeg_error , e , out )
break
time.sleep( 1 / 30 )
它没有卡在“ pipe.stdin.write(frame.tobytes())”上的任何错误