From edc81f471f729b973388535e667e37c58d632cd9 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Sun, 25 Nov 2018 14:24:47 +0100 Subject: [PATCH] Add preview mode (only for Desktop) --- .gitignore | 2 +- ffplayout.conf | 4 ++- ffplayout.py | 68 +++++++++++++++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 5f5bf158..011e85a2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ server.py **wip **temp **playlists -*.log +*.log* diff --git a/ffplayout.conf b/ffplayout.conf index 6ebf326d..7007e53a 100644 --- a/ffplayout.conf +++ b/ffplayout.conf @@ -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 diff --git a/ffplayout.py b/ffplayout.py index abb341de..528d0152 100755 --- a/ffplayout.py +++ b/ffplayout.py @@ -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=(