首页 > 解决方案 > ffmpeg Windows 使用来自管道的视频流到 Twitch 仅发送约 100 帧并卡住

问题描述

我尝试在 Windows 上使用 Python 和 ffmpeg 将 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())”上没有错误

标签: python-3.xwindowsffmpegsubprocess

解决方案


推荐阅读