-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streaming control for recording locally and streaming to LAN (#149)
* First commit for streaming to LAN Some considerations - This will need SLS installed. Will provide our own configuration. - Currently uses FFmpeg with hardcoded values as explained in #44 discussion. To test from the repo, copy `./config/sls.conf` to `~/.local/share/steam-buddy/settings/sls.conf` and start steam-buddy: ``` $ ./steam-buddy ``` Then after logging in into steam-buddy got to the url: `[steam-buddy-url]/streaming/net/start` to start streaming, and `[steam-buddy-url]/streaming/net/stop` to stop. To consume the stream you can do: ``` $ ffplay -fflags nobuffer -i "srt://[steam-buddy-url]:8080?streamid=live.gameros/live/stream" ``` * Allow for local recording To start: `[steam-buddy-ip]/record/start` To stop: `[steam-buddy-ip]/record/stop` * FFmpeg command change to array for readability Still need the join/split dance so we can work with ACODEC_OPTIONS and VCODEC_OPTIONS Co-authored-by: alkazar <[email protected]>
- Loading branch information
Showing
5 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
srt { #SRT | ||
worker_threads 1; | ||
worker_connections 300 ; | ||
|
||
log_file logs/error.log ; | ||
log_level info; | ||
|
||
record_hls_path_prefix /tmp/mov/sls; | ||
|
||
server { | ||
listen 8080; | ||
latency 20; #ms | ||
|
||
domain_player live.gameros ; | ||
domain_publisher uplive.gameros; | ||
backlog 100; #accept connections at the same time | ||
idle_streams_timeout 10;#s -1: unlimited | ||
app { | ||
app_player live ; | ||
app_publisher live ; | ||
|
||
record_hls off;#on, off | ||
record_hls_segment_duration 10; #unit s | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
import shlex | ||
import time | ||
import subprocess as sp | ||
|
||
|
||
class StreamServer: | ||
|
||
def __init__(self, sls_conf_file): | ||
self.sls_conf_file = sls_conf_file | ||
self._sls = None | ||
self._ffmpeg = None | ||
|
||
def __generate_sls_conf(self): | ||
pass | ||
|
||
def __start_sls(self): | ||
if self._sls is None: | ||
self._sls = sp.Popen(['sls', '-c', self.sls_conf_file]) | ||
else: | ||
raise(Exception("Error starting SLS: Already started")) | ||
|
||
def __stop_sls(self): | ||
self._sls.terminate() | ||
try: | ||
self._sls.wait(5) | ||
except sp.TimeoutExpired: | ||
self._sls.kill() | ||
self._sls = None | ||
|
||
def __start_ffmpeg(self, local=False): | ||
VCODEC = "libx264" | ||
VCODEC_OPTIONS = "-preset ultrafast -tune zerolatency" | ||
VSIZE = "1920x1080" | ||
ACODEC = "libmp3lame" | ||
ACODEC_OPTIONS = "" | ||
FPS = "60" | ||
|
||
if local: | ||
STREAM = "screen_" + \ | ||
str(time.strftime("%Y%m%d_%H%M%S")) + \ | ||
".mp4" | ||
else: | ||
STREAM = '"srt://localhost:8080?streamid=uplive.gameros/live/stream"' | ||
|
||
cmd = ["ffmpeg", | ||
"-f x11grab -framerate", FPS, "-i :0", | ||
"-f alsa -ac 2 -i pulse", | ||
"-vcodec", VCODEC, VCODEC_OPTIONS, | ||
"-acodec", ACODEC, ACODEC_OPTIONS, | ||
"-video_size", VSIZE, | ||
"-flush_packets 0", | ||
"-f mpegts", | ||
STREAM] | ||
args = shlex.split(" ".join(cmd)) | ||
if self._ffmpeg is None: | ||
self._ffmpeg = sp.Popen(args, cwd=os.path.expanduser("~")) | ||
else: | ||
raise(Exception("Error starting FFMpeg: Already started")) | ||
|
||
def __stop_ffmpeg(self): | ||
self._ffmpeg.terminate() | ||
try: | ||
self._ffmpeg.wait(5) | ||
except sp.TimeoutExpired: | ||
self._ffmpeg.kill() | ||
self._ffmpeg = None | ||
|
||
def stream_to_lan(self): | ||
self.__start_sls() | ||
self.__start_ffmpeg() | ||
|
||
def stop_stream(self): | ||
self.__stop_ffmpeg() | ||
self.__stop_sls() | ||
|
||
def record_screen(self): | ||
self.__start_ffmpeg(local=True) | ||
|
||
def stop_record(self): | ||
self.__stop_ffmpeg() |