Add preview mode (only for Desktop)

This commit is contained in:
jb-alvarado 2018-11-25 14:24:47 +01:00
parent 97aa9f89cc
commit edc81f471f
3 changed files with 46 additions and 28 deletions

2
.gitignore vendored
View File

@ -3,4 +3,4 @@ server.py
**wip
**temp
**playlists
*.log
*.log*

View File

@ -102,7 +102,7 @@ map_extension =
# buffer_cli: the prefert buffer tool, needs to be installed on your system
# buffer_cmd: need to end with the buffer size command, full command would look:
# /usr/bin/pv -q -B 72600k
# /usr/bin/pv -q -B or: /usr/bin/mbuffer -q -c -m
[BUFFER]
buffer_length = 5
buffer_tolerance = 2.5
@ -114,7 +114,9 @@ buffer_cmd = ["-q", "-c", "-m"]
# set the settings to your needs
# logo is only used if the path exist
# with logo_o = overlay=W-w-2:0 you can modify the logo position
# preview works only on a desktop system with ffplay!! Set it to True, if you need it
[OUT]
preview = False
service_name = Live Stream
service_provider = example.org
logo = /usr/local/share/logo.png

View File

@ -94,6 +94,7 @@ _buffer = SimpleNamespace(
)
_playout = SimpleNamespace(
preview=cfg.getboolean('OUT', 'preview'),
name=cfg.get('OUT', 'service_name'),
provider=cfg.get('OUT', 'service_provider'),
out_addr=cfg.get('OUT', 'out_addr'),
@ -666,6 +667,7 @@ def main():
# open a buffer for the streaming pipeline
# stdin get the files loop
# stdout pipes to ffmpeg rtmp streaming
# TODO: replace with Queue or BytesIO?
mbuffer = Popen(
[_buffer.cli] + list(_buffer.cmd)
+ [str(calc_buffer_size()) + 'k'],
@ -674,34 +676,48 @@ def main():
bufsize=0
)
try:
# playout to rtmp
if _pre_comp.copy:
playout_pre = [
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats', '-re',
'-i', 'pipe:0', '-c', 'copy'
] + _playout.post_comp_copy
if _playout.preview:
# preview playout to player
try:
playout = Popen(
['ffplay', '-i', 'pipe:0'],
stdin=mbuffer.stdout,
bufsize=0
)
except OSError as e:
logger.error(e)
mbuffer.terminate()
sys.exit(1)
else:
playout_pre = [
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats', '-re',
'-thread_queue_size', '256', '-fflags', '+igndts',
'-i', 'pipe:0', '-fflags', '+genpts'
] + _playout.logo + _playout.filter + \
_playout.post_comp_video + \
_playout.post_comp_audio
# playout to rtmp
if _pre_comp.copy:
playout_pre = [
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats',
'-re', '-i', 'pipe:0', '-c', 'copy'
] + _playout.post_comp_copy
else:
playout_pre = [
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats',
'-re', '-thread_queue_size', '256',
'-fflags', '+igndts', '-i', 'pipe:0',
'-fflags', '+genpts'
] + _playout.logo + _playout.filter + \
_playout.post_comp_video + \
_playout.post_comp_audio
playout = Popen(
list(playout_pre)
+ [
'-metadata', 'service_name=' + _playout.name,
'-metadata', 'service_provider=' + _playout.provider,
'-metadata', 'year=' + year
] + list(_playout.post_comp_extra)
+ [
_playout.out_addr
],
stdin=mbuffer.stdout,
bufsize=0
)
playout = Popen(
list(playout_pre)
+ [
'-metadata', 'service_name=' + _playout.name,
'-metadata', 'service_provider=' + _playout.provider,
'-metadata', 'year=' + year
] + list(_playout.post_comp_extra)
+ [
_playout.out_addr
],
stdin=mbuffer.stdout,
bufsize=0
)
play_thread = Thread(
name='play_clips', target=play_clips, args=(