From 8bb2291c1de8a691eb564eeb1ff71e22b92f9f1c Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Fri, 24 Apr 2020 19:33:04 +0200 Subject: [PATCH] validate ffmpeg --- ffplayout.py | 5 ++++- ffplayout/utils.py | 36 +++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/ffplayout.py b/ffplayout.py index 8536a73c..66366d81 100755 --- a/ffplayout.py +++ b/ffplayout.py @@ -26,7 +26,8 @@ from ffplayout.folder import GetSourceFromFolder, MediaStore, MediaWatcher from ffplayout.playlist import GetSourceFromPlaylist from ffplayout.utils import (_ff, _log, _playlist, _playout, _pre_comp, _text, ffmpeg_stderr_reader, get_date, messenger, - pre_audio_codec, stdin_args, terminate_processes) + pre_audio_codec, stdin_args, terminate_processes, + validate_ffmpeg_libs) try: if os.name != 'posix': @@ -149,4 +150,6 @@ def main(): if __name__ == '__main__': + # check if ffmpeg contains all codecs and filters + validate_ffmpeg_libs() main() diff --git a/ffplayout/utils.py b/ffplayout/utils.py index b583154b..b9c977c9 100644 --- a/ffplayout/utils.py +++ b/ffplayout/utils.py @@ -27,17 +27,17 @@ import smtplib import socket import sys import tempfile -import yaml from argparse import ArgumentParser from datetime import date, datetime, timedelta from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import formatdate from logging.handlers import TimedRotatingFileHandler -from subprocess import CalledProcessError, check_output +from subprocess import CalledProcessError, check_output, STDOUT from threading import Thread from types import SimpleNamespace +import yaml # ------------------------------------------------------------------------------ # argument parsing @@ -449,11 +449,12 @@ def ffmpeg_libs(): check which external libs are compiled in ffmpeg, for using them later """ - cmd = ['ffmpeg', '-version'] + cmd = ['ffmpeg', '-filters'] libs = [] + filters = [] try: - info = check_output(cmd).decode('UTF-8') + info = check_output(cmd, stderr=STDOUT).decode('UTF-8') except CalledProcessError as err: messenger.error('ffmpeg - libs could not be readed!\n' 'Processing is not possible. Error:\n{}'.format(err)) @@ -466,14 +467,35 @@ def ffmpeg_libs(): for cfg in configs: if '--enable-lib' in cfg: libs.append(cfg.replace('--enable-', '')) - break + elif re.match(r'^ (\.\.\.|T\.\.|\.S\.|\.\.C|TSC)', line) and \ + '=' not in line: + filter_list = line.split() + if len(filter_list) > 3: + filters.append(filter_list[1]) - return libs + return {'libs': libs, 'filters': filters} FF_LIBS = ffmpeg_libs() +def validate_ffmpeg_libs(): + if 'libx264' not in FF_LIBS['libs']: + playout_logger.error('ffmpeg contains no libx264!') + if 'libfdk-aac' not in FF_LIBS['libs']: + playout_logger.warning( + 'ffmpeg contains no libfdk-aac! No high quality aac...') + if 'libtwolame' not in FF_LIBS['libs']: + playout_logger.warning( + 'ffmpeg contains no libtwolame!' + ' Loudness correction use mp2 audio codec...') + if 'tpad' not in FF_LIBS['filters']: + playout_logger.error('ffmpeg contains no tpad filter!') + if 'zmq' not in FF_LIBS['filters']: + playout_logger.error( + 'ffmpeg contains no zmq filter! Text messages will not work...') + + # ------------------------------------------------------------------------------ # probe media infos # ------------------------------------------------------------------------------ @@ -967,7 +989,7 @@ def pre_audio_codec(): and works not well together with the loudnorm filter """ if _pre_comp.add_loudnorm: - acodec = 'libtwolame' if 'libtwolame' in FF_LIBS else 'mp2' + acodec = 'libtwolame' if 'libtwolame' in FF_LIBS['libs'] else 'mp2' audio = ['-c:a', acodec, '-b:a', '384k', '-ar', '48000', '-ac', '2'] else: audio = ['-c:a', 's302m', '-strict', '-2', '-ar', '48000', '-ac', '2']