rename and uppercase constans, rename filter function

This commit is contained in:
jb-alvarado 2021-03-24 17:24:31 +01:00
parent cb7034b3c8
commit d36cb6af6d
4 changed files with 48 additions and 48 deletions

View File

@ -4,7 +4,7 @@ Add your one filters here. They must have the correct file naming:
- for audio filter: a_[filter name].py
- for video filter: v_[filter name].py
The file itself should contain only one filter in a function named `def filter(prope):`
The file itself should contain only one filter in a function named `def filter_link(prope):`
Check **v_addtext.py** for example.

View File

@ -1,10 +1,10 @@
from ffplayout.utils import get_float, stdin_args
from ffplayout.utils import STDIN_ARGS, get_float
def filter(node):
def filter_link(node):
"""
set audio volume
"""
if stdin_args.volume and get_float(stdin_args.volume, False):
return f'volume={stdin_args.volume}'
if STDIN_ARGS.volume and get_float(STDIN_ARGS.volume, False):
return f'volume={STDIN_ARGS.volume}'

View File

@ -23,7 +23,7 @@ import re
from glob import glob
from pydoc import locate
from ffplayout.utils import _global, _pre, _text, is_advertisement, messenger
from ffplayout.utils import GENERAL, PRE, TEXT, is_advertisement, messenger
# ------------------------------------------------------------------------------
# building filters,
@ -35,12 +35,12 @@ def text_filter():
filter_chain = []
font = ''
if _text.add_text and _text.over_pre:
if _text.fontfile and os.path.isfile(_text.fontfile):
font = f":fontfile='{_text.fontfile}'"
if TEXT.add_text and TEXT.over_pre:
if TEXT.fontfile and os.path.isfile(TEXT.fontfile):
font = f":fontfile='{TEXT.fontfile}'"
filter_chain = [
"null,zmq=b=tcp\\\\://'{}',drawtext=text=''{}".format(
_text.address.replace(':', '\\:'), font)]
TEXT.address.replace(':', '\\:'), font)]
return filter_chain
@ -67,13 +67,13 @@ def pad_filter(probe):
filter_chain = []
if not math.isclose(probe.video[0]['aspect'],
_pre.aspect, abs_tol=0.03):
if probe.video[0]['aspect'] < _pre.aspect:
PRE.aspect, abs_tol=0.03):
if probe.video[0]['aspect'] < PRE.aspect:
filter_chain.append(
f'pad=ih*{_pre.w}/{_pre.h}/sar:ih:(ow-iw)/2:(oh-ih)/2')
elif probe.video[0]['aspect'] > _pre.aspect:
f'pad=ih*{PRE.w}/{PRE.h}/sar:ih:(ow-iw)/2:(oh-ih)/2')
elif probe.video[0]['aspect'] > PRE.aspect:
filter_chain.append(
f'pad=iw:iw*{_pre.h}/{_pre.w}/sar:(ow-iw)/2:(oh-ih)/2')
f'pad=iw:iw*{PRE.h}/{PRE.w}/sar:(ow-iw)/2:(oh-ih)/2')
return filter_chain
@ -84,8 +84,8 @@ def fps_filter(probe):
"""
filter_chain = []
if probe.video[0]['fps'] != _pre.fps:
filter_chain.append(f'fps={_pre.fps}')
if probe.video[0]['fps'] != PRE.fps:
filter_chain.append(f'fps={PRE.fps}')
return filter_chain
@ -97,13 +97,13 @@ def scale_filter(probe):
"""
filter_chain = []
if int(probe.video[0]['width']) != _pre.w or \
int(probe.video[0]['height']) != _pre.h:
filter_chain.append(f'scale={_pre.w}:{_pre.h}')
if int(probe.video[0]['width']) != PRE.w or \
int(probe.video[0]['height']) != PRE.h:
filter_chain.append(f'scale={PRE.w}:{PRE.h}')
if not math.isclose(probe.video[0]['aspect'],
_pre.aspect, abs_tol=0.03):
filter_chain.append(f'setdar=dar={_pre.aspect}')
PRE.aspect, abs_tol=0.03):
filter_chain.append(f'setdar=dar={PRE.aspect}')
return filter_chain
@ -132,22 +132,22 @@ def overlay_filter(duration, ad, ad_last, ad_next):
logo_filter = '[v]null'
scale_filter = ''
if _pre.add_logo and os.path.isfile(_pre.logo) and not ad:
if PRE.add_logo and os.path.isfile(PRE.logo) and not ad:
logo_chain = []
if _pre.logo_scale and \
re.match(r'\d+:-?\d+', _pre.logo_scale):
scale_filter = f'scale={_pre.logo_scale},'
if PRE.logo_scale and \
re.match(r'\d+:-?\d+', PRE.logo_scale):
scale_filter = f'scale={PRE.logo_scale},'
logo_extras = (f'format=rgba,{scale_filter}'
f'colorchannelmixer=aa={_pre.logo_opacity}')
f'colorchannelmixer=aa={PRE.logo_opacity}')
loop = 'loop=loop=-1:size=1:start=0'
logo_chain.append(f'movie={_pre.logo},{loop},{logo_extras}')
logo_chain.append(f'movie={PRE.logo},{loop},{logo_extras}')
if ad_last:
logo_chain.append('fade=in:st=0:d=1.0:alpha=1')
if ad_next:
logo_chain.append(f'fade=out:st={duration - 1}:d=1.0:alpha=1')
logo_filter = (f'{",".join(logo_chain)}[l];[v][l]'
f'{_pre.logo_filter}:shortest=1')
f'{PRE.logo_filter}:shortest=1')
return logo_filter
@ -172,9 +172,9 @@ def add_loudnorm(probe):
"""
loud_filter = []
if probe.audio and _pre.add_loudnorm:
if probe.audio and PRE.add_loudnorm:
loud_filter = [
f'loudnorm=I={_pre.loud_i}:TP={_pre.loud_tp}:LRA={_pre.loud_lra}']
f'loudnorm=I={PRE.loud_i}:TP={PRE.loud_tp}:LRA={PRE.loud_lra}']
return loud_filter
@ -209,11 +209,11 @@ def extend_video(probe, duration, target_duration):
def realtime_filter(duration, track=''):
speed_filter = ''
if _pre.realtime:
if PRE.realtime:
speed_filter = f',{track}realtime=speed=1'
if _global.time_delta < 0:
speed = duration / (duration + _global.time_delta)
if GENERAL.time_delta < 0:
speed = duration / (duration + GENERAL.time_delta)
if speed < 1.1:
speed_filter = f',{track}realtime=speed={speed}'
@ -229,11 +229,11 @@ def split_filter(filter_type):
if filter_type == 'a':
prefix = 'a'
if _pre.output_count > 1:
for num in range(_pre.output_count):
if PRE.output_count > 1:
for num in range(PRE.output_count):
map_node.append(f'[{filter_type}out{num + 1}]')
_filter = f',{prefix}split={_pre.output_count}{"".join(map_node)}'
_filter = f',{prefix}split={PRE.output_count}{"".join(map_node)}'
else:
_filter = f'[{filter_type}out1]'
@ -245,10 +245,10 @@ def custom_filter(type, node):
filter_dir = os.path.dirname(os.path.abspath(__file__))
filters = []
for filter in glob(os.path.join(filter_dir, f'{type}_*')):
filter = os.path.splitext(os.path.basename(filter))[0]
filter_func = locate(f'ffplayout.filters.{filter}.filter')
link = filter_func(node)
for filter_file in glob(os.path.join(filter_dir, f'{type}_*')):
filter_ = os.path.splitext(os.path.basename(filter_file))[0]
filter_function = locate(f'ffplayout.filters.{filter_}.filter_link')
link = filter_function(node)
if link is not None:
filters.append(link)

View File

@ -1,21 +1,21 @@
import os
import re
from ffplayout.utils import _text
from ffplayout.utils import TEXT
def filter(node):
def filter_link(node):
"""
extract title from file name and overlay it
"""
font = ''
source = os.path.basename(node.get('source'))
match = re.match(_text.regex, source)
match = re.match(TEXT.regex, source)
title = match[1] if match else source
if _text.fontfile and os.path.isfile(_text.fontfile):
font = f":fontfile='{_text.fontfile}'"
if TEXT.fontfile and os.path.isfile(TEXT.fontfile):
font = f":fontfile='{TEXT.fontfile}'"
if _text.text_from_filename:
if TEXT.text_from_filename:
escape = title.replace("'", "'\\\\\\''").replace("%", "\\\\\\%")
return f"drawtext=text='{escape}':{_text.style}{font}"
return f"drawtext=text='{escape}':{TEXT.style}{font}"