From 7de4f96dc527cb0e0e418932e2e9cd4a2644bc4b Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Sun, 4 Aug 2019 21:47:01 +0200 Subject: [PATCH] cleanup code --- ffplayout.conf | 33 ++++++++++++++++----------------- ffplayout.py | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/ffplayout.conf b/ffplayout.conf index 40d20c8c..78195bf5 100644 --- a/ffplayout.conf +++ b/ffplayout.conf @@ -15,7 +15,6 @@ # ------------------------------------------------------------------------------ -# set playlist_mode to False if you want to play clips from the [FOLDER] section # sometimes it can happen, that a file is corrupt but still playable, # this can produce an streaming error over all following files @@ -24,7 +23,6 @@ # best way is a systemd serivce on linux # stop_threshold: stop ffplayout, if it is async in time above this value [GENERAL] -playlist_mode = True stop_on_error = True stop_threshold = 11 @@ -74,32 +72,33 @@ ffmpeg_copy_settings = ["-c", "copy", "-bsf:v", "h264_mp4toannexb", "-f", "mpegt # playlist settings +# set playlist_mode to False if you want to play clips from the [STORAGE] section + # put only the root path here, for example: "/playlists" # subfolders are readed by the script # subfolders needs this structur: # "/playlists/2018/01" (/playlists/year/month) -# strings in playlist must have ampersan (&) as: & # day_start means at which time the playlist should start # leave day_start blank when playlist should always start at the begin +[PLAYLIST] +playlist_mode = True +path = /playlists +day_start = 05:59:25.000 + + +# play ordered or ramdomly files from path +# extensions: search only files with this extension, can be a list +# set shuffle to True to pick files randomly # filler_path are for the GUI only at the moment # filler_clip is for fill the end to reach 24 hours, it will loop when is necessary # blackclip is for stream copy mode, # best for this is a ~4 hours clip with black color and soft noise sound -[PLAYLIST] -playlist_path = /playlists -clips_root = /media +[STORAGE] +path = /media filler_path = /media/filler/filler-clips filler_clip = /media/filler/filler.mp4 -blackclip = /opt/dummy.mp4 -day_start = 05:59:25.000 - - -# play ordered or ramdomly files from clips_root -# extensions can be a list -# set shuffle to True to pick files randomly -[FOLDER] -storage = /media +blackclip = /media/dummy.mp4 extensions = ["*.mp4"] shuffle = False @@ -111,7 +110,7 @@ shuffle = False # on windows fontfile path need to be like this: C\:/WINDOWS/fonts/DejaVuSans.ttf # textfile has the same pattern [TEXT] -textfile = /opt/live.txt +textfile = /media/live.txt fontsize = 24 fontcolor = white fontfile = /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf @@ -134,7 +133,7 @@ post_comp_video = [ "-maxrate", "1300k", "-bufsize", "2600k", "-preset", "medium", "-profile:v", "Main", "-level", "3.1" ] -post_comp_audio = ["-c:a", "libfdk_aac", "-ar", "44100", "-b:a", "128k"] +post_comp_audio = ["-c:a", "aac", "-ar", "44100", "-b:a", "128k"] post_comp_extra = ["-flags", "+global_header", "-f", "flv"] post_comp_copy = ["-bsf:a", "aac_adtstoasc"] out_addr = rtmp://127.0.0.1/live/stream diff --git a/ffplayout.py b/ffplayout.py index 97c724d2..7e4e1a07 100755 --- a/ffplayout.py +++ b/ffplayout.py @@ -55,8 +55,7 @@ else: _general = SimpleNamespace( stop=cfg.getboolean('GENERAL', 'stop_on_error'), - threshold=cfg.getfloat('GENERAL', 'stop_threshold'), - playlist_mode=cfg.getboolean('GENERAL', 'playlist_mode') + threshold=cfg.getfloat('GENERAL', 'stop_threshold') ) _mail = SimpleNamespace( @@ -98,16 +97,17 @@ else: start_t = None _playlist = SimpleNamespace( - path=cfg.get('PLAYLIST', 'playlist_path'), - start=start_t, - filler=cfg.get('PLAYLIST', 'filler_clip'), - blackclip=cfg.get('PLAYLIST', 'blackclip'), + mode=cfg.getboolean('PLAYLIST', 'playlist_mode'), + path=cfg.get('PLAYLIST', 'path'), + start=start_t ) -_folder = SimpleNamespace( - storage=cfg.get('FOLDER', 'storage'), - extensions=json.loads(cfg.get('FOLDER', 'extensions')), - shuffle=cfg.getboolean('FOLDER', 'shuffle') +_storage = SimpleNamespace( + path=cfg.get('STORAGE', 'path'), + filler=cfg.get('STORAGE', 'filler_clip'), + blackclip=cfg.get('STORAGE', 'blackclip'), + extensions=json.loads(cfg.get('STORAGE', 'extensions')), + shuffle=cfg.getboolean('STORAGE', 'shuffle') ) _text = SimpleNamespace( @@ -430,7 +430,7 @@ def set_length(duration, seek, out): # generate a dummy clip, with black color and empty audiotrack def gen_dummy(duration): if _pre_comp.copy: - return ['-i', _playlist.blackclip, '-t', str(duration)] + return ['-i', _storage.blackclip, '-t', str(duration)] else: color = '#121212' # TODO: add noise could be an config option @@ -447,7 +447,7 @@ def gen_dummy(duration): # when playlist is not 24 hours long, we generate a loop from filler clip def gen_filler_loop(duration): - if not _playlist.filler: + if not _storage.filler: # when no filler is set, generate a dummy logger.warning('No filler is set!') return gen_dummy(duration) @@ -455,7 +455,7 @@ def gen_filler_loop(duration): # get duration from filler cmd = [ 'ffprobe', '-v', 'error', '-show_entries', 'format=duration', - '-of', 'default=noprint_wrappers=1:nokey=1', _playlist.filler] + '-of', 'default=noprint_wrappers=1:nokey=1', _storage.filler] try: f_dur = float(check_output(cmd).decode('utf-8')) @@ -466,7 +466,7 @@ def gen_filler_loop(duration): if f_dur > duration: # cut filler logger.info('Generate filler with {} seconds'.format(duration)) - return ['-i', _playlist.filler] + set_length( + return ['-i', _storage.filler] + set_length( f_dur, 0, duration) else: # loop filles n times @@ -474,7 +474,7 @@ def gen_filler_loop(duration): logger.info('Loop filler {} times, total duration: {}'.format( loop_count, duration)) return ['-stream_loop', str(loop_count), - '-i', _playlist.filler, '-t', str(duration)] + '-i', _storage.filler, '-t', str(duration)] else: logger.error("Can't get filler length, generate dummy!") return gen_dummy(duration) @@ -528,7 +528,7 @@ def gen_input(has_begin, src, begin, dur, seek, out, last): logger.info('we are under time, new_len is: {}'.format(new_len)) if time_diff >= ref_time: - if src == _playlist.filler: + if src == _storage.filler: # when filler is something like a clock, # is better to start the clip later and to play until end src_cmd = src_or_dummy(src, dur, dur - new_len, dur) @@ -551,7 +551,7 @@ def gen_input(has_begin, src, begin, dur, seek, out, last): logger.info('we are over time, new_len is: {}'.format(new_len)) if new_len > 5.0: - if src == _playlist.filler: + if src == _storage.filler: src_cmd = src_or_dummy(src, dur, out - new_len, out) else: src_cmd = src_or_dummy(src, dur, seek, new_len) @@ -933,7 +933,7 @@ class GetSourceIter(object): if filler: self.src_cmd = gen_filler_loop(self.out - self.seek) - if _playlist.filler: + if _storage.filler: self.is_dummy = False self.duration += 1 else: @@ -1104,16 +1104,16 @@ def main(): stdin=PIPE ) - if _general.playlist_mode: + if _playlist.mode: watcher = None get_source = GetSourceIter(encoder) else: logger.info("start folder mode") - media = MediaStore(_folder.extensions) - media.fill(_folder.storage) + media = MediaStore(_storage.extensions) + media.fill(_storage.path) - watcher = MediaWatcher(_folder.storage, _folder.extensions, media) - get_source = GetSource(media, _folder.shuffle) + watcher = MediaWatcher(_storage.path, _storage.extensions, media) + get_source = GetSource(media, _storage.shuffle) try: for src_cmd in get_source.next(): @@ -1151,7 +1151,7 @@ def main(): if __name__ == '__main__': - if not _general.playlist_mode: + if not _playlist.mode: from watchdog.events import PatternMatchingEventHandler from watchdog.observers import Observer