From 58c52ed46ffd155e4f868b435780c9a5547687b6 Mon Sep 17 00:00:00 2001 From: Christophe Mehay Date: Fri, 6 Mar 2020 22:54:22 +0100 Subject: [PATCH] Add sub parameters syntaxe for filters --- ffmpeg/nodes.py | 8 +++++++- ffmpeg/tests/test_ffmpeg.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ffmpeg/nodes.py b/ffmpeg/nodes.py index cacab8e..0558e80 100644 --- a/ffmpeg/nodes.py +++ b/ffmpeg/nodes.py @@ -286,7 +286,13 @@ class FilterNode(Node): out_kwargs = {} for k, v in list(kwargs.items()): k = escape_chars(k, '\\\'=:') - v = escape_chars(v, '\\\'=:') + if isinstance(v, dict): + v = ','.join(['{}={}'.format( + escape_chars(vk, '\\\'=:'), + escape_chars(v[vk], '\\\'=:') + ) for vk in sorted(v)]) + else: + v = escape_chars(v, '\\\'=:') out_kwargs[k] = v arg_params = [escape_chars(v, '\\\'=:') for v in out_args] diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 51ee258..20f368a 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -120,6 +120,19 @@ def test_repeated_args(): out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4', streamid=['0:0x101', '1:0x102']) assert out_file.get_args() == ['-i', 'dummy.mp4', '-streamid', '0:0x101', '-streamid', '1:0x102', 'dummy2.mp4'] +def test_filter_sub_options(): + subtitle_filter = ffmpeg.input('dummy.mp4').filter('subtitles', force_style={ + 'Alignement': '6', 'Fontsize': '48'}).output('dummy2.mp4') + assert subtitle_filter.get_args() == [ + '-i', + 'dummy.mp4', + '-filter_complex', + r'[0]subtitles=force_style=Alignement=6\,Fontsize=48[s0]', + '-map', + '[s0]', + 'dummy2.mp4' + ] + def test__get_args__simple(): out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4')