remove tolerance check, better naming
This commit is contained in:
parent
d76e7d6af9
commit
ba2426e866
@ -20,10 +20,8 @@
|
|||||||
# the only way in this case is, to stop ffplayout and start it again
|
# the only way in this case is, to stop ffplayout and start it again
|
||||||
# here we only say it can stop, the starting process is in your hand
|
# here we only say it can stop, the starting process is in your hand
|
||||||
# best way is a systemd serivce on linux
|
# best way is a systemd serivce on linux
|
||||||
# sync_tolerance: this measures the start time and if the difference exceeds this value a warning is sent
|
|
||||||
# stop_threshold: stop ffplayout, if it is async in time above this value
|
# stop_threshold: stop ffplayout, if it is async in time above this value
|
||||||
[GENERAL]
|
[GENERAL]
|
||||||
sync_tolerance = 5
|
|
||||||
stop_on_error = True
|
stop_on_error = True
|
||||||
stop_threshold = 11
|
stop_threshold = 11
|
||||||
|
|
||||||
|
48
ffplayout.py
48
ffplayout.py
@ -50,7 +50,6 @@ else:
|
|||||||
cfg.read('ffplayout.conf')
|
cfg.read('ffplayout.conf')
|
||||||
|
|
||||||
_general = SimpleNamespace(
|
_general = SimpleNamespace(
|
||||||
tolerance=cfg.getint('GENERAL', 'sync_tolerance'),
|
|
||||||
stop=cfg.getboolean('GENERAL', 'stop_on_error'),
|
stop=cfg.getboolean('GENERAL', 'stop_on_error'),
|
||||||
threshold=cfg.getfloat('GENERAL', 'stop_threshold')
|
threshold=cfg.getfloat('GENERAL', 'stop_threshold')
|
||||||
)
|
)
|
||||||
@ -273,7 +272,7 @@ def is_int(value):
|
|||||||
|
|
||||||
# compare clip play time with real time,
|
# compare clip play time with real time,
|
||||||
# to see if we are sync
|
# to see if we are sync
|
||||||
def check_sync(begin, playout):
|
def check_sync(begin, encoder):
|
||||||
time_now = get_time('full_sec')
|
time_now = get_time('full_sec')
|
||||||
|
|
||||||
time_distance = begin - time_now
|
time_distance = begin - time_now
|
||||||
@ -281,15 +280,13 @@ def check_sync(begin, playout):
|
|||||||
time_distance -= 86400.0
|
time_distance -= 86400.0
|
||||||
|
|
||||||
# check that we are in tolerance time
|
# check that we are in tolerance time
|
||||||
if abs(time_distance) > _general.tolerance:
|
if _general.stop and abs(time_distance) > _general.threshold:
|
||||||
mailer.warning(
|
mailer.error(
|
||||||
'Playlist is not sync!\n{} seconds async'.format(time_distance))
|
'Sync tolerance value exceeded with {} seconds,\n'
|
||||||
logger.warning('Playlist is {} seconds async!'.format(time_distance))
|
'program terminated!'.format(time_distance))
|
||||||
|
logger.error('Sync tolerance value exceeded, program terminated!')
|
||||||
if _general.stop and abs(time_distance) > _general.threshold:
|
encoder.terminate()
|
||||||
logger.error('Sync tolerance value exceeded, program terminated!')
|
sys.exit(1)
|
||||||
playout.terminate()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
# check begin and length
|
# check begin and length
|
||||||
@ -581,8 +578,8 @@ def build_filtergraph(first, duration, seek, out, ad, ad_last, ad_next, dummy):
|
|||||||
|
|
||||||
# read values from json playlist
|
# read values from json playlist
|
||||||
class GetSourceIter(object):
|
class GetSourceIter(object):
|
||||||
def __init__(self, playout):
|
def __init__(self, encoder):
|
||||||
self._playout = playout
|
self._encoder = encoder
|
||||||
self.last_time = get_time('full_sec')
|
self.last_time = get_time('full_sec')
|
||||||
|
|
||||||
if 0 <= self.last_time < _playlist.start:
|
if 0 <= self.last_time < _playlist.start:
|
||||||
@ -822,7 +819,7 @@ class GetSourceIter(object):
|
|||||||
self.last = False
|
self.last = False
|
||||||
|
|
||||||
if self.has_begin:
|
if self.has_begin:
|
||||||
check_sync(self.begin, self._playout)
|
check_sync(self.begin, self._encoder)
|
||||||
|
|
||||||
self.map_extension(node)
|
self.map_extension(node)
|
||||||
self.url_or_live_source()
|
self.url_or_live_source()
|
||||||
@ -888,29 +885,26 @@ def main():
|
|||||||
try:
|
try:
|
||||||
if _playout.preview:
|
if _playout.preview:
|
||||||
# preview playout to player
|
# preview playout to player
|
||||||
playout = Popen([
|
encoder = Popen([
|
||||||
'ffplay',
|
'ffplay', '-hide_banner', '-nostats', '-i', 'pipe:0'],
|
||||||
'-hide_banner', '-nostats', '-i', 'pipe:0'],
|
stderr=None, stdin=PIPE, stdout=None
|
||||||
stderr=None,
|
|
||||||
stdin=PIPE,
|
|
||||||
stdout=None
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# playout to rtmp
|
# playout to rtmp
|
||||||
if _pre_comp.copy:
|
if _pre_comp.copy:
|
||||||
playout_pre = [
|
encoder_cmd = [
|
||||||
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats',
|
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats',
|
||||||
'-re', '-i', 'pipe:0', '-c', 'copy'
|
'-re', '-i', 'pipe:0', '-c', 'copy'
|
||||||
] + _playout.post_comp_copy
|
] + _playout.post_comp_copy
|
||||||
else:
|
else:
|
||||||
playout_pre = [
|
encoder_cmd = [
|
||||||
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats',
|
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats',
|
||||||
'-re', '-thread_queue_size', '256',
|
'-re', '-thread_queue_size', '256',
|
||||||
'-i', 'pipe:0'
|
'-i', 'pipe:0'
|
||||||
] + _playout.post_comp_video + _playout.post_comp_audio
|
] + _playout.post_comp_video + _playout.post_comp_audio
|
||||||
|
|
||||||
playout = Popen(
|
encoder = Popen(
|
||||||
playout_pre + [
|
encoder_cmd + [
|
||||||
'-metadata', 'service_name=' + _playout.name,
|
'-metadata', 'service_name=' + _playout.name,
|
||||||
'-metadata', 'service_provider=' + _playout.provider,
|
'-metadata', 'service_provider=' + _playout.provider,
|
||||||
'-metadata', 'year={}'.format(year)
|
'-metadata', 'year={}'.format(year)
|
||||||
@ -918,7 +912,7 @@ def main():
|
|||||||
stdin=PIPE
|
stdin=PIPE
|
||||||
)
|
)
|
||||||
|
|
||||||
get_source = GetSourceIter(playout)
|
get_source = GetSourceIter(encoder)
|
||||||
|
|
||||||
for src_cmd in get_source.next():
|
for src_cmd in get_source.next():
|
||||||
if src_cmd[0] == '-i':
|
if src_cmd[0] == '-i':
|
||||||
@ -932,10 +926,10 @@ def main():
|
|||||||
'ffmpeg', '-v', 'error', '-hide_banner', '-nostats'
|
'ffmpeg', '-v', 'error', '-hide_banner', '-nostats'
|
||||||
] + src_cmd + ff_pre_settings,
|
] + src_cmd + ff_pre_settings,
|
||||||
stdout=PIPE) as decoder:
|
stdout=PIPE) as decoder:
|
||||||
copyfileobj(decoder.stdout, playout.stdin)
|
copyfileobj(decoder.stdout, encoder.stdin)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
playout.wait()
|
encoder.wait()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user