drawtext with config options

This commit is contained in:
Jonathan Baecker 2019-06-07 16:42:11 +02:00
parent 6fff195cd1
commit 3ce59811ab
2 changed files with 47 additions and 4 deletions

View File

@ -114,6 +114,23 @@ extensions = ["*.mp4"]
shuffle = False
# overlay text
# for paramters check ffmpeg doc
# with show you can enable/disable the filter
[TEXT]
show = True
enable = gte(t,3)
box = 1
boxcolor = black@0,65
boxborderw = 8
fontsize = 24
fontcolor = white
fontfile = /Library/Fonts/Arial.ttf
textfile = live.txt
x = w-w/8*mod(t,8*(w+tw)/w)
y = (h-line_h)*0,9
# the final playout post compression
# set the settings to your needs
# preview works only on a desktop system with ffplay!! Set it to True, if you need it

View File

@ -110,6 +110,20 @@ _folder = SimpleNamespace(
shuffle=cfg.getboolean('FOLDER', 'shuffle')
)
_text = SimpleNamespace(
show=cfg.getboolean('TEXT', 'show'),
enable=cfg.get('TEXT', 'enable'),
box=cfg.get('TEXT', 'box'),
boxcolor=cfg.get('TEXT', 'boxcolor'),
boxborderw=cfg.get('TEXT', 'boxborderw'),
fontsize=cfg.get('TEXT', 'fontsize'),
fontcolor=cfg.get('TEXT', 'fontcolor'),
fontfile=cfg.get('TEXT', 'fontfile'),
textfile=cfg.get('TEXT', 'textfile'),
x=cfg.get('TEXT', 'x'),
y=cfg.get('TEXT', 'y')
)
_playout = SimpleNamespace(
preview=cfg.getboolean('OUT', 'preview'),
name=cfg.get('OUT', 'service_name'),
@ -1019,13 +1033,24 @@ def main():
'-ar', '48000', '-ac', '2',
'-f', 'mpegts', '-']
if _text.show:
overlay = [
'-vf', ("drawtext=enable='{}':box={}:boxcolor='{}':"
"boxborderw={}:fontsize={}:fontcolor={}:fontfile='{}':"
"textfile={}:reload=1:x='{}':y='{}'").format(
_text.enable, _text.box, _text.boxcolor,
_text.boxborderw, _text.fontsize, _text.fontcolor,
_text.fontfile, _text.textfile, _text.x, _text.y)
]
else:
overlay = []
try:
if _playout.preview:
# preview playout to player
encoder = Popen([
'ffplay', '-hide_banner', '-nostats', '-i', 'pipe:0',
'-vf', "drawtext=enable='gte(t,3)':box=1:boxcolor=0x000000@0xcc:boxborderw=8:fontsize=24:fontcolor=white:textfile=live.txt:reload=1:y=(h-line_h)*0\,9:x=w-w/8*mod(t\,8*(w+tw)/w)"
],
'ffplay', '-hide_banner', '-nostats', '-i', 'pipe:0'
] + overlay,
stderr=None, stdin=PIPE, stdout=None
)
else:
@ -1040,7 +1065,8 @@ def main():
'ffmpeg', '-v', 'info', '-hide_banner', '-nostats',
'-re', '-thread_queue_size', '256',
'-i', 'pipe:0'
] + _playout.post_comp_video + _playout.post_comp_audio
] + overlay + _playout.post_comp_video \
+ _playout.post_comp_audio
encoder = Popen(
encoder_cmd + [