From 6e11d447412d39e932d3c4efb7fc7651dc5befd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 3 Nov 2021 23:14:43 +0100 Subject: [PATCH] feat(emulator): experimental rtmp stream --- src/emulator.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/emulator.py b/src/emulator.py index 119eb4c..666833e 100644 --- a/src/emulator.py +++ b/src/emulator.py @@ -1,4 +1,5 @@ import logging +from subprocess import PIPE, Popen import mgba.core import mgba.image @@ -34,6 +35,29 @@ def next_action(): return -1 +stream = Popen( + [ + "/usr/bin/ffmpeg", + "-y", + "-f", + "image2pipe", + "-vcodec", + "png", + "-r", + f"{FPS}", + "-s", + f"{WIDTH}x{HEIGHT}", + "-i", + "-", + "-f", + "flv", + "-b:v", + "2M", + "rtmp://localhost:1935/live/test", + ], + stdin=PIPE, +) + with pyvirtualcam.Camera(width=WIDTH, height=HEIGHT, fps=FPS) as cam: logging.debug(f"Using virtual camera: {cam.device}") @@ -46,6 +70,8 @@ with pyvirtualcam.Camera(width=WIDTH, height=HEIGHT, fps=FPS) as cam: core.run_frame() - frame = np.array(screen.to_pil().convert("RGB"), np.uint8) - cam.send(frame) + image = screen.to_pil().convert("RGB") + image.save(stream.stdin, "PNG") + + cam.send(np.array(image, np.uint8)) cam.sleep_until_next_frame()