feat(emulator): experimental rtmp stream

This commit is contained in:
Laureηt 2021-11-03 23:14:43 +01:00
parent 7fbe38e8ba
commit 6e11d44741
No known key found for this signature in database
GPG key ID: D88C6B294FD40994

View file

@ -1,4 +1,5 @@
import logging import logging
from subprocess import PIPE, Popen
import mgba.core import mgba.core
import mgba.image import mgba.image
@ -34,6 +35,29 @@ def next_action():
return -1 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: with pyvirtualcam.Camera(width=WIDTH, height=HEIGHT, fps=FPS) as cam:
logging.debug(f"Using virtual camera: {cam.device}") 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() core.run_frame()
frame = np.array(screen.to_pil().convert("RGB"), np.uint8) image = screen.to_pil().convert("RGB")
cam.send(frame) image.save(stream.stdin, "PNG")
cam.send(np.array(image, np.uint8))
cam.sleep_until_next_frame() cam.sleep_until_next_frame()