mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-04-05 12:48:09 +08:00
Add pipe
param to view
This commit is contained in:
parent
e6d09f532a
commit
4f97d1d679
@ -30,22 +30,23 @@ def _get_node_color(node):
|
|||||||
|
|
||||||
|
|
||||||
@stream_operator()
|
@stream_operator()
|
||||||
def view(stream_spec, **kwargs):
|
def view(stream_spec, detail=False, filename=None, pipe=False, **kwargs):
|
||||||
try:
|
try:
|
||||||
import graphviz
|
import graphviz
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError('failed to import graphviz; please make sure graphviz is installed (e.g. `pip install '
|
raise ImportError('failed to import graphviz; please make sure graphviz is installed (e.g. `pip install '
|
||||||
'graphviz`)')
|
'graphviz`)')
|
||||||
|
|
||||||
filename = kwargs.pop('filename', None)
|
|
||||||
show_labels = kwargs.pop('show_labels', True)
|
show_labels = kwargs.pop('show_labels', True)
|
||||||
if filename is None:
|
if pipe and filename is not None:
|
||||||
|
raise ValueError('Can\'t specify both `filename` and `pipe`')
|
||||||
|
elif not pipe and filename is None:
|
||||||
filename = tempfile.mktemp()
|
filename = tempfile.mktemp()
|
||||||
|
|
||||||
nodes = get_stream_spec_nodes(stream_spec)
|
nodes = get_stream_spec_nodes(stream_spec)
|
||||||
|
|
||||||
sorted_nodes, outgoing_edge_maps = topo_sort(nodes)
|
sorted_nodes, outgoing_edge_maps = topo_sort(nodes)
|
||||||
graph = graphviz.Digraph()
|
graph = graphviz.Digraph(format='png')
|
||||||
graph.attr(rankdir='LR')
|
graph.attr(rankdir='LR')
|
||||||
if len(list(kwargs.keys())) != 0:
|
if len(list(kwargs.keys())) != 0:
|
||||||
raise ValueError('Invalid kwargs key(s): {}'.format(', '.join(list(kwargs.keys()))))
|
raise ValueError('Invalid kwargs key(s): {}'.format(', '.join(list(kwargs.keys()))))
|
||||||
@ -53,7 +54,14 @@ def view(stream_spec, **kwargs):
|
|||||||
for node in sorted_nodes:
|
for node in sorted_nodes:
|
||||||
color = _get_node_color(node)
|
color = _get_node_color(node)
|
||||||
|
|
||||||
graph.node(str(hash(node)), node.short_repr, shape='box', style='filled', fillcolor=color)
|
if detail:
|
||||||
|
lines = [node.short_repr]
|
||||||
|
lines += ['{!r}'.format(arg) for arg in node.args]
|
||||||
|
lines += ['{}={!r}'.format(key, node.kwargs[key]) for key in sorted(node.kwargs)]
|
||||||
|
node_text = '\n'.join(lines)
|
||||||
|
else:
|
||||||
|
node_text = node.short_repr
|
||||||
|
graph.node(str(hash(node)), node_text, shape='box', style='filled', fillcolor=color)
|
||||||
outgoing_edge_map = outgoing_edge_maps.get(node, {})
|
outgoing_edge_map = outgoing_edge_maps.get(node, {})
|
||||||
|
|
||||||
for edge in get_outgoing_edges(node, outgoing_edge_map):
|
for edge in get_outgoing_edges(node, outgoing_edge_map):
|
||||||
@ -78,9 +86,11 @@ def view(stream_spec, **kwargs):
|
|||||||
downstream_node_id = str(hash(edge.downstream_node))
|
downstream_node_id = str(hash(edge.downstream_node))
|
||||||
graph.edge(upstream_node_id, downstream_node_id, **kwargs)
|
graph.edge(upstream_node_id, downstream_node_id, **kwargs)
|
||||||
|
|
||||||
graph.view(filename, cleanup=True)
|
if pipe:
|
||||||
|
return graph.pipe()
|
||||||
return stream_spec
|
else:
|
||||||
|
graph.view(filename, cleanup=True)
|
||||||
|
return stream_spec
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user