From 7bc77ff71417ea6391c571a3a9f737082508593f Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Fri, 22 Dec 2017 16:22:41 +0100 Subject: [PATCH 1/6] Add `asplit` filter --- ffmpeg/_filters.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ffmpeg/_filters.py b/ffmpeg/_filters.py index 0f980a7..8db40ee 100644 --- a/ffmpeg/_filters.py +++ b/ffmpeg/_filters.py @@ -52,6 +52,11 @@ def split(stream): return FilterNode(stream, split.__name__) +@filter_operator() +def asplit(stream): + return FilterNode(stream, split.__name__) + + @filter_operator() def setpts(stream, expr): """Change the PTS (presentation timestamp) of the input frames. From 755fb843de221faf90245eb47a1ce8d466e42fd5 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Fri, 22 Dec 2017 17:11:23 +0100 Subject: [PATCH 2/6] Also provide the number of splits to `asplit` filter --- ffmpeg/nodes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/nodes.py b/ffmpeg/nodes.py index 2b4c94f..013025d 100644 --- a/ffmpeg/nodes.py +++ b/ffmpeg/nodes.py @@ -152,7 +152,7 @@ class FilterNode(Node): def _get_filter(self, outgoing_edges): args = self.args kwargs = self.kwargs - if self.name == 'split': + if self.name in ('split', 'asplit'): args = [len(outgoing_edges)] out_args = [escape_chars(x, '\\\'=:') for x in args] From e7fbb288d418140f9ceaf7851ed3faa6d4d0368a Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Wed, 10 Jan 2018 10:35:23 +0100 Subject: [PATCH 3/6] Fix name of asplit filter --- ffmpeg/_filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/_filters.py b/ffmpeg/_filters.py index 8db40ee..94e6d24 100644 --- a/ffmpeg/_filters.py +++ b/ffmpeg/_filters.py @@ -54,7 +54,7 @@ def split(stream): @filter_operator() def asplit(stream): - return FilterNode(stream, split.__name__) + return FilterNode(stream, asplit.__name__) @filter_operator() From c87fd5cf56174f3b01b2df48993c801e5ec7ac47 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Wed, 10 Jan 2018 10:38:42 +0100 Subject: [PATCH 4/6] Add tests for asplit filter --- ffmpeg/tests/test_ffmpeg.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 95e0042..59d17b0 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -147,6 +147,41 @@ def test_get_args_complex_filter(): ] +def _get_complex_filter_asplit_example(): + split = (ffmpeg + .input(TEST_INPUT_FILE1) + .vflip() + .asplit() + ) + split0 = split[0] + split1 = split[1] + + return (ffmpeg + .concat( + split0.filter_("atrim", start=10, end=20), + split1.filter_("atrim", start=30, end=40), + ) + .output(TEST_OUTPUT_FILE1) + .overwrite_output() + ) + + +def test_filter_asplit(): + out = _get_complex_filter_asplit_example() + args = out.get_args() + assert args == [ + '-i', + TEST_INPUT_FILE1, + '-filter_complex', + '[0]vflip[s0];[s0]asplit=2[s1][s2];[s1]atrim=end=20:start=10[s3];[s2]atrim=end=40:start=30[s4];[s3]' + '[s4]concat=n=2[s5]', + '-map', + '[s5]', + TEST_OUTPUT_FILE1, + '-y' + ] + + def test_filter_normal_arg_escape(): """Test string escaping of normal filter args (e.g. ``font`` param of ``drawtext`` filter).""" def _get_drawtext_font_repr(font): From 50c4a8985d713e06bc809f221756ae9c69eacd18 Mon Sep 17 00:00:00 2001 From: Arne de Laat Date: Tue, 16 Jan 2018 22:10:41 +0100 Subject: [PATCH 5/6] Cleanup graph source file after rendering graph to pdf --- ffmpeg/_view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/_view.py b/ffmpeg/_view.py index cdb41b0..d2a945b 100644 --- a/ffmpeg/_view.py +++ b/ffmpeg/_view.py @@ -76,7 +76,7 @@ def view(stream_spec, **kwargs): downstream_node_id = str(hash(edge.downstream_node)) graph.edge(upstream_node_id, downstream_node_id, **kwargs) - graph.view(filename) + graph.view(filename, cleanup=True) return stream_spec From f1e418be4cd09f7bad0e42fcaa187cb6a42f1ac2 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Fri, 26 Jan 2018 14:38:57 +0100 Subject: [PATCH 6/6] Add `filter_multi_output` to `__all__` so it's available in API --- ffmpeg/_filters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ffmpeg/_filters.py b/ffmpeg/_filters.py index 8bbe0cd..d220b69 100644 --- a/ffmpeg/_filters.py +++ b/ffmpeg/_filters.py @@ -421,6 +421,7 @@ __all__ = [ 'drawbox', 'drawtext', 'filter_', + 'filter_multi_output', 'hflip', 'hue', 'overlay',